rado 0.4.9 → 1.0.0-preview.0
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/core/Builder.d.ts +36 -0
- package/dist/core/Builder.js +99 -0
- package/dist/core/Column.d.ts +38 -0
- package/dist/core/Column.js +59 -0
- package/dist/core/Constraint.d.ts +39 -0
- package/dist/core/Constraint.js +87 -0
- package/dist/core/Database.d.ts +43 -0
- package/dist/core/Database.js +58 -0
- package/dist/core/Dialect.d.ts +6 -0
- package/dist/core/Dialect.js +16 -0
- package/dist/core/Driver.d.ts +28 -0
- package/dist/core/Emitter.d.ts +35 -0
- package/dist/core/Emitter.js +153 -0
- package/dist/core/Index.d.ts +28 -0
- package/dist/core/Index.js +50 -0
- package/dist/core/Internal.d.ts +67 -0
- package/dist/core/Internal.js +62 -0
- package/dist/core/MetaData.d.ts +27 -0
- package/dist/core/Param.d.ts +9 -0
- package/dist/core/Param.js +14 -0
- package/dist/core/Query.d.ts +40 -0
- package/dist/core/Query.js +70 -0
- package/dist/core/Resolver.d.ts +23 -0
- package/dist/core/Resolver.js +54 -0
- package/dist/core/Schema.d.ts +4 -0
- package/dist/core/Schema.js +13 -0
- package/dist/core/Selection.d.ts +27 -0
- package/dist/core/Selection.js +88 -0
- package/dist/core/Sql.d.ts +49 -0
- package/dist/core/Sql.js +153 -0
- package/dist/core/Table.d.ts +56 -0
- package/dist/core/Table.js +103 -0
- package/dist/core/Types.d.ts +3 -0
- package/dist/core/Virtual.d.ts +2 -0
- package/dist/core/Virtual.js +28 -0
- package/dist/core/expr/Aggregate.d.ts +10 -0
- package/dist/core/expr/Aggregate.js +38 -0
- package/dist/core/expr/Conditions.d.ts +40 -0
- package/dist/core/expr/Conditions.js +137 -0
- package/dist/core/expr/Field.d.ts +14 -0
- package/dist/core/expr/Field.js +15 -0
- package/dist/core/expr/Functions.d.ts +6 -0
- package/dist/core/expr/Functions.js +11 -0
- package/dist/core/expr/Input.d.ts +3 -0
- package/dist/core/expr/Input.js +14 -0
- package/dist/core/query/CreateTable.d.ts +13 -0
- package/dist/core/query/CreateTable.js +23 -0
- package/dist/core/query/Delete.d.ts +19 -0
- package/dist/core/query/Delete.js +44 -0
- package/dist/core/query/DropTable.d.ts +13 -0
- package/dist/core/query/DropTable.js +23 -0
- package/dist/core/query/Insert.d.ts +43 -0
- package/dist/core/query/Insert.js +111 -0
- package/dist/core/query/Select.d.ts +93 -0
- package/dist/core/query/Select.js +196 -0
- package/dist/core/query/Union.d.ts +27 -0
- package/dist/core/query/Union.js +86 -0
- package/dist/core/query/Update.d.ts +23 -0
- package/dist/core/query/Update.js +55 -0
- package/dist/driver/better-sqlite3.d.ts +3 -16
- package/dist/driver/better-sqlite3.js +27 -33
- package/dist/driver/bun-sqlite.d.ts +3 -18
- package/dist/driver/bun-sqlite.js +26 -42
- package/dist/driver/pg.d.ts +25 -0
- package/dist/driver/pg.js +81 -0
- package/dist/driver/pglite.d.ts +24 -0
- package/dist/driver/pglite.js +59 -0
- package/dist/driver/sql.js.d.ts +3 -16
- package/dist/driver/sql.js.js +41 -47
- package/dist/index.d.ts +16 -21
- package/dist/index.js +16 -14
- package/dist/migrate/Scan.d.ts +1 -0
- package/dist/migrate/Scan.js +0 -0
- package/dist/postgres/PostgresColumns.d.ts +10 -0
- package/dist/postgres/PostgresColumns.js +58 -0
- package/dist/postgres/PostgresDialect.d.ts +2 -0
- package/dist/postgres/PostgresDialect.js +58 -0
- package/dist/postgres/PostgresSchema.d.ts +1 -0
- package/dist/postgres/PostgresSchema.js +4 -0
- package/dist/postgres/PostgresTable.d.ts +1 -0
- package/dist/postgres/PostgresTable.js +4 -0
- package/dist/postgres.d.ts +2 -0
- package/dist/postgres.js +2 -0
- package/dist/sqlite/SqliteColumns.d.ts +9 -0
- package/dist/sqlite/SqliteColumns.js +63 -0
- package/dist/sqlite/SqliteDialect.d.ts +2 -0
- package/dist/sqlite/SqliteDialect.js +51 -0
- package/dist/sqlite/SqliteFunctions.d.ts +8 -167
- package/dist/sqlite/SqliteFunctions.js +6 -3
- package/dist/sqlite/SqliteTable.d.ts +1 -0
- package/dist/sqlite/SqliteTable.js +4 -0
- package/dist/sqlite.d.ts +3 -2
- package/dist/sqlite.js +3 -2
- package/dist/src/core/Builder.d.ts +36 -0
- package/dist/src/core/Column.d.ts +38 -0
- package/dist/src/core/Constraint.d.ts +39 -0
- package/dist/src/core/Database.d.ts +43 -0
- package/dist/src/core/Dialect.d.ts +6 -0
- package/dist/src/core/Driver.d.ts +28 -0
- package/dist/src/core/Emitter.d.ts +35 -0
- package/dist/src/core/Index.d.ts +28 -0
- package/dist/src/core/Internal.d.ts +67 -0
- package/dist/src/core/MetaData.d.ts +27 -0
- package/dist/src/core/Param.d.ts +9 -0
- package/dist/src/core/Query.d.ts +40 -0
- package/dist/src/core/Resolver.d.ts +23 -0
- package/dist/src/core/Schema.d.ts +4 -0
- package/dist/src/core/Selection.d.ts +27 -0
- package/dist/src/core/Sql.d.ts +49 -0
- package/dist/src/core/Table.d.ts +56 -0
- package/dist/src/core/Types.d.ts +3 -0
- package/dist/src/core/Virtual.d.ts +2 -0
- package/dist/src/core/expr/Aggregate.d.ts +10 -0
- package/dist/src/core/expr/Conditions.d.ts +40 -0
- package/dist/src/core/expr/Field.d.ts +14 -0
- package/dist/src/core/expr/Functions.d.ts +6 -0
- package/dist/src/core/expr/Input.d.ts +3 -0
- package/dist/src/core/query/CreateTable.d.ts +13 -0
- package/dist/src/core/query/Delete.d.ts +19 -0
- package/dist/src/core/query/DropTable.d.ts +13 -0
- package/dist/src/core/query/Insert.d.ts +43 -0
- package/dist/src/core/query/Select.d.ts +93 -0
- package/dist/src/core/query/Union.d.ts +27 -0
- package/dist/src/core/query/Update.d.ts +23 -0
- package/dist/src/driver/better-sqlite3.d.ts +3 -0
- package/dist/src/driver/bun-sqlite.d.ts +4 -0
- package/dist/src/driver/pg.d.ts +25 -0
- package/dist/src/driver/pglite.d.ts +24 -0
- package/dist/src/driver/sql.js.d.ts +3 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/migrate/Scan.d.ts +1 -0
- package/dist/src/postgres/PostgresColumns.d.ts +10 -0
- package/dist/src/postgres/PostgresDialect.d.ts +2 -0
- package/dist/src/postgres/PostgresSchema.d.ts +1 -0
- package/dist/src/postgres/PostgresTable.d.ts +1 -0
- package/dist/src/postgres.d.ts +2 -0
- package/dist/src/sqlite/SqliteColumns.d.ts +9 -0
- package/dist/src/sqlite/SqliteDialect.d.ts +2 -0
- package/dist/src/sqlite/SqliteFunctions.d.ts +8 -0
- package/dist/src/sqlite/SqliteTable.d.ts +1 -0
- package/dist/src/sqlite.d.ts +3 -0
- package/dist/src/universal/UniversalColumns.d.ts +6 -0
- package/dist/src/universal/UniversalTransaction.d.ts +3 -0
- package/dist/src/universal.d.ts +2 -0
- package/dist/test/Suite.d.ts +11 -0
- package/dist/test/TestDriver.d.ts +2 -0
- package/dist/test/TestUtils.d.ts +4 -0
- package/dist/test/core/Expr.test.d.ts +1 -0
- package/dist/test/core/Selection.test.d.ts +1 -0
- package/dist/test/core/Sql.test.d.ts +1 -0
- package/dist/test/core/SqliteFunctions.test.d.ts +1 -0
- package/dist/test/core/Table.test.d.ts +1 -0
- package/dist/test/driver/better-sqlite3.test.d.ts +1 -0
- package/dist/test/driver/bun-sqlite.test.d.ts +1 -0
- package/dist/test/driver/pg.test.d.ts +1 -0
- package/dist/test/driver/pglite.test.d.ts +1 -0
- package/dist/test/driver/sql.js.test.d.ts +1 -0
- package/dist/test/query/CreateTable.test.d.ts +1 -0
- package/dist/test/query/Delete.test.d.ts +1 -0
- package/dist/test/query/DropTable.test.d.ts +1 -0
- package/dist/test/query/Insert.test.d.ts +1 -0
- package/dist/test/query/Select.test.d.ts +1 -0
- package/dist/test/query/Union.test.d.ts +1 -0
- package/dist/test/query/Update.test.d.ts +1 -0
- package/dist/universal/UniversalColumns.d.ts +6 -0
- package/dist/universal/UniversalColumns.js +56 -0
- package/dist/universal/UniversalTransaction.d.ts +3 -0
- package/dist/universal/UniversalTransaction.js +14 -0
- package/dist/universal.d.ts +2 -0
- package/dist/universal.js +2 -0
- package/package.json +25 -43
- package/dist/define/Column.d.ts +0 -122
- package/dist/define/Column.js +0 -183
- package/dist/define/Expr.d.ts +0 -185
- package/dist/define/Expr.js +0 -463
- package/dist/define/Fields.d.ts +0 -18
- package/dist/define/Functions.d.ts +0 -5
- package/dist/define/Functions.js +0 -12
- package/dist/define/Id.d.ts +0 -3
- package/dist/define/Index.d.ts +0 -17
- package/dist/define/Index.js +0 -19
- package/dist/define/Ops.d.ts +0 -36
- package/dist/define/Ops.js +0 -114
- package/dist/define/OrderBy.d.ts +0 -9
- package/dist/define/OrderBy.js +0 -8
- package/dist/define/Param.d.ts +0 -18
- package/dist/define/Param.js +0 -27
- package/dist/define/Query.d.ts +0 -268
- package/dist/define/Query.js +0 -596
- package/dist/define/Schema.d.ts +0 -12
- package/dist/define/Schema.js +0 -140
- package/dist/define/Selection.d.ts +0 -21
- package/dist/define/Selection.js +0 -6
- package/dist/define/Sql.d.ts +0 -6
- package/dist/define/Sql.js +0 -21
- package/dist/define/Table.d.ts +0 -75
- package/dist/define/Table.js +0 -138
- package/dist/define/Target.d.ts +0 -47
- package/dist/define/Target.js +0 -68
- package/dist/define/VirtualTable.d.ts +0 -31
- package/dist/define/VirtualTable.js +0 -39
- package/dist/driver/@sqlite.org/sqlite-wasm.d.ts +0 -17
- package/dist/driver/@sqlite.org/sqlite-wasm.js +0 -80
- package/dist/driver/d1.d.ts +0 -22
- package/dist/driver/d1.js +0 -71
- package/dist/driver/sqlite3.d.ts +0 -22
- package/dist/driver/sqlite3.js +0 -132
- package/dist/lib/Driver.d.ts +0 -111
- package/dist/lib/Driver.js +0 -398
- package/dist/lib/Formatter.d.ts +0 -106
- package/dist/lib/Formatter.js +0 -898
- package/dist/lib/Sanitizer.d.ts +0 -5
- package/dist/lib/SqlError.d.ts +0 -3
- package/dist/lib/SqlError.js +0 -10
- package/dist/lib/Statement.d.ts +0 -108
- package/dist/lib/Statement.js +0 -190
- package/dist/sqlite/SqliteFormatter.d.ts +0 -11
- package/dist/sqlite/SqliteFormatter.js +0 -66
- package/dist/sqlite/SqliteSchema.d.ts +0 -25
- package/dist/sqlite/SqliteSchema.js +0 -46
- package/dist/util/Alias.d.ts +0 -1
- package/dist/util/Alias.js +0 -6
- package/dist/util/Callable.d.ts +0 -16
- package/dist/util/Callable.js +0 -9
- /package/dist/{define/Fields.js → core/Driver.js} +0 -0
- /package/dist/{define/Id.js → core/MetaData.js} +0 -0
- /package/dist/{lib/Sanitizer.js → core/Types.js} +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import pg from "pg";
|
|
2
|
+
import { AsyncDatabase } from "../core/Database.ts";
|
|
3
|
+
import { postgresDialect } from "../postgres/PostgresDialect.ts";
|
|
4
|
+
class PreparedStatement {
|
|
5
|
+
constructor(client, sql, name) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
this.sql = sql;
|
|
8
|
+
this.name = name;
|
|
9
|
+
}
|
|
10
|
+
all(params) {
|
|
11
|
+
return this.client.query({
|
|
12
|
+
name: this.name,
|
|
13
|
+
text: this.sql,
|
|
14
|
+
values: params
|
|
15
|
+
}).then((res) => res.rows);
|
|
16
|
+
}
|
|
17
|
+
async run(params) {
|
|
18
|
+
await this.client.query(
|
|
19
|
+
{
|
|
20
|
+
name: this.name,
|
|
21
|
+
text: this.sql,
|
|
22
|
+
values: params
|
|
23
|
+
},
|
|
24
|
+
params
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
get(params) {
|
|
28
|
+
return this.all(params).then((rows) => rows[0] ?? null);
|
|
29
|
+
}
|
|
30
|
+
values(params) {
|
|
31
|
+
return this.client.query({
|
|
32
|
+
name: this.name,
|
|
33
|
+
text: this.sql,
|
|
34
|
+
values: params,
|
|
35
|
+
rowMode: "array"
|
|
36
|
+
}).then((res) => res.rows);
|
|
37
|
+
}
|
|
38
|
+
free() {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class PgDriver {
|
|
42
|
+
constructor(client) {
|
|
43
|
+
this.client = client;
|
|
44
|
+
}
|
|
45
|
+
async exec(query) {
|
|
46
|
+
await this.client.query(query);
|
|
47
|
+
}
|
|
48
|
+
prepare(sql, name) {
|
|
49
|
+
return new PreparedStatement(this.client, sql, name);
|
|
50
|
+
}
|
|
51
|
+
async close() {
|
|
52
|
+
if ("end" in this.client)
|
|
53
|
+
return this.client.end();
|
|
54
|
+
if ("release" in this.client)
|
|
55
|
+
return this.client.release();
|
|
56
|
+
}
|
|
57
|
+
async transaction(run, options, depth) {
|
|
58
|
+
const client = this.client instanceof pg.Pool ? await this.client.connect() : this.client;
|
|
59
|
+
try {
|
|
60
|
+
await client.query(depth > 0 ? `savepoint d${depth}` : "begin");
|
|
61
|
+
const result = await run(new PgDriver(client));
|
|
62
|
+
await client.query(depth > 0 ? `release savepoint d${depth}` : "commit");
|
|
63
|
+
return result;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
await client.query(
|
|
66
|
+
depth > 0 ? `rollback to savepoint d${depth}` : "rollback"
|
|
67
|
+
);
|
|
68
|
+
throw error;
|
|
69
|
+
} finally {
|
|
70
|
+
if ("release" in client)
|
|
71
|
+
client.release();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function connect(client) {
|
|
76
|
+
return new AsyncDatabase(new PgDriver(client), postgresDialect);
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
PgDriver,
|
|
80
|
+
connect
|
|
81
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PGlite, Transaction } from '@electric-sql/pglite';
|
|
2
|
+
import type { AsyncDriver, AsyncStatement } from '../core/Driver.ts';
|
|
3
|
+
import { AsyncDatabase, type TransactionOptions } from '../index.ts';
|
|
4
|
+
type Queryable = PGlite | Transaction;
|
|
5
|
+
declare class PreparedStatement implements AsyncStatement {
|
|
6
|
+
private client;
|
|
7
|
+
private sql;
|
|
8
|
+
constructor(client: Queryable, sql: string);
|
|
9
|
+
all(params: Array<unknown>): Promise<Array<object>>;
|
|
10
|
+
run(params: Array<unknown>): Promise<void>;
|
|
11
|
+
get(params: Array<unknown>): Promise<object>;
|
|
12
|
+
values(params: Array<unknown>): Promise<unknown[][]>;
|
|
13
|
+
free(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class PGliteDriver implements AsyncDriver {
|
|
16
|
+
private client;
|
|
17
|
+
constructor(client: Queryable);
|
|
18
|
+
exec(query: string): Promise<void>;
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
prepare(sql: string): PreparedStatement;
|
|
21
|
+
transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['postgres']): Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
export declare function connect(db: PGlite): AsyncDatabase<"postgres">;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AsyncDatabase } from "../index.ts";
|
|
2
|
+
import { postgresDialect } from "../postgres/PostgresDialect.ts";
|
|
3
|
+
class PreparedStatement {
|
|
4
|
+
constructor(client, sql) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
this.sql = sql;
|
|
7
|
+
}
|
|
8
|
+
all(params) {
|
|
9
|
+
return this.client.query(this.sql, params, {
|
|
10
|
+
rowMode: "object"
|
|
11
|
+
}).then((res) => res.rows);
|
|
12
|
+
}
|
|
13
|
+
async run(params) {
|
|
14
|
+
await this.client.query(this.sql, params, {
|
|
15
|
+
rowMode: "array"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
get(params) {
|
|
19
|
+
return this.all(params).then((rows) => rows[0] ?? null);
|
|
20
|
+
}
|
|
21
|
+
values(params) {
|
|
22
|
+
return this.client.query(this.sql, params, {
|
|
23
|
+
rowMode: "array"
|
|
24
|
+
}).then((res) => res.rows);
|
|
25
|
+
}
|
|
26
|
+
free() {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class PGliteDriver {
|
|
30
|
+
constructor(client) {
|
|
31
|
+
this.client = client;
|
|
32
|
+
}
|
|
33
|
+
async exec(query) {
|
|
34
|
+
await this.client.exec(query);
|
|
35
|
+
}
|
|
36
|
+
close() {
|
|
37
|
+
if ("close" in this.client) {
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
throw new Error("Cannot close a transaction");
|
|
41
|
+
}
|
|
42
|
+
prepare(sql) {
|
|
43
|
+
return new PreparedStatement(this.client, sql);
|
|
44
|
+
}
|
|
45
|
+
async transaction(run, options) {
|
|
46
|
+
if ("transaction" in this.client)
|
|
47
|
+
return this.client.transaction((tx) => {
|
|
48
|
+
return run(new PGliteDriver(tx));
|
|
49
|
+
});
|
|
50
|
+
throw new Error("Cannot nest transactions in PGLite");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function connect(db) {
|
|
54
|
+
return new AsyncDatabase(new PGliteDriver(db), postgresDialect);
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
PGliteDriver,
|
|
58
|
+
connect
|
|
59
|
+
};
|
package/dist/driver/sql.js.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { Database } from 'sql.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { Statement } from '../lib/Statement.js';
|
|
5
|
-
import { SqliteSchema } from '../sqlite/SqliteSchema.js';
|
|
6
|
-
export declare class SqlJsDriver extends Driver.Sync {
|
|
7
|
-
db: Database;
|
|
8
|
-
tableData?: (tableName: string) => Array<SqliteSchema.Column>;
|
|
9
|
-
indexData?: (tableName: string) => Array<SqliteSchema.Index>;
|
|
10
|
-
constructor(db: Database, options?: DriverOptions);
|
|
11
|
-
close(): void;
|
|
12
|
-
prepareStatement(stmt: Statement, discardAfter: boolean): Driver.Sync.PreparedStatement;
|
|
13
|
-
schemaInstructions(tableName: string): SchemaInstructions | undefined;
|
|
14
|
-
export(): Uint8Array;
|
|
15
|
-
}
|
|
16
|
-
export declare function connect(db: Database, options?: DriverOptions): SqlJsDriver;
|
|
1
|
+
import type { Database as Client } from 'sql.js';
|
|
2
|
+
import { SyncDatabase } from '../core/Database.ts';
|
|
3
|
+
export declare function connect(db: Client): SyncDatabase<import("../core/MetaData.ts").QueryDialect>;
|
package/dist/driver/sql.js.js
CHANGED
|
@@ -1,75 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
1
|
+
import { SyncDatabase } from "../core/Database.ts";
|
|
2
|
+
import { sqliteDialect } from "../sqlite.ts";
|
|
4
3
|
class PreparedStatement {
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
4
|
+
constructor(client, stmt) {
|
|
5
|
+
this.client = client;
|
|
7
6
|
this.stmt = stmt;
|
|
8
|
-
this.discardAfter = discardAfter;
|
|
9
7
|
}
|
|
10
8
|
*iterate(params) {
|
|
11
9
|
this.stmt.bind(params);
|
|
12
10
|
while (this.stmt.step())
|
|
13
11
|
yield this.stmt.getAsObject();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
this.stmt.reset();
|
|
13
|
+
}
|
|
14
|
+
*iterateValues(params) {
|
|
15
|
+
this.stmt.bind(params);
|
|
16
|
+
while (this.stmt.step())
|
|
17
|
+
yield this.stmt.get();
|
|
18
|
+
this.stmt.reset();
|
|
18
19
|
}
|
|
19
20
|
all(params) {
|
|
20
21
|
return Array.from(this.iterate(params));
|
|
21
22
|
}
|
|
22
23
|
run(params) {
|
|
23
24
|
this.stmt.run(params);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
else
|
|
27
|
-
this.stmt.reset();
|
|
28
|
-
return { rowsAffected: this.db.getRowsModified() };
|
|
25
|
+
this.stmt.reset();
|
|
26
|
+
return { rowsAffected: this.client.getRowsModified() };
|
|
29
27
|
}
|
|
30
28
|
get(params) {
|
|
31
|
-
return this.all(params)[0];
|
|
29
|
+
return this.all(params)[0] ?? null;
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.stmt.reset();
|
|
31
|
+
values(params) {
|
|
32
|
+
return Array.from(this.iterateValues(params));
|
|
33
|
+
}
|
|
34
|
+
free() {
|
|
35
|
+
this.stmt.free();
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
class SqlJsDriver
|
|
42
|
-
constructor(
|
|
43
|
-
|
|
44
|
-
this.db = db;
|
|
38
|
+
class SqlJsDriver {
|
|
39
|
+
constructor(client) {
|
|
40
|
+
this.client = client;
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
close() {
|
|
49
|
-
this.db.close();
|
|
42
|
+
exec(query) {
|
|
43
|
+
this.client.exec(query);
|
|
50
44
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.db,
|
|
54
|
-
this.db.prepare(stmt.sql),
|
|
55
|
-
discardAfter
|
|
56
|
-
);
|
|
45
|
+
close() {
|
|
46
|
+
this.client.close();
|
|
57
47
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.indexData = this.indexData || (this.indexData = this.prepare(SqliteSchema.indexData));
|
|
61
|
-
const columnData = this.tableData(tableName);
|
|
62
|
-
const indexData = this.indexData(tableName);
|
|
63
|
-
return SqliteSchema.createInstructions(columnData, indexData);
|
|
48
|
+
prepare(sql) {
|
|
49
|
+
return new PreparedStatement(this.client, this.client.prepare(sql));
|
|
64
50
|
}
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
transaction(run, options, depth) {
|
|
52
|
+
const behavior = options.behavior ?? "deferred";
|
|
53
|
+
this.exec(depth > 0 ? `savepoint d${depth}` : `begin ${behavior}`);
|
|
54
|
+
try {
|
|
55
|
+
const result = run(this);
|
|
56
|
+
this.exec(depth > 0 ? `release d${depth}` : "commit");
|
|
57
|
+
return result;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
this.exec(depth > 0 ? `rollback to d${depth}` : "rollback");
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
function connect(db
|
|
70
|
-
return new SqlJsDriver(db,
|
|
64
|
+
function connect(db) {
|
|
65
|
+
return new SyncDatabase(new SqlJsDriver(db), sqliteDialect);
|
|
71
66
|
}
|
|
72
67
|
export {
|
|
73
|
-
SqlJsDriver,
|
|
74
68
|
connect
|
|
75
69
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export
|
|
4
|
-
export * from './
|
|
5
|
-
export
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export type { Driver, DriverOptions } from './lib/Driver.js';
|
|
18
|
-
export type { FormatContext, Formatter } from './lib/Formatter.js';
|
|
19
|
-
export type { Sanitizer } from './lib/Sanitizer.js';
|
|
20
|
-
export * from './lib/SqlError.js';
|
|
21
|
-
export type { Statement } from './lib/Statement.js';
|
|
1
|
+
export * from './core/Column.ts';
|
|
2
|
+
export * from './core/Constraint.ts';
|
|
3
|
+
export * from './core/Database.ts';
|
|
4
|
+
export * from './core/Driver.ts';
|
|
5
|
+
export * from './core/Index.ts';
|
|
6
|
+
export * from './core/Query.ts';
|
|
7
|
+
export * from './core/Selection.ts';
|
|
8
|
+
export * from './core/Sql.ts';
|
|
9
|
+
export * from './core/Table.ts';
|
|
10
|
+
export * from './core/expr/Conditions.ts';
|
|
11
|
+
export * from './core/query/CreateTable.ts';
|
|
12
|
+
export * from './core/query/Delete.ts';
|
|
13
|
+
export * from './core/query/Insert.ts';
|
|
14
|
+
export * from './core/query/Select.ts';
|
|
15
|
+
export * from './core/query/Union.ts';
|
|
16
|
+
export * from './core/query/Update.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./
|
|
12
|
-
export * from "./
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
1
|
+
export * from "./core/Column.ts";
|
|
2
|
+
export * from "./core/Constraint.ts";
|
|
3
|
+
export * from "./core/Database.ts";
|
|
4
|
+
export * from "./core/Driver.ts";
|
|
5
|
+
export * from "./core/Index.ts";
|
|
6
|
+
export * from "./core/Query.ts";
|
|
7
|
+
export * from "./core/Selection.ts";
|
|
8
|
+
export * from "./core/Sql.ts";
|
|
9
|
+
export * from "./core/Table.ts";
|
|
10
|
+
export * from "./core/expr/Conditions.ts";
|
|
11
|
+
export * from "./core/query/CreateTable.ts";
|
|
12
|
+
export * from "./core/query/Delete.ts";
|
|
13
|
+
export * from "./core/query/Insert.ts";
|
|
14
|
+
export * from "./core/query/Select.ts";
|
|
15
|
+
export * from "./core/query/Union.ts";
|
|
16
|
+
export * from "./core/query/Update.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Column, JsonColumn } from '../core/Column.ts';
|
|
2
|
+
export declare function serial(name?: string): Column<number | null>;
|
|
3
|
+
export declare function boolean(name?: string): Column<boolean | null>;
|
|
4
|
+
export declare function integer(name?: string): Column<number | null>;
|
|
5
|
+
export declare function blob(name?: string): Column<Uint8Array | null>;
|
|
6
|
+
export declare function text(name?: string): Column<string | null>;
|
|
7
|
+
export declare function real(name?: string): Column<number | null>;
|
|
8
|
+
export declare function numeric(name?: string): Column<number | null>;
|
|
9
|
+
export declare function json<T>(name?: string): JsonColumn<T | null>;
|
|
10
|
+
export declare function jsonb<T>(name?: string): JsonColumn<T | null>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Column, JsonColumn } from "../core/Column.ts";
|
|
2
|
+
import { sql } from "../core/Sql.ts";
|
|
3
|
+
function serial(name) {
|
|
4
|
+
return new Column({
|
|
5
|
+
name,
|
|
6
|
+
type: sql`serial`
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function boolean(name) {
|
|
10
|
+
return new Column({
|
|
11
|
+
name,
|
|
12
|
+
type: sql`boolean`
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function integer(name) {
|
|
16
|
+
return new Column({ name, type: sql`integer` });
|
|
17
|
+
}
|
|
18
|
+
function blob(name) {
|
|
19
|
+
return new Column({ name, type: sql`blob` });
|
|
20
|
+
}
|
|
21
|
+
function text(name) {
|
|
22
|
+
return new Column({ name, type: sql`text` });
|
|
23
|
+
}
|
|
24
|
+
function real(name) {
|
|
25
|
+
return new Column({ name, type: sql`real` });
|
|
26
|
+
}
|
|
27
|
+
function numeric(name) {
|
|
28
|
+
return new Column({ name, type: sql`numeric` });
|
|
29
|
+
}
|
|
30
|
+
function json(name) {
|
|
31
|
+
return new JsonColumn({
|
|
32
|
+
name,
|
|
33
|
+
type: sql`json`,
|
|
34
|
+
mapToDriverValue(value) {
|
|
35
|
+
return JSON.stringify(value);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function jsonb(name) {
|
|
40
|
+
return new JsonColumn({
|
|
41
|
+
name,
|
|
42
|
+
type: sql`jsonb`,
|
|
43
|
+
mapToDriverValue(value) {
|
|
44
|
+
return JSON.stringify(value);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
blob,
|
|
50
|
+
boolean,
|
|
51
|
+
integer,
|
|
52
|
+
json,
|
|
53
|
+
jsonb,
|
|
54
|
+
numeric,
|
|
55
|
+
real,
|
|
56
|
+
serial,
|
|
57
|
+
text
|
|
58
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { dialect } from "../core/Dialect.ts";
|
|
2
|
+
import { Emitter } from "../core/Emitter.ts";
|
|
3
|
+
import { NamedParam, ValueParam } from "../core/Param.ts";
|
|
4
|
+
const DOUBLE_QUOTE = '"';
|
|
5
|
+
const ESCAPE_DOUBLE_QUOTE = '""';
|
|
6
|
+
const MATCH_DOUBLE_QUOTE = /"/g;
|
|
7
|
+
const SINGLE_QUOTE = "'";
|
|
8
|
+
const ESCAPE_SINGLE_QUOTE = "''";
|
|
9
|
+
const MATCH_SINGLE_QUOTE = /'/g;
|
|
10
|
+
class PostgresEmitter extends Emitter {
|
|
11
|
+
paramIndex = 0;
|
|
12
|
+
emitValue(value) {
|
|
13
|
+
this.sql += `$${++this.paramIndex}`;
|
|
14
|
+
this.params.push(new ValueParam(value));
|
|
15
|
+
}
|
|
16
|
+
emitJsonPath(path) {
|
|
17
|
+
for (let i = 0; i < path.length; i++) {
|
|
18
|
+
const access = path[i];
|
|
19
|
+
if (i <= path.length - 2)
|
|
20
|
+
this.sql += "->";
|
|
21
|
+
else if (i === path.length - 1)
|
|
22
|
+
this.sql += "->>";
|
|
23
|
+
if (typeof access === "number")
|
|
24
|
+
this.sql += access;
|
|
25
|
+
else
|
|
26
|
+
this.sql += this.quoteString(access);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
emitInline(value) {
|
|
30
|
+
if (value === null || value === void 0)
|
|
31
|
+
return this.sql += "null";
|
|
32
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
33
|
+
return this.sql += value;
|
|
34
|
+
if (typeof value === "string")
|
|
35
|
+
return this.sql += this.quoteString(value);
|
|
36
|
+
this.sql += `json(${this.quoteString(JSON.stringify(value))})`;
|
|
37
|
+
}
|
|
38
|
+
emitPlaceholder(name) {
|
|
39
|
+
this.sql += `$${++this.paramIndex}`;
|
|
40
|
+
this.params.push(new NamedParam(name));
|
|
41
|
+
}
|
|
42
|
+
quoteString(input) {
|
|
43
|
+
return SINGLE_QUOTE + input.replace(MATCH_SINGLE_QUOTE, ESCAPE_SINGLE_QUOTE) + SINGLE_QUOTE;
|
|
44
|
+
}
|
|
45
|
+
emitIdentifier(identifier) {
|
|
46
|
+
this.sql += DOUBLE_QUOTE + identifier.replace(MATCH_DOUBLE_QUOTE, ESCAPE_DOUBLE_QUOTE) + DOUBLE_QUOTE;
|
|
47
|
+
}
|
|
48
|
+
emitDefaultValue() {
|
|
49
|
+
this.sql += "default";
|
|
50
|
+
}
|
|
51
|
+
emitIdColumn() {
|
|
52
|
+
this.sql += "int generated always as identity";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const postgresDialect = dialect(PostgresEmitter);
|
|
56
|
+
export {
|
|
57
|
+
postgresDialect
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { schema as pgSchema } from '../core/Schema.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { table as pgTable } from '../core/Table.ts';
|
package/dist/postgres.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Column, JsonColumn } from '../core/Column.ts';
|
|
2
|
+
export declare function boolean(name?: string): Column<boolean | null>;
|
|
3
|
+
export declare function integer(name?: string): Column<number | null>;
|
|
4
|
+
export declare function blob(name?: string): Column<Uint8Array | null>;
|
|
5
|
+
export declare function text(name?: string): Column<string | null>;
|
|
6
|
+
export declare function real(name?: string): Column<number | null>;
|
|
7
|
+
export declare function numeric(name?: string): Column<number | null>;
|
|
8
|
+
export declare function json<T>(name?: string): JsonColumn<T | null>;
|
|
9
|
+
export declare function jsonb<T>(name?: string): JsonColumn<T | null>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Column, JsonColumn } from "../core/Column.ts";
|
|
2
|
+
import { sql } from "../core/Sql.ts";
|
|
3
|
+
function boolean(name) {
|
|
4
|
+
return new Column({
|
|
5
|
+
name,
|
|
6
|
+
type: sql`integer`,
|
|
7
|
+
mapFromDriverValue(value) {
|
|
8
|
+
return value === 1;
|
|
9
|
+
},
|
|
10
|
+
mapToDriverValue(value) {
|
|
11
|
+
return value ? 1 : 0;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function integer(name) {
|
|
16
|
+
return new Column({ name, type: sql`integer` });
|
|
17
|
+
}
|
|
18
|
+
function blob(name) {
|
|
19
|
+
return new Column({ name, type: sql`blob` });
|
|
20
|
+
}
|
|
21
|
+
function text(name) {
|
|
22
|
+
return new Column({ name, type: sql`text` });
|
|
23
|
+
}
|
|
24
|
+
function real(name) {
|
|
25
|
+
return new Column({ name, type: sql`real` });
|
|
26
|
+
}
|
|
27
|
+
function numeric(name) {
|
|
28
|
+
return new Column({ name, type: sql`numeric` });
|
|
29
|
+
}
|
|
30
|
+
function json(name) {
|
|
31
|
+
return new JsonColumn({
|
|
32
|
+
name,
|
|
33
|
+
type: sql`json`,
|
|
34
|
+
mapFromDriverValue(value) {
|
|
35
|
+
return JSON.parse(value);
|
|
36
|
+
},
|
|
37
|
+
mapToDriverValue(value) {
|
|
38
|
+
return JSON.stringify(value);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function jsonb(name) {
|
|
43
|
+
return new JsonColumn({
|
|
44
|
+
name,
|
|
45
|
+
type: sql`jsonb`,
|
|
46
|
+
mapFromDriverValue(value) {
|
|
47
|
+
return JSON.parse(value);
|
|
48
|
+
},
|
|
49
|
+
mapToDriverValue(value) {
|
|
50
|
+
return JSON.stringify(value);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
blob,
|
|
56
|
+
boolean,
|
|
57
|
+
integer,
|
|
58
|
+
json,
|
|
59
|
+
jsonb,
|
|
60
|
+
numeric,
|
|
61
|
+
real,
|
|
62
|
+
text
|
|
63
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { dialect } from "../core/Dialect.ts";
|
|
2
|
+
import { Emitter } from "../core/Emitter.ts";
|
|
3
|
+
import { NamedParam, ValueParam } from "../core/Param.ts";
|
|
4
|
+
const DOUBLE_QUOTE = '"';
|
|
5
|
+
const ESCAPE_DOUBLE_QUOTE = '""';
|
|
6
|
+
const MATCH_DOUBLE_QUOTE = /"/g;
|
|
7
|
+
const SINGLE_QUOTE = "'";
|
|
8
|
+
const ESCAPE_SINGLE_QUOTE = "''";
|
|
9
|
+
const MATCH_SINGLE_QUOTE = /'/g;
|
|
10
|
+
class SqliteEmitter extends Emitter {
|
|
11
|
+
emitValue(value) {
|
|
12
|
+
this.sql += "?";
|
|
13
|
+
this.params.push(
|
|
14
|
+
new ValueParam(typeof value === "boolean" ? value ? 1 : 0 : value)
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
emitJsonPath(path) {
|
|
18
|
+
this.sql += `->>${this.quoteString(`$.${path.join(".")}`)}`;
|
|
19
|
+
}
|
|
20
|
+
emitInline(value) {
|
|
21
|
+
if (value === null || value === void 0)
|
|
22
|
+
return this.sql += "null";
|
|
23
|
+
if (typeof value === "number")
|
|
24
|
+
return this.sql += value;
|
|
25
|
+
if (typeof value === "string")
|
|
26
|
+
return this.sql += this.quoteString(value);
|
|
27
|
+
if (typeof value === "boolean")
|
|
28
|
+
return this.sql += value ? "1" : "0";
|
|
29
|
+
this.sql += `json(${this.quoteString(JSON.stringify(value))})`;
|
|
30
|
+
}
|
|
31
|
+
emitPlaceholder(name) {
|
|
32
|
+
this.sql += "?";
|
|
33
|
+
this.params.push(new NamedParam(name));
|
|
34
|
+
}
|
|
35
|
+
emitIdentifier(identifier) {
|
|
36
|
+
this.sql += DOUBLE_QUOTE + identifier.replace(MATCH_DOUBLE_QUOTE, ESCAPE_DOUBLE_QUOTE) + DOUBLE_QUOTE;
|
|
37
|
+
}
|
|
38
|
+
emitDefaultValue() {
|
|
39
|
+
this.sql += "null";
|
|
40
|
+
}
|
|
41
|
+
quoteString(input) {
|
|
42
|
+
return SINGLE_QUOTE + input.replace(MATCH_SINGLE_QUOTE, ESCAPE_SINGLE_QUOTE) + SINGLE_QUOTE;
|
|
43
|
+
}
|
|
44
|
+
emitIdColumn() {
|
|
45
|
+
this.sql += "integer";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const sqliteDialect = dialect(SqliteEmitter);
|
|
49
|
+
export {
|
|
50
|
+
sqliteDialect
|
|
51
|
+
};
|