diff --git a/docs/bundler/fullstack.mdx b/docs/bundler/fullstack.mdx index 937d41d39facc0..c17035d462e196 100644 --- a/docs/bundler/fullstack.mdx +++ b/docs/bundler/fullstack.mdx @@ -547,7 +547,7 @@ import dashboard from "./public/dashboard.html"; // Initialize database const db = new Database("app.db"); -db.exec(` +db.run(` CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, diff --git a/docs/runtime/http/server.mdx b/docs/runtime/http/server.mdx index f230f1e7ea7add..b39c3037ae2be9 100644 --- a/docs/runtime/http/server.mdx +++ b/docs/runtime/http/server.mdx @@ -415,7 +415,7 @@ import type { Post } from "./types.ts"; import { Database } from "bun:sqlite"; const db = new Database("posts.db"); -db.exec(` +db.run(` CREATE TABLE IF NOT EXISTS posts ( id TEXT PRIMARY KEY, title TEXT NOT NULL, diff --git a/docs/runtime/sqlite.mdx b/docs/runtime/sqlite.mdx index 14c2663e91538d..bf16f64053352a 100644 --- a/docs/runtime/sqlite.mdx +++ b/docs/runtime/sqlite.mdx @@ -190,7 +190,7 @@ SQLite supports [write-ahead log mode](https://www.sqlite.org/wal.html) (WAL) wh To enable WAL mode, run this pragma query at the beginning of your application: ```ts db.ts icon="/icons/typescript.svg" -db.exec("PRAGMA journal_mode = WAL;"); +db.run("PRAGMA journal_mode = WAL;"); ``` diff --git a/packages/bun-types/sqlite.d.ts b/packages/bun-types/sqlite.d.ts index 47ef366629a1b9..5cd3c4b957c50e 100644 --- a/packages/bun-types/sqlite.d.ts +++ b/packages/bun-types/sqlite.d.ts @@ -361,7 +361,7 @@ declare module "bun:sqlite" { * // setup * import { Database } from "bun:sqlite"; * const db = Database.open(":memory:"); - * db.exec( + * db.run( * "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)" * ); * @@ -423,9 +423,9 @@ declare module "bun:sqlite" { * ```ts * test("supports serialize/deserialize", () => { * const db = Database.open(":memory:"); - * db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)"); - * db.exec('INSERT INTO test (name) VALUES ("Hello")'); - * db.exec('INSERT INTO test (name) VALUES ("World")'); + * db.run("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)"); + * db.run('INSERT INTO test (name) VALUES ("Hello")'); + * db.run('INSERT INTO test (name) VALUES ("World")'); * * const input = db.serialize(); * const db2 = new Database(input); @@ -450,7 +450,7 @@ declare module "bun:sqlite" { * }, * ]), * ); - * db2.exec("insert into test (name) values ('foo')"); + * db2.run("insert into test (name) values ('foo')"); * expect(JSON.stringify(stmt.all())).toBe( * JSON.stringify([ * { @@ -470,7 +470,7 @@ declare module "bun:sqlite" { * * const db3 = Database.deserialize(input, true); * try { - * db3.exec("insert into test (name) values ('foo')"); + * db3.run("insert into test (name) values ('foo')"); * throw new Error("Expected error"); * } catch (e) { * expect(e.message).toBe("attempt to write a readonly database"); @@ -493,9 +493,9 @@ declare module "bun:sqlite" { * ```ts * test("supports serialize/deserialize", () => { * const db = Database.open(":memory:"); - * db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)"); - * db.exec('INSERT INTO test (name) VALUES ("Hello")'); - * db.exec('INSERT INTO test (name) VALUES ("World")'); + * db.run("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)"); + * db.run('INSERT INTO test (name) VALUES ("Hello")'); + * db.run('INSERT INTO test (name) VALUES ("World")'); * * const input = db.serialize(); * const db2 = Database.deserialize(input, { strict: true }); @@ -520,7 +520,7 @@ declare module "bun:sqlite" { * }, * ]), * ); - * db2.exec("insert into test (name) values ($foo)", { foo: "baz" }); + * db2.run("insert into test (name) values ($foo)", { foo: "baz" }); * expect(JSON.stringify(stmt.all())).toBe( * JSON.stringify([ * { @@ -540,7 +540,7 @@ declare module "bun:sqlite" { * * const db3 = Database.deserialize(input, { readonly: true, strict: true }); * try { - * db3.exec("insert into test (name) values ($foo)", { foo: "baz" }); + * db3.run("insert into test (name) values ($foo)", { foo: "baz" }); * throw new Error("Expected error"); * } catch (e) { * expect(e.message).toBe("attempt to write a readonly database"); @@ -925,7 +925,7 @@ declare module "bun:sqlite" { * } * * const db = new Database(":memory:"); - * db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, rawBirthdate TEXT)"); + * db.run("CREATE TABLE users (id INTEGER PRIMARY KEY, rawBirthdate TEXT)"); * db.run("INSERT INTO users (rawBirthdate) VALUES ('1995-12-19')"); * const query = db.query("SELECT * FROM users"); * query.as(User); @@ -1108,7 +1108,7 @@ declare module "bun:sqlite" { * const db = Database.open("mydb.sqlite"); * db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0); * // enable WAL - * db.exec("PRAGMA journal_mode = WAL"); + * db.run("PRAGMA journal_mode = WAL"); * // .. do some work * db.close(); * ```