Skip to content

Add native sqlite Kysely dialect#78921

Merged
steipete merged 4 commits intomainfrom
steipete/kysely-node-sqlite-node-22-16
May 7, 2026
Merged

Add native sqlite Kysely dialect#78921
steipete merged 4 commits intomainfrom
steipete/kysely-node-sqlite-node-22-16

Conversation

@steipete
Copy link
Copy Markdown
Contributor

@steipete steipete commented May 7, 2026

Summary

  • add a small owned Kysely dialect for native node:sqlite
  • add a regression test covering builder selects, raw selects, and INSERT ... RETURNING
  • add root dependency ownership metadata for Kysely and raise the supported Node floor to >=22.16.0 so StatementSync.columns() is always available
  • update install/runtime docs, README, SECURITY, and changelog for the new Node 22 floor

Real behavior proof

  • Behavior or issue addressed: Kysely can execute builder selects, raw selects, and INSERT ... RETURNING through OpenClaw's owned native node:sqlite dialect without depending on a third-party adapter.
  • Real environment tested: Local OpenClaw checkout on macOS, Node v25.9.0, native node:sqlite, in-memory SQLite database.
  • Exact steps or command run after this patch: Ran a live smoke command with pnpm exec tsx --no-warnings --eval '...' that imported NodeSqliteKyselyDialect, created a table, inserted/select rows, and exercised raw SQL.
  • Evidence after fix: Terminal output from the live command:
{"node":"25.9.0","selected":{"id":1,"name":"Ada"},"returning":{"id":2,"name":"Grace"},"raw":{"name":"Grace"}}
  • Observed result after fix: The native sqlite dialect returned the inserted row from the builder select, returned the row from INSERT ... RETURNING, and returned the same row through raw SQL.
  • What was not tested: No persistent on-disk database or concurrent connection stress test in this PR.

Verification

  • pnpm test src/infra/runtime-guard.test.ts src/daemon/runtime-paths.test.ts src/daemon/service-env.test.ts src/cli/update-cli.test.ts src/infra/update-check.test.ts src/infra/kysely-node-sqlite.test.ts test/scripts/root-dependency-ownership-audit.test.ts
  • pnpm test extensions/memory-core
  • pnpm tsgo:core
  • pnpm tsgo:extensions
  • pnpm exec oxlint src/infra/kysely-node-sqlite.ts src/infra/kysely-node-sqlite.test.ts src/infra/runtime-guard.ts src/infra/runtime-guard.test.ts src/daemon/runtime-paths.ts src/daemon/runtime-paths.test.ts src/daemon/service-env.test.ts src/cli/update-cli/update-command.ts src/cli/update-cli.test.ts src/infra/update-check.test.ts src/commands/doctor-gateway-services.ts src/daemon/service-audit.ts src/daemon/program-args.ts extensions/memory-core/src/memory/provider-adapters.ts
  • pnpm deadcode:dependencies
  • pnpm deadcode:unused-files
  • git diff --check origin/main...HEAD

@steipete steipete requested a review from a team as a code owner May 7, 2026 11:53
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos gateway Gateway runtime extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations size: M maintainer Maintainer-authored PR labels May 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0662aeda99

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +154 to +157
const { changes, lastInsertRowid } = stmt.run(...sqliteParameters);
return Promise.resolve({
insertId: BigInt(lastInsertRowid),
numAffectedRows: BigInt(changes),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid returning stale insertId from stmt.run results

node:sqlite documents lastInsertRowid as the most recent insert rowid on the connection, not the rowid for the statement that just ran. Because this dialect always maps stmt.run(...).lastInsertRowid into insertId, any non-insert statement (or insert paths that do not actually insert, such as conflict-ignore flows) can surface a stale insertId from an earlier insert, which makes Kysely insert results incorrect for callers that depend on insertId semantics.

Useful? React with 👍 / 👎.

@steipete
Copy link
Copy Markdown
Contributor Author

steipete commented May 7, 2026

Addressed Codex review on stale insertId: src/infra/kysely-node-sqlite.ts now only returns insertId for insert statements with changes > 0, and src/infra/kysely-node-sqlite.test.ts covers ignored inserts and updates so connection-level lastInsertRowid cannot leak into non-insert results.

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 7, 2026

ClawSweeper status: review started.

I am starting a fresh review of this pull request: Add native sqlite Kysely dialect This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 838a59cdfc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

numAffectedRows: BigInt(changes),
rows: [],
};
if (isInsertStatement(sql) && changes > 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve insertId for INSERT forms beyond plain INSERT

The insertId assignment is gated by isInsertStatement(sql), which only matches SQL text starting with insert. This drops insertId for valid insert-producing statements like WITH ... INSERT ... (CTE inserts) and REPLACE INTO ..., even when stmt.run() reports changes > 0 and a valid lastInsertRowid. In those cases Kysely callers get an incomplete InsertResult despite a successful write, which can break flows that depend on the returned id.

Useful? React with 👍 / 👎.

@steipete steipete merged commit 955b025 into main May 7, 2026
85 checks passed
@steipete steipete deleted the steipete/kysely-node-sqlite-node-22-16 branch May 7, 2026 12:07
@steipete
Copy link
Copy Markdown
Contributor Author

steipete commented May 7, 2026

Landed via squash merge onto main.

  • Source head: 838a59c
  • Merge commit: 955b025
  • Local proof: targeted Kysely/native sqlite test, runtime/update/daemon tests, memory-core tests, tsgo:core, tsgo:extensions, dependency scan, lint, and diff sanity.
  • CI proof: Real behavior proof, check-dependencies, check-docs, and front CI/security/workflow sanity checks green before merge; GitHub accepted the squash merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: memory-core Extension: memory-core gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant