Skip to content

Serialize arrays in SQLite inserts, and return ids from batch inserts only when needed - #353

Merged
lehni merged 1 commit into
nextfrom
fix/sqlite-batch-insert
Oct 12, 2026
Merged

lehni merged 1 commit into
nextfrom
fix/sqlite-batch-insert

Conversation

@lehni

@lehni lehni commented Oct 12, 2026 •

Copy link
Copy Markdown

What

A follow-up to #349, after a review of it:

  • On SQLite, insert() stores objects and arrays in columns that aren't jsonAttributes as JSON in every insert, not only in batches. knex leaves arrays as '[object Object]' even in single rows, which Batch inserts on SQLite, and inserts of models with ids on all databases #349 didn't cover.
  • SQLite batch inserts only add returning when there are ids to return. Models that have their ids aren't matched to the returned rows by position then, whose order SQLite doesn't guarantee.
  • Batch inserts of models without an idColumn work on all databases, like models that have their ids, as there is nothing to return. Ids that $beforeInsert hooks give the models count too, and queries that a beforeInsert hook cancels don't throw.
  • Docs:
    • SQLite needs 3.35 for batch inserts of new rows, and older versions fail with a syntax error near "returning".
    • In SQLite batch inserts, columns that some rows leave out get NULL instead of their defaults, as knex inserts them with select ... union all, and batches of more than 500 rows or 32766 values fail.
    • Many-to-many relate() of several ids works on all databases.
    • The changelog no longer says that graph inserts batch on SQLite, which only Rewrite upsertGraph() and insertGraph() (#1268, #1378, #1694, #853) #350 makes true.
  • Tests:

@lehni lehni added the 4.0 Breaking change, deferred to 4.0 (#53) label Oct 12, 2026
@lehni
lehni force-pushed the fix/sqlite-batch-insert branch 2 times, most recently from 0c06029 to b53be4a Compare October 12, 2026 21:08
@lehni
lehni force-pushed the fix/sqlite-batch-insert branch from b53be4a to bf0799b Compare October 12, 2026 21:13
@lehni
lehni marked this pull request as ready for review October 12, 2026 21:16
@lehni
lehni merged commit 5886d9d into next Oct 12, 2026
5 checks passed
@lehni
lehni deleted the fix/sqlite-batch-insert branch October 12, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 Breaking change, deferred to 4.0 (#53)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant