rado 1.0.11 → 1.0.12

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
@@ -50,21 +50,22 @@ Currently supported drivers:
50
50
 
51
51
  | `PostgreSQL ` | `import ` |
52
52
  | -------------------------- | ------------------------------ |
53
- | `pg` | `'rado/driver/pg'` |
54
- | `@electric-sql/pglite` | `'rado/driver/pglite'` |
55
- | `@neondatabase/serverless` | `'rado/driver/pg'` |
56
- | `@vercel/postgres` | `'rado/driver/pg'` |
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
- | `better-sqlite3` | `'rado/driver/better-sqlite3'` |
61
- | `bun:sqlite` | `'rado/driver/bun-sqlite'` |
62
- | `sql.js` | `'rado/driver/sql.js'` |
63
- | `Cloudflare D1` | `'rado/driver/d1'` |
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
- | `mysql2` | `'rado/driver/mysql2'` |
68
+ | mysql2 | rado/driver/mysql2 |
68
69
 
69
70
  Pass an instance of the database to the `connect` function to get started:
70
71
 
@@ -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/mysql2.js";
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 connect8 } from "./driver/pglite.js";
12
- import { connect as connect9 } from "./driver/sql.js.js";
12
+ import { connect as connect9 } from "./driver/pglite.js";
13
+ import { connect as connect10 } from "./driver/sql.js.js";
13
14
  export {
14
- connect8 as "@electric-sql/pglite",
15
- connect5 as "@neondatabase/serverless",
16
- connect6 as "@vercel/postgres",
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
- connect4 as mysql2,
21
- connect7 as pg,
22
- connect9 as "sql.js"
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.11",
3
+ "version": "1.0.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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",