Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ext/node): implement node:sqlite #27308

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 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
37 changes: 20 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
littledivy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.324.0" }
deno_core = { version = "0.326.0" }

deno_bench_util = { version = "0.176.0", path = "./bench_util" }
deno_config = { version = "=0.39.3", features = ["workspace", "sync"] }
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
littledivy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa
deno_cache_dir.workspace = true
deno_config.workspace = true
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "=0.161.2", features = ["rust", "comrak"] }
deno_doc = { version = "=0.161.3", features = ["rust", "comrak"] }
deno_graph = { version = "=0.86.3" }
deno_lint = { version = "=0.68.2", features = ["docs"] }
deno_lockfile.workspace = true
Expand Down
36 changes: 36 additions & 0 deletions cli/bench/sqlite.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but... we should have a deno.json file in cli/bench to run various benchmarks. I never remember how to run them and it feels like half of them are already code-rotted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-console

import { DatabaseSync } from "node:sqlite";
import fs from "node:fs";

function bench(name, fun, count = 10000) {
const start = Date.now();
for (let i = 0; i < count; i++) fun();
const elapsed = Date.now() - start;
const rate = Math.floor(count / (elapsed / 1000));
console.log(` ${name}: time ${elapsed} ms rate ${rate}`);
}

for (const name of [":memory:", "test.db"]) {
console.log(`Benchmarking ${name}`);
try {
fs.unlinkSync(name);
} catch {
// Ignore
}

const db = new DatabaseSync(name);
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");

bench("prepare", () => db.prepare("SELECT * FROM test"));
bench("exec", () => db.exec("INSERT INTO test (name) VALUES ('foo')"));

const stmt = db.prepare("SELECT * FROM test");
bench("get", () => stmt.get());

const stmt2 = db.prepare("SELECT * FROM test WHERE id = ?");
bench("get (integer bind)", () => stmt2.get(1));

bench("all", () => stmt.all(), 1000);
}
1 change: 1 addition & 0 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4496,6 +4496,7 @@ impl<'a> ToV8<'a> for TscRequestArray {

let method_name = deno_core::FastString::from_static(method_name)
.v8_string(scope)
.unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I must have missed that. Why is it now a Result/Option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.into();
let args = args.unwrap_or_else(|| v8::Array::new(scope, 0).into());
let scope_url = serde_v8::to_v8(scope, self.scope)
Expand Down
1 change: 1 addition & 0 deletions ext/fs/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ impl<'s> ToV8<'s> for V8MaybeStaticStr {
Cow::Owned(value) => value.into(),
}
.v8_string(scope)
.unwrap()
.into(),
)
}
Expand Down
2 changes: 2 additions & 0 deletions ext/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ipnetwork = "0.20.0"
k256 = "0.13.1"
lazy-regex.workspace = true
libc.workspace = true
libsqlite3-sys = "0.30.1"
libz-sys.workspace = true
md-5 = { version = "0.10.5", features = ["oid"] }
md4 = "0.10.2"
Expand All @@ -82,6 +83,7 @@ regex.workspace = true
ring.workspace = true
ripemd = { version = "0.1.3", features = ["oid"] }
rsa.workspace = true
rusqlite.workspace = true
scrypt = "0.11.0"
sec1.workspace = true
serde = "1.0.149"
Expand Down
5 changes: 4 additions & 1 deletion ext/node/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ deno_core::extension!(deno_node,
ops::inspector::op_inspector_enabled,
],
objects = [
ops::perf_hooks::EldHistogram
ops::perf_hooks::EldHistogram,
ops::sqlite::DatabaseSync,
ops::sqlite::StatementSync
],
esm_entry_point = "ext:deno_node/02_init.js",
esm = [
Expand Down Expand Up @@ -655,6 +657,7 @@ deno_core::extension!(deno_node,
"node:readline" = "readline.ts",
"node:readline/promises" = "readline/promises.ts",
"node:repl" = "repl.ts",
"node:sqlite" = "sqlite.ts",
"node:stream" = "stream.ts",
"node:stream/consumers" = "stream/consumers.mjs",
"node:stream/promises" = "stream/promises.mjs",
Expand Down
1 change: 1 addition & 0 deletions ext/node/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod os;
pub mod perf_hooks;
pub mod process;
pub mod require;
pub mod sqlite;
pub mod tls;
pub mod util;
pub mod v8;
Expand Down
Loading
Loading