rado 1.0.9 → 1.0.10

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
@@ -150,14 +150,23 @@ const PostTags = table({
150
150
 
151
151
  Currently supported drivers:
152
152
 
153
- | Driver | import |
154
- | ---------------- | ------------------------------ |
155
- | `better-sqlite3` | `'rado/driver/better-sqlite3'` |
156
- | `bun-sqlite` | `'rado/driver/bun-sqlite'` |
157
- | `mysql2` | `'rado/driver/mysql2'` |
158
- | `pg` | `'rado/driver/pg'` |
159
- | `pglite` | `'rado/driver/pglite'` |
160
- | `sql.js` | `'rado/driver/sql.js'` |
153
+ | `PostgreSQL ` | `import ` |
154
+ | -------------------------- | ------------------------------ |
155
+ | `pg` | `'rado/driver/pg'` |
156
+ | `@electric-sql/pglite` | `'rado/driver/pglite'` |
157
+ | `@neondatabase/serverless` | `'rado/driver/pg'` |
158
+ | `@vercel/postgres` | `'rado/driver/pg'` |
159
+
160
+ | `SQLite ` | `import ` |
161
+ | -------------------------- | ------------------------------ |
162
+ | `better-sqlite3` | `'rado/driver/better-sqlite3'` |
163
+ | `bun:sqlite` | `'rado/driver/bun-sqlite'` |
164
+ | `sql.js` | `'rado/driver/sql.js'` |
165
+ | `Cloudflare D1` | `'rado/driver/d1'` |
166
+
167
+ | `MySQL ` | `import ` |
168
+ | -------------------------- | ------------------------------ |
169
+ | `mysql2` | `'rado/driver/mysql2'` |
161
170
 
162
171
  Pass an instance of the database to the `connect` function to get started:
163
172
 
@@ -26,9 +26,13 @@ var Executable = class {
26
26
  return this.#execute();
27
27
  }
28
28
  // biome-ignore lint/suspicious/noThenProperty:
29
- then(onfulfilled, onrejected) {
30
- const result = this.#execute();
31
- return Promise.resolve(result).then(onfulfilled, onrejected);
29
+ async then(onfulfilled, onrejected) {
30
+ try {
31
+ const result = await this.#execute();
32
+ return onfulfilled ? onfulfilled(result) : result;
33
+ } catch (error) {
34
+ return onrejected ? onrejected(error) : Promise.reject(error);
35
+ }
32
36
  }
33
37
  catch(onrejected) {
34
38
  return this.then().catch(onrejected);
@@ -13,8 +13,10 @@ var Include = class {
13
13
  #mapFromDriverValue = (value, specs) => {
14
14
  const { select, first } = getData(this);
15
15
  const parsed = specs.parsesJson ? value : JSON.parse(value);
16
- if (first)
17
- return parsed ? select.mapRow({ values: parsed, index: 0, specs }) : null;
16
+ if (first) {
17
+ const result = parsed ? select.mapRow({ values: parsed, index: 0, specs }) : null;
18
+ return result;
19
+ }
18
20
  if (!parsed) return [];
19
21
  const rows = parsed;
20
22
  const ctx = {
@@ -18,7 +18,8 @@ var PreparedStatement = class {
18
18
  return this.stmt.get(...params);
19
19
  }
20
20
  values(params) {
21
- if (this.isSelection) return this.stmt.raw(true).all(...params);
21
+ if (this.isSelection)
22
+ return this.stmt.raw(true).all(...params);
22
23
  this.stmt.run(...params);
23
24
  return [];
24
25
  }
@@ -0,0 +1,25 @@
1
+ import { AsyncDatabase } from '../core/Database.js';
2
+ import type { AsyncDriver, AsyncStatement, BatchQuery, PrepareOptions } from '../core/Driver.js';
3
+ type Client = D1Database;
4
+ declare class PreparedStatement implements AsyncStatement {
5
+ private stmt;
6
+ private isSelection;
7
+ constructor(stmt: D1PreparedStatement, isSelection: boolean);
8
+ all(params: Array<unknown>): Promise<Array<object>>;
9
+ run(params: Array<unknown>): Promise<void>;
10
+ get(params: Array<unknown>): Promise<object | null>;
11
+ values(params: Array<unknown>): Promise<Array<Array<unknown>>>;
12
+ free(): void;
13
+ }
14
+ export declare class D1Driver implements AsyncDriver {
15
+ private client;
16
+ parsesJson: boolean;
17
+ constructor(client: Client);
18
+ exec(query: string): Promise<void>;
19
+ prepare(sql: string, options: PrepareOptions): PreparedStatement;
20
+ close(): Promise<void>;
21
+ batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
22
+ transaction<T>(): Promise<T>;
23
+ }
24
+ export declare function connect(client: Client): AsyncDatabase<'sqlite'>;
25
+ export {};
@@ -0,0 +1,60 @@
1
+ // src/driver/d1.ts
2
+ import { AsyncDatabase } from "../core/Database.js";
3
+ import { sqliteDialect } from "../sqlite.js";
4
+ import { sqliteDiff } from "../sqlite/diff.js";
5
+ var PreparedStatement = class {
6
+ constructor(stmt, isSelection) {
7
+ this.stmt = stmt;
8
+ this.isSelection = isSelection;
9
+ }
10
+ async all(params) {
11
+ return this.stmt.bind(...params).all().then(({ results }) => results);
12
+ }
13
+ async run(params) {
14
+ const results = await this.stmt.bind(...params).run();
15
+ }
16
+ async get(params) {
17
+ return this.stmt.bind(...params).first();
18
+ }
19
+ async values(params) {
20
+ if (this.isSelection) {
21
+ const results = await this.stmt.bind(...params).raw();
22
+ console.log(results);
23
+ return results;
24
+ }
25
+ await this.stmt.bind(...params).run();
26
+ return [];
27
+ }
28
+ free() {
29
+ }
30
+ };
31
+ var D1Driver = class {
32
+ constructor(client) {
33
+ this.client = client;
34
+ }
35
+ parsesJson = false;
36
+ async exec(query) {
37
+ await this.client.exec(query);
38
+ }
39
+ prepare(sql, options) {
40
+ return new PreparedStatement(this.client.prepare(sql), options.isSelection);
41
+ }
42
+ async close() {
43
+ }
44
+ async batch(queries) {
45
+ const results = [];
46
+ for (const { sql, params, isSelection } of queries)
47
+ results.push(await this.prepare(sql, { isSelection }).values(params));
48
+ return results;
49
+ }
50
+ async transaction() {
51
+ throw new Error("Transactions are not supported in D1");
52
+ }
53
+ };
54
+ function connect(client) {
55
+ return new AsyncDatabase(new D1Driver(client), sqliteDialect, sqliteDiff);
56
+ }
57
+ export {
58
+ D1Driver,
59
+ connect
60
+ };
@@ -1,6 +1,6 @@
1
1
  import type { PGlite, Transaction } from '@electric-sql/pglite';
2
+ import { AsyncDatabase, type TransactionOptions } from '../core/Database.js';
2
3
  import type { AsyncDriver, AsyncStatement, BatchQuery } from '../core/Driver.js';
3
- import { AsyncDatabase, type TransactionOptions } from '../index.js';
4
4
  type Queryable = PGlite | Transaction;
5
5
  declare class PreparedStatement implements AsyncStatement {
6
6
  private client;
@@ -1,5 +1,5 @@
1
1
  // src/driver/pglite.ts
2
- import { AsyncDatabase } from "../index.js";
2
+ import { AsyncDatabase } from "../core/Database.js";
3
3
  import { postgresDialect } from "../postgres/dialect.js";
4
4
  import { postgresDiff } from "../postgres/diff.js";
5
5
  import { setTransaction } from "../postgres/transactions.js";
@@ -0,0 +1,7 @@
1
+ export { connect as 'better-sqlite3' } from './driver/better-sqlite3.js';
2
+ export { connect as 'bun:sqlite' } from './driver/bun-sqlite.js';
3
+ export { connect as 'd1' } from './driver/d1.js';
4
+ export { connect as 'mysql2' } from './driver/mysql2.js';
5
+ export { connect as '@neondatabase/serverless', connect as '@vercel/postgres', connect as 'pg' } from './driver/pg.js';
6
+ export { connect as '@electric-sql/pglite' } from './driver/pglite.js';
7
+ export { connect as 'sql.js' } from './driver/sql.js.js';
package/dist/driver.js ADDED
@@ -0,0 +1,23 @@
1
+ // src/driver.ts
2
+ import { connect } from "./driver/better-sqlite3.js";
3
+ import { connect as connect2 } from "./driver/bun-sqlite.js";
4
+ import { connect as connect3 } from "./driver/d1.js";
5
+ import { connect as connect4 } from "./driver/mysql2.js";
6
+ import {
7
+ connect as connect5,
8
+ connect as connect6,
9
+ connect as connect7
10
+ } from "./driver/pg.js";
11
+ import { connect as connect8 } from "./driver/pglite.js";
12
+ import { connect as connect9 } from "./driver/sql.js.js";
13
+ export {
14
+ connect8 as "@electric-sql/pglite",
15
+ connect5 as "@neondatabase/serverless",
16
+ connect6 as "@vercel/postgres",
17
+ connect as "better-sqlite3",
18
+ connect2 as "bun:sqlite",
19
+ connect3 as d1,
20
+ connect4 as mysql2,
21
+ connect7 as pg,
22
+ connect9 as "sql.js"
23
+ };
@@ -1,4 +1,4 @@
1
- import { JsonColumn, type Column } from '../core/Column.js';
1
+ import { type Column, JsonColumn } from '../core/Column.js';
2
2
  export declare function id(name?: string): Column<number>;
3
3
  export declare function text(name?: string): Column<string | null>;
4
4
  export declare function varchar(name?: string, options?: {
@@ -69,7 +69,13 @@ function jsonb(name) {
69
69
  });
70
70
  }
71
71
  function blob(name) {
72
- return column({ name, type: blobType });
72
+ return column({
73
+ name,
74
+ type: blobType,
75
+ mapFromDriverValue(value) {
76
+ return new Uint8Array(value);
77
+ }
78
+ });
73
79
  }
74
80
  export {
75
81
  blob,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "cycles": "madge --circular src/index.ts src/sqlite.ts src/mysql.ts src/postgres.ts",
12
12
  "test:bun": "bun test",
13
13
  "test:node": "node --test-force-exit --test-concurrency=1 --import tsx --test \"**/*.test.ts\"",
14
- "test:deno": "deno test --no-check --allow-read"
14
+ "test:deno": "deno test --no-check -A --unstable-ffi"
15
15
  },
16
16
  "sideEffects": false,
17
17
  "exports": {
@@ -26,16 +26,20 @@
26
26
  },
27
27
  "files": ["dist"],
28
28
  "devDependencies": {
29
+ "@alinea/suite": "^0.4.0",
29
30
  "@biomejs/biome": "^1.8.3",
30
31
  "@cloudflare/workers-types": "^4.20230628.0",
31
32
  "@electric-sql/pglite": "^0.1.5",
33
+ "@miniflare/d1": "^2.14.2",
34
+ "@miniflare/shared": "^2.14.2",
32
35
  "@sqlite.org/sqlite-wasm": "^3.42.0-build4",
33
- "@types/better-sqlite3": "^5.4.1",
34
- "@types/bun": "^1.1.6",
35
- "@types/glob": "^8.0.0",
36
- "@types/pg": "^8.11.5",
37
- "@types/sql.js": "^1.4.2",
38
- "better-sqlite3": "^11.2.1",
36
+ "@types/better-sqlite3": "^7.6.11",
37
+ "@types/bun": "^1.1.8",
38
+ "@types/glob": "^8.1.0",
39
+ "@types/pg": "^8.11.8",
40
+ "@types/sql.js": "^1.4.9",
41
+ "@vercel/postgres": "^0.10.0",
42
+ "better-sqlite3": "^11.3.0",
39
43
  "esbuild": "^0.23.1",
40
44
  "glob": "^11.0.0",
41
45
  "madge": "^8.0.0",
@@ -45,7 +49,6 @@
45
49
  "sql.js": "^1.11.0",
46
50
  "sqlite3": "^5.1.7",
47
51
  "tsx": "^4.19.0",
48
- "typescript": "^5.5.4",
49
- "@alinea/suite": "^0.4.0"
52
+ "typescript": "^5.6.2"
50
53
  }
51
54
  }