@observablehq/notebook-kit 1.1.0-rc.11 → 1.1.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +2 -1
- package/dist/src/databases/index.js +1 -1
- package/dist/src/databases/sqlite-bun.d.ts +2 -0
- package/dist/src/databases/sqlite-bun.js +30 -0
- package/dist/src/databases/sqlite-node.d.ts +2 -0
- package/dist/src/databases/sqlite-node.js +29 -0
- package/dist/src/databases/sqlite.d.ts +2 -2
- package/dist/src/databases/sqlite.js +1 -29
- package/package.json +2 -1
package/dist/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/observablehq/notebook-kit.git"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.1.0-rc.
|
|
8
|
+
"version": "1.1.0-rc.13",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "vitest",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"@eslint/js": "^9.29.0",
|
|
68
68
|
"@types/jsdom": "^21.1.7",
|
|
69
69
|
"@types/markdown-it": "^14.1.2",
|
|
70
|
+
"bun-types": "^1.2.20",
|
|
70
71
|
"eslint": "^9.29.0",
|
|
71
72
|
"globals": "^16.2.0",
|
|
72
73
|
"htl": "^0.3.1",
|
|
@@ -38,7 +38,7 @@ export async function getDatabase(config, context) {
|
|
|
38
38
|
case "duckdb":
|
|
39
39
|
return (await import("./duckdb.js")).default(config, context);
|
|
40
40
|
case "sqlite":
|
|
41
|
-
return (await import("./sqlite.js")).default(config, context);
|
|
41
|
+
return (await (typeof Bun !== "undefined" ? import("./sqlite-bun.js") : import("./sqlite-node.js"))).default(config, context);
|
|
42
42
|
case "snowflake":
|
|
43
43
|
return (await import("./snowflake.js")).default(config);
|
|
44
44
|
case "postgres":
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { Database } from "bun:sqlite";
|
|
3
|
+
import { getColumnType } from "./sqlite.js";
|
|
4
|
+
export default function sqlite({ path = ":memory:" }, context) {
|
|
5
|
+
if (path !== undefined)
|
|
6
|
+
path = join(context.cwd, path);
|
|
7
|
+
return async (strings, ...params) => {
|
|
8
|
+
const date = new Date();
|
|
9
|
+
const database = new Database(path);
|
|
10
|
+
try {
|
|
11
|
+
const statement = database.prepare(strings.join("?"));
|
|
12
|
+
const rows = statement.all(...params);
|
|
13
|
+
return {
|
|
14
|
+
rows,
|
|
15
|
+
schema: getStatementSchema(statement),
|
|
16
|
+
duration: Date.now() - +date,
|
|
17
|
+
date
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
database.close();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function getStatementSchema(statement) {
|
|
26
|
+
return statement.columnNames.map((name, i) => ({
|
|
27
|
+
name,
|
|
28
|
+
type: getColumnType(statement.columnTypes[i])
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { DatabaseSync } from "node:sqlite";
|
|
3
|
+
import { getColumnType } from "./sqlite.js";
|
|
4
|
+
export default function sqlite({ path = ":memory:" }, context) {
|
|
5
|
+
if (path !== undefined)
|
|
6
|
+
path = join(context.cwd, path);
|
|
7
|
+
return async (strings, ...params) => {
|
|
8
|
+
const date = new Date();
|
|
9
|
+
const database = new DatabaseSync(path);
|
|
10
|
+
try {
|
|
11
|
+
const statement = database.prepare(strings.join("?"));
|
|
12
|
+
const rows = statement.all(...params);
|
|
13
|
+
return {
|
|
14
|
+
rows,
|
|
15
|
+
schema: getStatementSchema(statement),
|
|
16
|
+
duration: Date.now() - +date,
|
|
17
|
+
date
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
database.close();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function getStatementSchema(statement) {
|
|
26
|
+
return statement
|
|
27
|
+
.columns()
|
|
28
|
+
.map((column) => ({ name: column.name, type: getColumnType(column.type) }));
|
|
29
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
1
|
+
import type { ColumnSchema } from "../runtime/index.js";
|
|
2
|
+
export declare function getColumnType(type: string | null): ColumnSchema["type"];
|
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { DatabaseSync } from "node:sqlite";
|
|
3
|
-
export default function sqlite({ path = ":memory:" }, context) {
|
|
4
|
-
if (path !== undefined)
|
|
5
|
-
path = join(context.cwd, path);
|
|
6
|
-
return async (strings, ...params) => {
|
|
7
|
-
const date = new Date();
|
|
8
|
-
const database = new DatabaseSync(path);
|
|
9
|
-
try {
|
|
10
|
-
const statement = database.prepare(strings.join("?"));
|
|
11
|
-
const rows = statement.all(...params);
|
|
12
|
-
return {
|
|
13
|
-
rows,
|
|
14
|
-
schema: getStatementSchema(statement),
|
|
15
|
-
duration: Date.now() - +date,
|
|
16
|
-
date
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
database.close();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function getStatementSchema(statement) {
|
|
25
|
-
return statement
|
|
26
|
-
.columns()
|
|
27
|
-
.map((column) => ({ name: column.name, type: getColumnType(column.type) }));
|
|
28
|
-
}
|
|
29
|
-
function getColumnType(type) {
|
|
1
|
+
export function getColumnType(type) {
|
|
30
2
|
switch (type) {
|
|
31
3
|
case "INT":
|
|
32
4
|
case "INTEGER":
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/observablehq/notebook-kit.git"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.1.0-rc.
|
|
8
|
+
"version": "1.1.0-rc.13",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "vitest",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"@eslint/js": "^9.29.0",
|
|
68
68
|
"@types/jsdom": "^21.1.7",
|
|
69
69
|
"@types/markdown-it": "^14.1.2",
|
|
70
|
+
"bun-types": "^1.2.20",
|
|
70
71
|
"eslint": "^9.29.0",
|
|
71
72
|
"globals": "^16.2.0",
|
|
72
73
|
"htl": "^0.3.1",
|