Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions examples/sqlite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// deno-lint-ignore-file no-explicit-any

const db = new Database(":memory:");

try {
// Create sample tables
db.exec(`
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
age INTEGER,
email TEXT
);

CREATE TABLE products (
id INTEGER PRIMARY KEY,
name TEXT,
price REAL,
in_stock INTEGER
);
`);

// Insert with parameters
const insertUserStmt = db.prepare(
"INSERT INTO users (name, age, email) VALUES (?, ?, ?)",
);
insertUserStmt.run("Alice Smith", 25, "alice@example.com");
insertUserStmt.run("Bob Johnson", 30, "bob@example.com");
insertUserStmt.run("Charlie Brown", 28, "charlie@example.com");

// Select with parameters
const usersOver26 = db.prepare("SELECT * FROM users WHERE age > ?").all(26);
console.log("Users over 26:");
usersOver26.forEach((user: any) => {
console.log(`${user.name} (${user.age}): ${user.email}`);
});

// Update with parameters
db.prepare("UPDATE users SET age = ? WHERE name = ?").run(
26,
"Alice Smith",
);

// Complex query with multiple parameters
const filteredUsers = db.prepare(
"SELECT * FROM users WHERE age BETWEEN ? AND ? AND name LIKE ?",
).all(25, 30, "%o%");
console.log("\nUsers aged 25-30 with 'o' in name:");
filteredUsers.forEach((user: any) => {
console.log(`${user.name} (${user.age})`);
});

// Different parameter types
const insertProductStmt = db.prepare(
"INSERT INTO products (id, name, price, in_stock) VALUES (?, ?, ?, ?)",
);
insertProductStmt.run(1, "Laptop", 999.99, true);
insertProductStmt.run(2, "Mouse", 25.50, false);

db.exec("CREATE TABLE nullable_test (id INTEGER, value TEXT)");
const nullStmt = db.prepare(
"INSERT INTO nullable_test (id, value) VALUES (?, ?)",
);
nullStmt.run(1, "not null");
nullStmt.run(2, null);

const nullResults = db.prepare("SELECT * FROM nullable_test").all();
console.log("\nNULL parameter test results:");
nullResults.forEach((row: any) => {
console.log(
`ID: ${row.id}, Value: ${row.value === null ? "NULL" : row.value}`,
);
});
} catch (error) {
console.error("Error:", error);
} finally {
db.close();
}
5 changes: 2 additions & 3 deletions runtime/src/ext/fetch/response/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface ResponseInit {
statusText?: string;
}


class Response {
#response;
#headers: any;
Expand Down Expand Up @@ -47,7 +46,7 @@ class Response {
return this.#response.url;
}

/**
/**
* Returns true if the response is the result of a redirect; otherwise false.
*/
get redirected() {
Expand All @@ -70,7 +69,7 @@ class Response {
return this.#response.statusText;
}

/**
/**
* Gets the headers.
*/
get headers() {
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mod fs;
#[cfg(feature = "storage")]
mod local_storage;
mod process;
#[cfg(feature = "storage")]
mod sqlite;
mod time;
mod url;
mod web;
Expand All @@ -27,6 +29,8 @@ pub use fs::*;
#[cfg(feature = "storage")]
pub use local_storage::*;
pub use process::*;
#[cfg(feature = "storage")]
pub use sqlite::*;
pub use time::*;
pub use url::*;
pub use web::*;
Loading
Loading