fix(Bun.SQL) fix command detection on sqlite (#23221)

### What does this PR do?
Returning clause should work with insert now
### How did you verify your code works?
Tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Ciro Spaciari
2025-10-03 17:50:47 -07:00
committed by GitHub
parent f1204ea2fd
commit e3bd03628a
2 changed files with 174 additions and 242 deletions

View File

@@ -1055,7 +1055,6 @@ describe("Template Literal Security", () => {
await sql.close();
});
});
describe("Transactions", () => {
let sql: SQL;
@@ -1185,6 +1184,36 @@ describe("SQLite-specific features", () => {
expect(results[0].id).toBe(1);
expect(results[1].id).toBe(3);
});
test("returning clause on insert statements", async () => {
await using sql = new SQL("sqlite://:memory:");
await sql`
create table users (
id integer primary key,
name text not null,
verified integer not null default 0,
created_at integer not null default (strftime('%s', 'now'))
)`;
const result =
await sql`insert into "users" ("id", "name", "verified", "created_at") values (null, ${"John"}, ${0}, strftime('%s', 'now')), (null, ${"Bruce"}, ${0}, strftime('%s', 'now')), (null, ${"Jane"}, ${0}, strftime('%s', 'now')), (null, ${"Austin"}, ${0}, strftime('%s', 'now')) returning "id", "name", "verified"`;
expect(result[0].id).toBe(1);
expect(result[0].name).toBe("John");
expect(result[0].verified).toBe(0);
expect(result[1].id).toBe(2);
expect(result[1].name).toBe("Bruce");
expect(result[1].verified).toBe(0);
expect(result[2].id).toBe(3);
expect(result[2].name).toBe("Jane");
expect(result[2].verified).toBe(0);
expect(result[3].id).toBe(4);
expect(result[3].name).toBe("Austin");
expect(result[3].verified).toBe(0);
const [{ 'upper("name")': upperName }] =
await sql`insert into "users" ("id", "name", "verified", "created_at") values (null, ${"John"}, ${0}, strftime('%s', 'now')) returning upper("name")`;
expect(upperName).toBe("JOHN");
});
test("last_insert_rowid()", async () => {
await sql`CREATE TABLE rowid_test (id INTEGER PRIMARY KEY, value TEXT)`;