rado 1.0.11 → 1.0.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/README.md +10 -9
- package/dist/core/Sql.d.ts +1 -1
- package/dist/core/Sql.js +4 -2
- package/dist/driver/libsql.d.ts +28 -0
- package/dist/driver/libsql.js +76 -0
- package/dist/driver.d.ts +1 -0
- package/dist/driver.js +13 -11
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -50,21 +50,22 @@ Currently supported drivers:
|
|
|
50
50
|
|
|
51
51
|
| `PostgreSQL ` | `import ` |
|
|
52
52
|
| -------------------------- | ------------------------------ |
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
53
|
+
| pg | rado/driver/pg |
|
|
54
|
+
| @electric-sql/pglite | rado/driver/pglite |
|
|
55
|
+
| @neondatabase/serverless | rado/driver/pg |
|
|
56
|
+
| @vercel/postgres | rado/driver/pg |
|
|
57
57
|
|
|
58
58
|
| `SQLite ` | `import ` |
|
|
59
59
|
| -------------------------- | ------------------------------ |
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
60
|
+
| better-sqlite3 | rado/driver/better-sqlite3 |
|
|
61
|
+
| bun:sqlite | rado/driver/bun-sqlite |
|
|
62
|
+
| sql.js | rado/driver/sql.js |
|
|
63
|
+
| @libsql/client | rado/driver/libsql |
|
|
64
|
+
| Cloudflare D1 | rado/driver/d1 |
|
|
64
65
|
|
|
65
66
|
| `MySQL ` | `import ` |
|
|
66
67
|
| -------------------------- | ------------------------------ |
|
|
67
|
-
|
|
|
68
|
+
| mysql2 | rado/driver/mysql2 |
|
|
68
69
|
|
|
69
70
|
Pass an instance of the database to the `connect` function to get started:
|
|
70
71
|
|
package/dist/core/Sql.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare class Sql<Value = unknown> implements HasSql<Value> {
|
|
|
41
41
|
nameSelf(name: string): Sql;
|
|
42
42
|
emitTo(emitter: Emitter): void;
|
|
43
43
|
}
|
|
44
|
-
export declare function sql<T>(strings: TemplateStringsArray, ...inner: Array<HasSql>): Sql<T>;
|
|
44
|
+
export declare function sql<T>(strings: TemplateStringsArray, ...inner: Array<HasSql | unknown>): Sql<T>;
|
|
45
45
|
export declare namespace sql {
|
|
46
46
|
export function empty<T>(): Sql<T>;
|
|
47
47
|
export function unsafe<T>(directSql: string | number): Sql<T>;
|
package/dist/core/Sql.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/Sql.ts
|
|
2
|
-
import { getSql, internalSql } from "./Internal.js";
|
|
2
|
+
import { getSql, hasSql, internalSql } from "./Internal.js";
|
|
3
3
|
var Chunk = class {
|
|
4
4
|
constructor(type, inner) {
|
|
5
5
|
this.type = type;
|
|
@@ -111,7 +111,9 @@ function sql(strings, ...inner) {
|
|
|
111
111
|
sql2.unsafe(strings[i]);
|
|
112
112
|
if (i < inner.length) {
|
|
113
113
|
const insert = inner[i];
|
|
114
|
-
|
|
114
|
+
if (insert !== null && typeof insert === "object" && hasSql(insert))
|
|
115
|
+
sql2.add(insert);
|
|
116
|
+
else sql2.value(insert);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
return sql2;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Client, InValue, Transaction } from '@libsql/client';
|
|
2
|
+
import { AsyncDatabase, type TransactionOptions } from '../core/Database.js';
|
|
3
|
+
import type { AsyncDriver, AsyncStatement, BatchQuery, PrepareOptions } from '../core/Driver.js';
|
|
4
|
+
type Queryable = Client | Transaction;
|
|
5
|
+
declare class PreparedStatement implements AsyncStatement {
|
|
6
|
+
private client;
|
|
7
|
+
private sql;
|
|
8
|
+
constructor(client: Queryable, sql: string);
|
|
9
|
+
all(params: Array<InValue>): Promise<Array<object>>;
|
|
10
|
+
run(params: Array<InValue>): Promise<void>;
|
|
11
|
+
get(params: Array<InValue>): Promise<object | null>;
|
|
12
|
+
values(params: Array<InValue>): Promise<Array<Array<unknown>>>;
|
|
13
|
+
free(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class LibSQLClient implements AsyncDriver {
|
|
16
|
+
private client;
|
|
17
|
+
private depth;
|
|
18
|
+
parsesJson: boolean;
|
|
19
|
+
supportsTransactions: boolean;
|
|
20
|
+
constructor(client: Queryable, depth?: number);
|
|
21
|
+
exec(query: string): Promise<void>;
|
|
22
|
+
prepare(sql: string, options: PrepareOptions): PreparedStatement;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
|
|
25
|
+
transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['sqlite']): Promise<T>;
|
|
26
|
+
}
|
|
27
|
+
export declare function connect(client: Client): AsyncDatabase<'sqlite'>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/driver/libsql.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(client, sql) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.sql = sql;
|
|
9
|
+
}
|
|
10
|
+
async all(params) {
|
|
11
|
+
const result = await this.client.execute({ sql: this.sql, args: params });
|
|
12
|
+
return result.rows;
|
|
13
|
+
}
|
|
14
|
+
async run(params) {
|
|
15
|
+
const result = await this.client.execute({ sql: this.sql, args: params });
|
|
16
|
+
}
|
|
17
|
+
async get(params) {
|
|
18
|
+
return (await this.all(params))[0] ?? null;
|
|
19
|
+
}
|
|
20
|
+
async values(params) {
|
|
21
|
+
const result = await this.client.execute({ sql: this.sql, args: params });
|
|
22
|
+
return result.rows;
|
|
23
|
+
}
|
|
24
|
+
free() {
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var LibSQLClient = class _LibSQLClient {
|
|
28
|
+
constructor(client, depth = 0) {
|
|
29
|
+
this.client = client;
|
|
30
|
+
this.depth = depth;
|
|
31
|
+
}
|
|
32
|
+
parsesJson = false;
|
|
33
|
+
supportsTransactions = true;
|
|
34
|
+
async exec(query) {
|
|
35
|
+
await this.client.execute(query);
|
|
36
|
+
}
|
|
37
|
+
prepare(sql, options) {
|
|
38
|
+
return new PreparedStatement(this.client, sql);
|
|
39
|
+
}
|
|
40
|
+
async close() {
|
|
41
|
+
if ("close" in this.client) return this.client.close();
|
|
42
|
+
}
|
|
43
|
+
async batch(queries) {
|
|
44
|
+
const stmts = queries.map(({ sql, params }) => {
|
|
45
|
+
return { sql, args: params };
|
|
46
|
+
});
|
|
47
|
+
const rows = await this.client.batch(stmts);
|
|
48
|
+
return rows.map((row) => row.rows);
|
|
49
|
+
}
|
|
50
|
+
async transaction(run, options) {
|
|
51
|
+
const client = "transaction" in this.client ? await this.client.transaction() : this.client;
|
|
52
|
+
const driver = new _LibSQLClient(client, this.depth + 1);
|
|
53
|
+
if (this.depth > 0) await client.execute(`savepoint d${this.depth}`);
|
|
54
|
+
try {
|
|
55
|
+
const result = await run(driver);
|
|
56
|
+
if (this.depth > 0)
|
|
57
|
+
await client.execute(`release savepoint d${this.depth}`);
|
|
58
|
+
else await client.commit();
|
|
59
|
+
return result;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (this.depth > 0)
|
|
62
|
+
await client.execute(`rollback to savepoint d${this.depth}`);
|
|
63
|
+
else await client.rollback();
|
|
64
|
+
throw error;
|
|
65
|
+
} finally {
|
|
66
|
+
if (this.depth === 0) client.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function connect(client) {
|
|
71
|
+
return new AsyncDatabase(new LibSQLClient(client), sqliteDialect, sqliteDiff);
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
LibSQLClient,
|
|
75
|
+
connect
|
|
76
|
+
};
|
package/dist/driver.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { connect as 'better-sqlite3' } from './driver/better-sqlite3.js';
|
|
2
2
|
export { connect as 'bun:sqlite' } from './driver/bun-sqlite.js';
|
|
3
3
|
export { connect as 'd1' } from './driver/d1.js';
|
|
4
|
+
export { connect as '@libsql/client' } from './driver/libsql.js';
|
|
4
5
|
export { connect as 'mysql2' } from './driver/mysql2.js';
|
|
5
6
|
export { connect as '@neondatabase/serverless', connect as '@vercel/postgres', connect as 'pg' } from './driver/pg.js';
|
|
6
7
|
export { connect as '@electric-sql/pglite' } from './driver/pglite.js';
|
package/dist/driver.js
CHANGED
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
import { connect } from "./driver/better-sqlite3.js";
|
|
3
3
|
import { connect as connect2 } from "./driver/bun-sqlite.js";
|
|
4
4
|
import { connect as connect3 } from "./driver/d1.js";
|
|
5
|
-
import { connect as connect4 } from "./driver/
|
|
5
|
+
import { connect as connect4 } from "./driver/libsql.js";
|
|
6
|
+
import { connect as connect5 } from "./driver/mysql2.js";
|
|
6
7
|
import {
|
|
7
|
-
connect as connect5,
|
|
8
8
|
connect as connect6,
|
|
9
|
-
connect as connect7
|
|
9
|
+
connect as connect7,
|
|
10
|
+
connect as connect8
|
|
10
11
|
} from "./driver/pg.js";
|
|
11
|
-
import { connect as
|
|
12
|
-
import { connect as
|
|
12
|
+
import { connect as connect9 } from "./driver/pglite.js";
|
|
13
|
+
import { connect as connect10 } from "./driver/sql.js.js";
|
|
13
14
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
connect6 as "@
|
|
15
|
+
connect9 as "@electric-sql/pglite",
|
|
16
|
+
connect4 as "@libsql/client",
|
|
17
|
+
connect6 as "@neondatabase/serverless",
|
|
18
|
+
connect7 as "@vercel/postgres",
|
|
17
19
|
connect as "better-sqlite3",
|
|
18
20
|
connect2 as "bun:sqlite",
|
|
19
21
|
connect3 as d1,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
connect5 as mysql2,
|
|
23
|
+
connect8 as pg,
|
|
24
|
+
connect10 as "sql.js"
|
|
23
25
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rado",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
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 -A --unstable-ffi"
|
|
14
|
+
"test:deno": "deno test --node-modules-dir=false --no-check -A --unstable-ffi"
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"exports": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@biomejs/biome": "^1.8.3",
|
|
31
31
|
"@cloudflare/workers-types": "^4.20230628.0",
|
|
32
32
|
"@electric-sql/pglite": "^0.1.5",
|
|
33
|
+
"@libsql/client": "^0.10.0",
|
|
33
34
|
"@miniflare/d1": "^2.14.2",
|
|
34
35
|
"@miniflare/shared": "^2.14.2",
|
|
35
36
|
"@sqlite.org/sqlite-wasm": "^3.42.0-build4",
|