rado 1.3.0-preview.2 → 1.3.0-preview.3

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/README.md CHANGED
@@ -121,6 +121,7 @@ const db = connect(new Database('app.db'))
121
121
  | PostgreSQL | [@neondatabase/serverless](https://www.npmjs.com/package/@neondatabase/serverless) | `rado/driver/pg` | async |
122
122
  | PostgreSQL | [@vercel/postgres](https://www.npmjs.com/package/@vercel/postgres) | `rado/driver/pg` | async |
123
123
  | SQLite | [better-sqlite3](https://www.npmjs.com/package/better-sqlite3) | `rado/driver/better-sqlite3` | sync |
124
+ | SQLite | `node:sqlite` | `rado/driver/node-sqlite` | sync |
124
125
  | SQLite | `bun:sqlite` | `rado/driver/bun-sqlite` | sync |
125
126
  | SQLite | [sql.js](https://www.npmjs.com/package/sql.js) | `rado/driver/sql.js` | sync |
126
127
  | SQLite | [@libsql/client](https://www.npmjs.com/package/@libsql/client) | `rado/driver/libsql` | async |
@@ -0,0 +1,14 @@
1
+ import { SyncDatabase } from '../core/Database.js';
2
+ interface Client {
3
+ close(): void;
4
+ exec(query: string): void;
5
+ prepare(sql: string): Statement;
6
+ }
7
+ interface Statement {
8
+ all(...params: Array<unknown>): Array<object>;
9
+ run(...params: Array<unknown>): unknown;
10
+ get(...params: Array<unknown>): object | null;
11
+ setReturnArrays(value: boolean): void;
12
+ }
13
+ export declare function connect(db: Client): SyncDatabase<'sqlite'>;
14
+ export {};
@@ -0,0 +1,78 @@
1
+ // src/driver/node-sqlite.ts
2
+ import { SyncDatabase } from "../core/Database.js";
3
+ import { sqliteDialect } from "../sqlite.js";
4
+ import { sqliteDiff } from "../sqlite/diff.js";
5
+ import { execTransaction } from "../sqlite/transactions.js";
6
+ var PreparedStatement = class {
7
+ constructor(stmt, isSelection) {
8
+ this.stmt = stmt;
9
+ this.isSelection = isSelection;
10
+ }
11
+ stmt;
12
+ isSelection;
13
+ all(params) {
14
+ return this.stmt.all(...params);
15
+ }
16
+ run(params) {
17
+ this.stmt.run(...params);
18
+ }
19
+ get(params) {
20
+ return this.stmt.get(...params);
21
+ }
22
+ values(params) {
23
+ if (!this.isSelection) {
24
+ this.stmt.run(...params);
25
+ return [];
26
+ }
27
+ this.stmt.setReturnArrays(true);
28
+ try {
29
+ return this.stmt.all(...params);
30
+ } finally {
31
+ this.stmt.setReturnArrays(false);
32
+ }
33
+ }
34
+ free() {
35
+ }
36
+ };
37
+ var NodeSqliteDriver = class _NodeSqliteDriver {
38
+ constructor(client, depth = 0) {
39
+ this.client = client;
40
+ this.depth = depth;
41
+ }
42
+ client;
43
+ depth;
44
+ parsesJson = false;
45
+ supportsTransactions = true;
46
+ exec(query) {
47
+ this.client.exec(query);
48
+ }
49
+ close() {
50
+ this.client.close();
51
+ }
52
+ prepare(sql, options) {
53
+ return new PreparedStatement(this.client.prepare(sql), options.isSelection);
54
+ }
55
+ batch(queries) {
56
+ return this.transaction(
57
+ (tx) => queries.map(
58
+ ({ sql, params, isSelection }) => tx.prepare(sql, { isSelection }).values(params)
59
+ ),
60
+ {}
61
+ );
62
+ }
63
+ transaction(run, options) {
64
+ return execTransaction(
65
+ this,
66
+ this.depth,
67
+ (depth) => new _NodeSqliteDriver(this.client, depth),
68
+ run,
69
+ options
70
+ );
71
+ }
72
+ };
73
+ function connect(db) {
74
+ return new SyncDatabase(new NodeSqliteDriver(db), sqliteDialect, sqliteDiff);
75
+ }
76
+ export {
77
+ connect
78
+ };
package/dist/driver.d.ts CHANGED
@@ -3,6 +3,7 @@ export { connect as 'bun:sqlite' } from './driver/bun-sqlite.js';
3
3
  export { connect as 'd1' } from './driver/d1.js';
4
4
  export { connect as '@libsql/client' } from './driver/libsql.js';
5
5
  export { connect as 'mysql2' } from './driver/mysql2.js';
6
+ export { connect as 'node:sqlite' } from './driver/node-sqlite.js';
6
7
  export { connect as '@neondatabase/serverless', connect as '@vercel/postgres', connect as 'pg' } from './driver/pg.js';
7
8
  export { connect as '@electric-sql/pglite' } from './driver/pglite.js';
8
9
  export { connect as 'sql.js' } from './driver/sql.js.js';
package/dist/driver.js CHANGED
@@ -4,22 +4,24 @@ import { connect as connect2 } from "./driver/bun-sqlite.js";
4
4
  import { connect as connect3 } from "./driver/d1.js";
5
5
  import { connect as connect4 } from "./driver/libsql.js";
6
6
  import { connect as connect5 } from "./driver/mysql2.js";
7
+ import { connect as connect6 } from "./driver/node-sqlite.js";
7
8
  import {
8
- connect as connect6,
9
9
  connect as connect7,
10
- connect as connect8
10
+ connect as connect8,
11
+ connect as connect9
11
12
  } from "./driver/pg.js";
12
- import { connect as connect9 } from "./driver/pglite.js";
13
- import { connect as connect10 } from "./driver/sql.js.js";
13
+ import { connect as connect10 } from "./driver/pglite.js";
14
+ import { connect as connect11 } from "./driver/sql.js.js";
14
15
  export {
15
- connect9 as "@electric-sql/pglite",
16
+ connect10 as "@electric-sql/pglite",
16
17
  connect4 as "@libsql/client",
17
- connect6 as "@neondatabase/serverless",
18
- connect7 as "@vercel/postgres",
18
+ connect7 as "@neondatabase/serverless",
19
+ connect8 as "@vercel/postgres",
19
20
  connect as "better-sqlite3",
20
21
  connect2 as "bun:sqlite",
21
22
  connect3 as d1,
22
23
  connect5 as mysql2,
23
- connect8 as pg,
24
- connect10 as "sql.js"
24
+ connect6 as "node:sqlite",
25
+ connect9 as pg,
26
+ connect11 as "sql.js"
25
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "1.3.0-preview.2",
3
+ "version": "1.3.0-preview.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",