<< Back to previous view

[JDBC-3] Inconsistency between tuples and regular maps Created: 08/May/11  Updated: 01/Jun/16  Resolved: 12/Oct/11

Status: Closed
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Sean Corfield Assignee: Sean Corfield
Resolution: Duplicate Votes: 0
Labels: None


Stuart Sierra: In general, c.c.sql is inconsistent about using tuples of column values versus maps of column=>value pairs. Both are useful, and I'd like to see versions of all the core functions that support both modes.

Comment by Sean Corfield [ 13/Aug/11 6:59 PM ]

Having reviewed this after using the library for quite a while, I don't really see any inconsistencies except, perhaps in the naming of update-values (and update-or-insert-values).

insert-values is the base function, taking a table name, a vector of column names and any number of vectors of column values. Generates one insert statement (containing multiple rows). If only one row is inserted, returns a map of generated keys if the database supports that.

insert-rows takes a table name and any number of vectors of column values (for all columns); uses insert-values.

insert-records takes a table name and any number of maps (containing column/value pairs); uses insert-values to insert one record at a time (and thus may return a sequence of maps of generated keys).

insert-record takes a table name and a single map; uses insert-records and returns a map of generated key if the database supports that.

delete-rows takes a table name and a where clause. Perhaps delete-where might be a better name?

update-values takes a table name, a where clause and a map (of column/value pairs to update). Arguably this should be renamed since it doesn't take the same argument pattern as insert-values, but whilst update-records might sound more appropriate it only takes one "record" and update-record is clearly not right since it can update more than one row!

update-or-insert-values (taking the same arguments as update-values) can however lead to inserting a single record but it can also update multiple records instead.

On both of the latter functions, an analogy could be drawn with the findAndModify command in MongoDB which has an upsert option (to insert the document if no matches are found for the update), but most notably, findAndModify only updates a single record. I don't believe SQL has any portable equivalent but perhaps find-and-modify is a better name for update-values? Or perhaps, in the spirit of my suggestion for delete-where, we might call it update-where - and use an optional keyword argument to indicate that an insert-record should be performed when no rows match?

The only other comment I could make on update-values is that it might be nice to have a variant that took: table where-params column-names value-group - somewhat inline with insert-values (although not allowing any number of vectors of column values).

Comment by Sean Corfield [ 12/Oct/11 4:29 PM ]

The API aspects of this ticket are covered in JDBC-20 (post 0.1.0) and the struct-map issue is covered in JDBC-15 so I'm closing this out as a duplicate for now.

Comment by Sean Corfield [ 12/Oct/11 4:29 PM ]

Essentially duplicated with more focus in JDBC-15 and JDBC-20.

Generated at Sun Oct 22 05:14:43 CDT 2017 using JIRA 4.4#649-r158309.