camsaul / toucan2

Successor library to Toucan with a modern and more-extensible API, more consistent behavior, and support for different backends including non-JDBC databases and non-HoneySQL queries. Currently in active beta.
Eclipse Public License 1.0
81 stars 11 forks source link

Supports sqlite3 #169

Open qnkhuat opened 7 months ago

qnkhuat commented 7 months ago

Helpers that return pk or instance don't work with sqlite3. This is because the sqlite3 JDBC does not return pk when :return-key is set to true but it'll return the last_insert_rowid() (src).

The best way to fix this is to use the RETURNING clause as last_insert_rowid is not guaranteed to be the row id we inserted.

From the doc

returns the rowid of the most recent successful INSERT into a rowid table

Also, this will not work for WITHOUT ROWID tables.

Another advantage of using RETURNING clause is that we don't have to do another DB call to select the instance.