Skip to content

Commit

Permalink
fix(ext/node): DatabaseSync#exec should execute batch statements (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Feb 11, 2025
1 parent acdc7dc commit 196ceb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ext/node/ops/sqlite/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ impl DatabaseSync {
let db = self.conn.borrow();
let db = db.as_ref().ok_or(SqliteError::InUse)?;

let mut stmt = db.prepare_cached(sql)?;
stmt.raw_execute()?;
db.execute_batch(sql)?;

Ok(())
}
Expand Down
13 changes: 13 additions & 0 deletions tests/unit_node/sqlite_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,16 @@ Deno.test("[node/sqlite] applyChangeset across databases", () => {
{ key: 2, value: "world", __proto__: null },
]);
});

Deno.test("[node/sqlite] exec should execute batch statements", () => {
const db = new DatabaseSync(":memory:");
db.exec(`CREATE TABLE one(id int PRIMARY KEY) STRICT;
CREATE TABLE two(id int PRIMARY KEY) STRICT;`);

const table = db.prepare(
`SELECT name FROM sqlite_master WHERE type='table'`,
).all();
assertEquals(table.length, 2);

db.close();
});

0 comments on commit 196ceb7

Please sign in to comment.