rado 0.0.0 → 0.1.1
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/Column.d.ts +13 -7
- package/dist/Column.js +7 -4
- package/dist/Cursor.d.ts +6 -5
- package/dist/Cursor.js +6 -5
- package/dist/Driver.d.ts +64 -35
- package/dist/Driver.js +191 -94
- package/dist/Formatter.d.ts +8 -2
- package/dist/Formatter.js +60 -17
- package/dist/Ops.js +9 -10
- package/dist/Query.d.ts +40 -18
- package/dist/Query.js +15 -0
- package/dist/Sanitizer.d.ts +1 -1
- package/dist/Schema.d.ts +23 -0
- package/dist/Schema.js +60 -0
- package/dist/Statement.d.ts +5 -2
- package/dist/Statement.js +2 -2
- package/dist/Table.d.ts +8 -10
- package/dist/Table.js +34 -18
- package/dist/Target.d.ts +4 -4
- package/dist/driver/better-sqlite3.d.ts +10 -5
- package/dist/driver/better-sqlite3.js +23 -25
- package/dist/driver/sql.js.d.ts +10 -5
- package/dist/driver/sql.js.js +32 -33
- package/dist/driver/sqlite3.d.ts +10 -3
- package/dist/driver/sqlite3.js +47 -46
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/sqlite/SqliteFormatter.d.ts +1 -1
- package/dist/sqlite/SqliteFormatter.js +1 -1
- package/dist/sqlite/SqliteSchema.d.ts +24 -0
- package/dist/sqlite/SqliteSchema.js +40 -0
- package/package.json +1 -1
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
// src/driver/better-sqlite3.ts
|
|
2
2
|
import { Driver } from "../Driver.js";
|
|
3
|
-
import { QueryType } from "../Query.js";
|
|
4
3
|
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
+
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
5
5
|
var BetterSqlite3Driver = class extends Driver.Sync {
|
|
6
6
|
constructor(db) {
|
|
7
|
-
super();
|
|
7
|
+
super(new SqliteFormatter());
|
|
8
8
|
this.db = db;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return { rowsAffected: changes };
|
|
32
|
-
}
|
|
10
|
+
rows([sql, params]) {
|
|
11
|
+
return this.db.prepare(sql).all(...params);
|
|
12
|
+
}
|
|
13
|
+
values([sql, params]) {
|
|
14
|
+
return this.db.prepare(sql).raw().all(...params);
|
|
15
|
+
}
|
|
16
|
+
execute([sql, params]) {
|
|
17
|
+
this.db.prepare(sql).run(...params);
|
|
18
|
+
}
|
|
19
|
+
mutate([sql, params]) {
|
|
20
|
+
const { changes } = this.db.prepare(sql).run(...params);
|
|
21
|
+
return { rowsAffected: changes };
|
|
22
|
+
}
|
|
23
|
+
schemaInstructions(tableName) {
|
|
24
|
+
const columnData = this.rows(
|
|
25
|
+
SqliteSchema.tableData(tableName).compile(this.formatter)
|
|
26
|
+
);
|
|
27
|
+
const indexData = this.rows(
|
|
28
|
+
SqliteSchema.indexData(tableName).compile(this.formatter)
|
|
29
|
+
);
|
|
30
|
+
return SqliteSchema.createInstructions(columnData, indexData);
|
|
33
31
|
}
|
|
34
32
|
export() {
|
|
35
33
|
return this.db.serialize();
|
package/dist/driver/sql.js.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { Database } from 'sql.js';
|
|
2
2
|
import { Driver } from '../Driver';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { SchemaInstructions } from '../Schema';
|
|
4
|
+
import { Statement } from '../Statement';
|
|
5
5
|
export declare class SqlJsDriver extends Driver.Sync {
|
|
6
|
-
|
|
7
|
-
formatter: SqliteFormatter;
|
|
6
|
+
db: Database;
|
|
8
7
|
constructor(db: Database);
|
|
9
|
-
|
|
8
|
+
rows<T extends object = object>([sql, params]: Statement.Compiled): Array<T>;
|
|
9
|
+
values([sql, params]: Statement.Compiled): Array<Array<any>>;
|
|
10
|
+
execute([sql, params]: Statement.Compiled): void;
|
|
11
|
+
mutate([sql, params]: Statement.Compiled): {
|
|
12
|
+
rowsAffected: number;
|
|
13
|
+
};
|
|
14
|
+
schemaInstructions(tableName: string): SchemaInstructions | undefined;
|
|
10
15
|
export(): Uint8Array;
|
|
11
16
|
}
|
|
12
17
|
export declare function connect(db: Database): SqlJsDriver;
|
package/dist/driver/sql.js.js
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
// src/driver/sql.js.ts
|
|
2
2
|
import { Driver } from "../Driver.js";
|
|
3
|
-
import { QueryType } from "../Query.js";
|
|
4
3
|
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
+
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
5
5
|
var SqlJsDriver = class extends Driver.Sync {
|
|
6
6
|
constructor(db) {
|
|
7
|
-
super();
|
|
7
|
+
super(new SqliteFormatter());
|
|
8
8
|
this.db = db;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
execute(query) {
|
|
12
|
-
const [sql, params] = this.formatter.compile(query);
|
|
10
|
+
rows([sql, params]) {
|
|
13
11
|
const stmt = this.db.prepare(sql);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
12
|
+
stmt.bind(params);
|
|
13
|
+
const res = [];
|
|
14
|
+
while (stmt.step())
|
|
15
|
+
res.push(stmt.getAsObject());
|
|
16
|
+
return res;
|
|
17
|
+
}
|
|
18
|
+
values([sql, params]) {
|
|
19
|
+
const stmt = this.db.prepare(sql);
|
|
20
|
+
stmt.bind(params);
|
|
21
|
+
const res = [];
|
|
22
|
+
while (stmt.step())
|
|
23
|
+
res.push(stmt.get());
|
|
24
|
+
return res;
|
|
25
|
+
}
|
|
26
|
+
execute([sql, params]) {
|
|
27
|
+
this.db.prepare(sql).run(params);
|
|
28
|
+
}
|
|
29
|
+
mutate([sql, params]) {
|
|
30
|
+
this.db.prepare(sql).run(params);
|
|
31
|
+
return { rowsAffected: this.db.getRowsModified() };
|
|
32
|
+
}
|
|
33
|
+
schemaInstructions(tableName) {
|
|
34
|
+
const columnData = this.rows(
|
|
35
|
+
SqliteSchema.tableData(tableName).compile(this.formatter)
|
|
36
|
+
);
|
|
37
|
+
const indexData = this.rows(
|
|
38
|
+
SqliteSchema.indexData(tableName).compile(this.formatter)
|
|
39
|
+
);
|
|
40
|
+
return SqliteSchema.createInstructions(columnData, indexData);
|
|
42
41
|
}
|
|
43
42
|
export() {
|
|
44
43
|
return this.db.export();
|
package/dist/driver/sqlite3.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { Database } from 'sqlite3';
|
|
2
2
|
import { Driver } from '../Driver';
|
|
3
3
|
import { Query } from '../Query';
|
|
4
|
-
import {
|
|
4
|
+
import { SchemaInstructions } from '../Schema';
|
|
5
|
+
import { Statement } from '../Statement';
|
|
5
6
|
export declare class Sqlite3Driver extends Driver.Async {
|
|
6
7
|
private db;
|
|
7
|
-
formatter: SqliteFormatter;
|
|
8
8
|
lock: Promise<void> | undefined;
|
|
9
9
|
constructor(db: Database);
|
|
10
|
-
|
|
10
|
+
executeQuery<T>(query: Query<T>): Promise<T>;
|
|
11
|
+
rows<T extends object = object>([sql, params]: Statement.Compiled): Promise<Array<T>>;
|
|
12
|
+
values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
|
|
13
|
+
execute([sql, params]: Statement.Compiled): Promise<void>;
|
|
14
|
+
mutate([sql, params]: Statement.Compiled): Promise<{
|
|
15
|
+
rowsAffected: number;
|
|
16
|
+
}>;
|
|
17
|
+
schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
|
|
11
18
|
isolate(): [connection: Driver.Async, release: () => Promise<void>];
|
|
12
19
|
}
|
|
13
20
|
export declare function connect(db: Database): Sqlite3Driver;
|
package/dist/driver/sqlite3.js
CHANGED
|
@@ -1,62 +1,63 @@
|
|
|
1
1
|
// src/driver/sqlite3.ts
|
|
2
2
|
import { Driver } from "../Driver.js";
|
|
3
|
-
import { QueryType } from "../Query.js";
|
|
4
3
|
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
+
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
5
5
|
var Sqlite3Driver = class extends Driver.Async {
|
|
6
6
|
constructor(db) {
|
|
7
|
-
super();
|
|
7
|
+
super(new SqliteFormatter());
|
|
8
8
|
this.db = db;
|
|
9
9
|
}
|
|
10
|
-
formatter = new SqliteFormatter();
|
|
11
10
|
lock;
|
|
12
|
-
async
|
|
11
|
+
async executeQuery(query) {
|
|
13
12
|
await this.lock;
|
|
13
|
+
return super.executeQuery(query);
|
|
14
|
+
}
|
|
15
|
+
rows([sql, params]) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const stmt = this.db.prepare(sql);
|
|
18
|
+
stmt.all(params, (err, rows) => {
|
|
19
|
+
if (err)
|
|
20
|
+
reject(err);
|
|
21
|
+
else
|
|
22
|
+
resolve(rows);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async values(stmt) {
|
|
27
|
+
const rows = await this.rows(stmt);
|
|
28
|
+
return rows.map(Object.values);
|
|
29
|
+
}
|
|
30
|
+
execute([sql, params]) {
|
|
14
31
|
return new Promise((resolve, reject) => {
|
|
15
|
-
const [sql, params] = this.formatter.compile(query);
|
|
16
32
|
const stmt = this.db.prepare(sql);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
resolve(query.singleResult ? res[0] : res);
|
|
24
|
-
});
|
|
25
|
-
} else if (query.type === QueryType.Raw) {
|
|
26
|
-
switch (query.expectedReturn) {
|
|
27
|
-
case "row":
|
|
28
|
-
return stmt.get(params, (err, row) => {
|
|
29
|
-
if (err)
|
|
30
|
-
reject(err);
|
|
31
|
-
else
|
|
32
|
-
resolve(row);
|
|
33
|
-
});
|
|
34
|
-
case "rows":
|
|
35
|
-
return stmt.all(params, (err, rows) => {
|
|
36
|
-
if (err)
|
|
37
|
-
reject(err);
|
|
38
|
-
else
|
|
39
|
-
resolve(rows);
|
|
40
|
-
});
|
|
41
|
-
default:
|
|
42
|
-
stmt.run(params, (err) => {
|
|
43
|
-
if (err)
|
|
44
|
-
reject(err);
|
|
45
|
-
else
|
|
46
|
-
resolve(void 0);
|
|
47
|
-
});
|
|
48
|
-
return void 0;
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
stmt.run(params, function(err) {
|
|
52
|
-
if (err)
|
|
53
|
-
reject(err);
|
|
54
|
-
else
|
|
55
|
-
resolve({ rowsAffected: this.changes });
|
|
56
|
-
});
|
|
57
|
-
}
|
|
33
|
+
stmt.run(params, (err) => {
|
|
34
|
+
if (err)
|
|
35
|
+
reject(err);
|
|
36
|
+
else
|
|
37
|
+
resolve();
|
|
38
|
+
});
|
|
58
39
|
});
|
|
59
40
|
}
|
|
41
|
+
mutate([sql, params]) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const stmt = this.db.prepare(sql);
|
|
44
|
+
stmt.run(params, function(err) {
|
|
45
|
+
if (err)
|
|
46
|
+
reject(err);
|
|
47
|
+
else
|
|
48
|
+
resolve({ rowsAffected: this.changes });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async schemaInstructions(tableName) {
|
|
53
|
+
const columnData = await this.rows(
|
|
54
|
+
SqliteSchema.tableData(tableName).compile(this.formatter)
|
|
55
|
+
);
|
|
56
|
+
const indexData = await this.rows(
|
|
57
|
+
SqliteSchema.indexData(tableName).compile(this.formatter)
|
|
58
|
+
);
|
|
59
|
+
return SqliteSchema.createInstructions(columnData, indexData);
|
|
60
|
+
}
|
|
60
61
|
isolate() {
|
|
61
62
|
const connection = new Sqlite3Driver(this.db);
|
|
62
63
|
let release, trigger = new Promise((resolve) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './Column';
|
|
2
2
|
export * from './Cursor';
|
|
3
|
+
export * from './Driver';
|
|
3
4
|
export * from './Expr';
|
|
4
5
|
export * from './Fields';
|
|
5
6
|
export * from './Formatter';
|
|
@@ -9,6 +10,7 @@ export * from './OrderBy';
|
|
|
9
10
|
export * from './Param';
|
|
10
11
|
export * from './Query';
|
|
11
12
|
export * from './Sanitizer';
|
|
13
|
+
export * from './Schema';
|
|
12
14
|
export * from './Selection';
|
|
13
15
|
export * from './Statement';
|
|
14
16
|
export * from './Table';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
export * from "./Column.js";
|
|
3
3
|
export * from "./Cursor.js";
|
|
4
|
+
export * from "./Driver.js";
|
|
4
5
|
export * from "./Expr.js";
|
|
5
6
|
export * from "./Fields.js";
|
|
6
7
|
export * from "./Formatter.js";
|
|
@@ -10,6 +11,7 @@ export * from "./OrderBy.js";
|
|
|
10
11
|
export * from "./Param.js";
|
|
11
12
|
export * from "./Query.js";
|
|
12
13
|
export * from "./Sanitizer.js";
|
|
14
|
+
export * from "./Schema.js";
|
|
13
15
|
export * from "./Selection.js";
|
|
14
16
|
export * from "./Statement.js";
|
|
15
17
|
export * from "./Table.js";
|
|
@@ -2,7 +2,7 @@ import { Formatter } from '../Formatter';
|
|
|
2
2
|
import { Statement } from '../Statement';
|
|
3
3
|
export declare class SqliteFormatter extends Formatter {
|
|
4
4
|
escapeValue(value: any): string;
|
|
5
|
-
|
|
5
|
+
escapeIdentifier(input: string): string;
|
|
6
6
|
escapeString(input: string): string;
|
|
7
7
|
formatSqlAccess(on: Statement, field: string): Statement;
|
|
8
8
|
formatJsonAccess(on: Statement, field: string): Statement;
|
|
@@ -23,7 +23,7 @@ var SqliteFormatter = class extends Formatter {
|
|
|
23
23
|
return this.escapeString(value);
|
|
24
24
|
return "json(" + this.escapeString(JSON.stringify(value)) + ")";
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
escapeIdentifier(input) {
|
|
27
27
|
return escapeWithin(input, "`");
|
|
28
28
|
}
|
|
29
29
|
escapeString(input) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SchemaInstructions } from '../Schema';
|
|
2
|
+
import { Statement } from '../Statement';
|
|
3
|
+
export declare namespace SqliteSchema {
|
|
4
|
+
type Column = {
|
|
5
|
+
cid: number;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
notnull: number;
|
|
9
|
+
dflt_value: string | null;
|
|
10
|
+
pk: number;
|
|
11
|
+
};
|
|
12
|
+
interface Index {
|
|
13
|
+
type: 'index';
|
|
14
|
+
name: string;
|
|
15
|
+
tbl_name: string;
|
|
16
|
+
rootpage: number;
|
|
17
|
+
sql: string;
|
|
18
|
+
}
|
|
19
|
+
function tableData(tableName: string): Statement;
|
|
20
|
+
function indexData(tableName: string): Statement;
|
|
21
|
+
function createInstructions(columnData: Array<Column>, indexData: Array<Index>): SchemaInstructions | undefined;
|
|
22
|
+
function columnInstruction(column: Column): [string, string];
|
|
23
|
+
function indexInstruction(index: Index): [string, string];
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/sqlite/SqliteSchema.ts
|
|
2
|
+
import { Statement, identifier } from "../Statement.js";
|
|
3
|
+
import { SqliteFormatter } from "./SqliteFormatter.js";
|
|
4
|
+
var SqliteSchema;
|
|
5
|
+
((SqliteSchema2) => {
|
|
6
|
+
const formatter = new SqliteFormatter();
|
|
7
|
+
function tableData(tableName) {
|
|
8
|
+
return Statement.tag`select * from pragma_table_info(${tableName}) order by cid`;
|
|
9
|
+
}
|
|
10
|
+
SqliteSchema2.tableData = tableData;
|
|
11
|
+
function indexData(tableName) {
|
|
12
|
+
return Statement.tag`select * from sqlite_master where type='index' and tbl_name=${tableName}`;
|
|
13
|
+
}
|
|
14
|
+
SqliteSchema2.indexData = indexData;
|
|
15
|
+
function createInstructions(columnData, indexData2) {
|
|
16
|
+
if (columnData.length === 0 && indexData2.length === 0)
|
|
17
|
+
return void 0;
|
|
18
|
+
const columns = columnData.map(columnInstruction);
|
|
19
|
+
const indexes = indexData2.map(indexInstruction);
|
|
20
|
+
return {
|
|
21
|
+
columns: Object.fromEntries(columns),
|
|
22
|
+
indexes: Object.fromEntries(indexes)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
SqliteSchema2.createInstructions = createInstructions;
|
|
26
|
+
function columnInstruction(column) {
|
|
27
|
+
return [
|
|
28
|
+
column.name,
|
|
29
|
+
identifier(column.name).add(column.type.toLowerCase()).addIf(column.pk === 1, "primary key").addIf(column.notnull === 1, "not null").addIf(column.dflt_value !== null, column.dflt_value).compile(formatter)[0]
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
SqliteSchema2.columnInstruction = columnInstruction;
|
|
33
|
+
function indexInstruction(index) {
|
|
34
|
+
return [index.name, index.sql];
|
|
35
|
+
}
|
|
36
|
+
SqliteSchema2.indexInstruction = indexInstruction;
|
|
37
|
+
})(SqliteSchema || (SqliteSchema = {}));
|
|
38
|
+
export {
|
|
39
|
+
SqliteSchema
|
|
40
|
+
};
|