Skip to content

fix(sqlite): Statement.run() and Database.exec() now return Changes object#1798

Closed
David Anderson (akapug) wants to merge 2 commits intoelide-dev:mainfrom
akapug:fix/sqlite-run-returns-changes
Closed

fix(sqlite): Statement.run() and Database.exec() now return Changes object#1798
David Anderson (akapug) wants to merge 2 commits intoelide-dev:mainfrom
akapug:fix/sqlite-run-returns-changes

Conversation

@akapug
Copy link
Copy Markdown
Contributor

@akapug David Anderson (akapug) commented Nov 26, 2025

Ready for review Powered by Pull Request Badge

Summary

Updates Statement.run() and Database.exec() to return a Changes object instead of undefined, matching the Bun SQLite API.

Problem

Per the TypeScript types and Bun compatibility, run() and exec() should return a Changes object:

interface Changes {
  changes: number;        // rows affected
  lastInsertRowid: number | bigint;
}

Previously:

  • Statement.run() returned Unit (undefined in JS)
  • Database.exec() returned Undefined.instance

Solution

  1. New SQLiteChanges interface - Defines the contract matching Bun's Changes
  2. SQLiteChangesImpl - Internal implementation as a ProxyObject for JS interop
  3. Updated exec() - Now captures update count and last insert rowid from JDBC
  4. Updated run() - Returns the result from exec()

Changes

File Change
SQLiteChanges.kt New interface
SQLiteStatement.kt run() returns SQLiteChanges
SQLiteDatabase.kt exec() returns SQLiteChanges
SqliteModule.kt Implementation

Usage

const db = new Database(":memory:");
db.run("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");

const result = db.run("INSERT INTO users (name) VALUES (?)", ["Alice"]);
console.log(result.changes);        // 1
console.log(result.lastInsertRowid); // 1

Fixes

Fixes #1791

…bject

Previously, run() returned undefined and exec() returned Undefined.instance.
Now both return a SQLiteChanges object with:
- changes: number of affected rows
- lastInsertRowid: rowid of the last inserted row

This matches the Bun SQLite API behavior.

Fixes elide-dev#1791
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite run() returns undefined instead of Changes object

2 participants