This is the query I pass into a batch transaction:
INSERT INTO table VALUES(${id}, ${name}, ${crtd});
The input array may or may not contain one of the keys, say ${crtd}
.
This throws Error: property 'crtd' does not exist
and the entire batch fails.
I still want this row to be inserted, containing only {id}
and {name}
. The ${crtd}
is a nullable column too.
In the below, 'l' is the input json missing the key ${crtd}.
db.tx(t=>t.batch(valuesArray.map(l=>t.none(query, l)))) So, the only way to do this is additional logic that checks for missing keys and adds them?
How to handle this?