google/lovefield

Consider accepting a single row when calling values()

valioDOTch opened this issue · 2 comments

Enhancement suggestion: I have stumbled multiple times over the fact, that values expects an array and can't handle a call where I provide a single row (which gives the not-so-descriptive error "rows.some is not a function").

Said differently: I would expect the following the work
let pendingRequestTable = connection.getSchema().table("PendingRequests"); let data = {url,method,body, timestamp: (new Date()).valueOf()}; let requestRow = pendingRequestTable.createRow(data); connection.insertOrReplace().into(pendingRequestTable).values(requestRow).exec();

This sounds reasonable. When we first designed this API we wanted (and still do) to avoid runtime type checking (like detecting if an array or a single value was passed). Perhaps a different way to address the issue is to add a value() method, that accepts a single value and leave values() semantics as is.

FWIW, another enhancement I've thought about (but never got to implement), is to stop requiring calling code to call createRow() first, instead call this internally. So in your example you would be passing data straight to values().

I assumed that performance might be an issue for this decision.
I think the "value" approach would be a possibility (albeit being at odds with SQL syntax).

I would be in favour of omitting the createRow call.
I haven't met a case yet where the explicit call would add further value.