72 Commits
Author SHA1 Message Date
tbenandClaude Opus 5.5 938a1da71d Add queue tables, quote SQL identifiers (v1.3.0)
- isQueue table option adds queue columns and a (status, available_at)
  index; BunSQLite.queue exposes add, claim, complete, fail and
  release_stale with atomic claims
- Set busy_timeout on connections so workers in separate processes wait
  instead of failing with SQLITE_BUSY
- Quote table and column names with backticks in generated SQL, so
  reserved words (to, order, group) work and unknown columns error
  instead of matching as string literals
- Tests for queue ops, multi-process claims and reserved-word names

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 16:29:14 +01:00
tben 07807cb19d Add default returning record on db insert and update 2026-10-17 18:44:26 +01:00
tben 695347944d Return inserted/updated records from insert and update handlers
Append RETURNING * to generated INSERT/UPDATE SQL so the affected
record(s) are returned in payload/singleRes. Vector tables skip RETURNING
on update because SQLite does not support UPDATE ... RETURNING on virtual
tables, falling back to postInsertReturn.

postInsertReturn (affectedRows/insertId) is still populated for backwards
compatibility. Adds a returning?: boolean opt-out (default true) and tests.
2026-10-17 18:43:46 +01:00
tben 7c095f6f16 Major version update. Major bugfixes. Security vulnerabilites fixed 2026-10-14 03:02:07 +01:00
tbenandClaude Opus 5.5 4e47bd8ce0 Port bun-mariadb schema guard, targetId fix, lazy init and tests
- schema: add --dry-run (sync in a rolled-back transaction) and require
  confirmation (or --yes) before dropping tables or columns; unapproved
  destructive changes are refused
- only rebuild tables whose CREATE TABLE statement changed
- always AND targetId with the query, regardless of searchOperator
- empty IN / NOT IN lists become 1 = 0 / 1 = 1
- initialize lazily on first call so importing never throws
- read CLI version from package.json, chmod CLI on compile, pin @types/bun
- add SQL generator, value and schema guard tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 03:00:29 +01:00
tbenandClaude Opus 5.5 87da436f81 Port bun-mariadb conventions: init globals, db handler, split schema sync
- init() loads config, schema and the SQLite client once into globals
- all CRUD queries go through lib/db-handler.ts (optional per-call config)
- split db-schema-manager.ts into lib/schema/* with FK-aware table ordering
- add bun:test tests for schema ordering, FK constraints and schema sync
- config/schema files can be .ts/.js/.json/.yaml/.yml; db_schema_file_name
  is now optional (defaults to schema.* in db_dir)
- add export/import commands (database snapshot + schema archives)
- package exports map, type re-exports, hardened publish.sh
- validate table name in delete

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 02:37:35 +01:00
tbenandClaude Opus 5.5 66f73c4228 Fix SQL injection, schema-sync data loss, and backup safety
Security:
- select: bind parameters instead of mysql.format (backslash escaping
  allowed injection on SQLite); drop the mysql dependency
- validate all interpolated identifiers, limit/offset/page, order
  strategy, operators, join types and raw equalities (new sql-safe.ts)
- quote identifiers and bind values in schema manager DDL/queries

Data loss:
- schema sync runs with foreign keys off inside a transaction, with
  foreign_key_check before commit (DROP TABLE no longer cascades)
- parentTableName tables: stop mutating the parent schema and copy
  inherited columns on rebuild
- keep column data on type changes (match columns by name)
- backups and schema snapshots use VACUUM INTO (includes WAL data);
  restore closes the DB, clears -wal/-shm, and swaps atomically
- backup listing/trimming only touches <db_name>-<timestamp> files

Correctness:
- update/delete use the generator's WHERE clause instead of a regex
- keep 0/""/false values; booleans stored as 0/1
- IN/NOT IN and BETWEEN arrays, NOT LIKE wrapping, AVG, select aliases
- OFFSET without LIMIT, count ignores pagination
- MATCH emits `field MATCH fn(?)` for sqlite-vec
- sql() returns rows for any row-producing statement
- targetId no longer mutates the caller's query
- init throws instead of process.exit; CLI reports errors

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 02:06:59 +01:00
tben 991b02d7c1 Updates 2026-09-20 06:50:40 +01:00
tben 9129593545 Updates 2026-09-17 11:22:18 +01:00
tben a357f69380 Updates 2026-05-24 04:37:51 +01:00
tben 6796a36464 Updates 2026-05-23 16:42:12 +01:00
tben bcdd1f4b7e Updates 2026-05-23 16:40:20 +01:00
tben 47f85d8343 Change updated_at and created_at preference. Insert data can override them. 2026-04-19 11:10:41 +01:00
tben 95d567d4dd Update joins parser. Enforce selectFields unless instructed otherwise 2026-04-19 09:48:38 +01:00
tben 64a6d78506 SQL gen bugfix #5 2026-04-18 19:25:59 +01:00
tben 0309b0dc81 SQL gen bugfix #4 2026-04-18 19:24:55 +01:00
tben ca99684183 SQL gen bugfix #3 2026-04-18 15:30:18 +01:00
tben 9e830cfb74 SQL gen bugfix #2 2026-04-18 15:27:25 +01:00
tben df195412ac SQL gen bugfix 2026-04-18 15:18:44 +01:00
tben 9c5d39edfb Add more features to the query generator 2026-04-18 14:59:23 +01:00
tben f3f1c42699 Major version update. Refactor sql generator function. Add core select directives like SUM, MIN, MAX, etc 2026-04-18 07:24:01 +01:00
tben 0a3320ff83 Updates 2026-04-18 06:02:43 +01:00
tben fbf3622b18 DB Update Bugfix 2026-04-16 17:27:18 +01:00
tben ff5d8082b7 Bugfix 2026-04-16 17:25:41 +01:00
tben b73309e9d5 Bugfix 2026-04-16 17:18:50 +01:00
tben 959465a006 Bugfix 2026-04-16 15:15:33 +01:00
tben 7b2dc81bbb Bugfix 2026-04-16 15:07:38 +01:00
tben ea8a2eab6b Updates 2026-04-16 15:05:35 +01:00
tben af6b44ffbe Updates 2026-04-16 14:36:28 +01:00
tben 613962a925 Update sql equalities. 2026-04-14 20:05:02 +01:00
tben a4aa20baa4 Update sql gen. Add support for raw sql in joins select and regular select sections 2026-04-12 14:15:57 +01:00
tben a57a063f67 Refactor select count strategy. Run the count query together with the normal query 2026-04-12 10:36:32 +01:00
tben 0827cfed11 Pagination Bugfix #3 2026-04-12 08:40:48 +01:00
tben 33f040116d Pagination Bugfix #2 2026-04-12 08:36:21 +01:00
tben eec6ad2785 Pagination Bugfix. 2026-04-12 08:33:29 +01:00
tben dea25b71c2 Add Select pagination 2026-04-12 08:32:00 +01:00
tben 31a7fb40cb Update conflict appenditures. Add updated_at field 2026-04-11 08:58:38 +01:00
tben e6af7de865 Updates 2026-04-10 21:13:11 +01:00
tben 5799a2586e Update sql insert data types 2026-04-05 09:45:29 +01:00
tben d3bfb3a82b Update raw SQL runner 2026-04-05 09:44:09 +01:00
tben f500c52ee5 Fix vector table errors 2026-04-05 09:34:18 +01:00
tben 259a684136 Document typedefs better. Fix tables deletion schema sync issue. 2026-04-05 09:03:47 +01:00
tben 01b96d788e Update schema gen function to be compatible with buffers 2026-04-05 07:40:10 +01:00
tben 88fff6c507 Update insert value types. Allow buffers 2026-04-05 07:37:08 +01:00
tben b3bd5866e6 Update SQL handlers debugging 2026-04-05 07:19:26 +01:00
tben 685d47d91f Change table update strategy to full recreation every time 2026-04-05 07:10:26 +01:00
tben b46ff44dc7 Updates 2026-04-04 17:18:41 +01:00
tben 1a52f1927f Updates 2026-04-04 16:49:01 +01:00
tben 1a96c95f7c Updates 2026-04-02 20:26:01 +01:00
tben eb41e95bd3 Updates 2026-04-02 07:33:04 +01:00