rado 0.4.6 → 0.4.7
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/lib/Driver.js +1 -1
- package/dist/sqlite/SqliteFormatter.js +1 -0
- package/dist/sqlite/SqliteFunctions.d.ts +2 -0
- package/package.json +1 -1
- package/dist/define/CTE.d.ts +0 -2
- package/dist/define/CTE.js +0 -51
- package/dist/define/Cursor.d.ts +0 -108
- package/dist/define/Cursor.js +0 -338
- package/dist/define/Update.d.ts +0 -4
- package/dist/define/Update.js +0 -0
- package/dist/define/query/Batch.d.ts +0 -7
- package/dist/define/query/Batch.js +0 -17
- package/dist/define/query/CreateTable.d.ts +0 -6
- package/dist/define/query/CreateTable.js +0 -11
- package/dist/define/query/Delete.d.ts +0 -11
- package/dist/define/query/Delete.js +0 -18
- package/dist/define/query/Insert.d.ts +0 -22
- package/dist/define/query/Insert.js +0 -47
- package/dist/define/query/Select.d.ts +0 -39
- package/dist/define/query/Select.js +0 -170
- package/dist/define/query/TableSelect.d.ts +0 -28
- package/dist/define/query/TableSelect.js +0 -79
- package/dist/define/query/Union.d.ts +0 -17
- package/dist/define/query/Union.js +0 -116
- package/dist/define/query/Update.d.ts +0 -12
- package/dist/define/query/Update.js +0 -18
- package/dist/deno/driver/better-sqlite3.js +0 -57
- package/dist/deno/driver/bun-sqlite.js +0 -69
- package/dist/deno/driver/sql.js.js +0 -72
- package/dist/deno/driver/sqlite3.js +0 -123
- package/dist/deno/index.js +0 -14
- package/dist/deno/lib/Driver.js +0 -330
- package/dist/deno/lib/Formatter.js +0 -715
- package/dist/deno/lib/Sanitizer.js +0 -0
- package/dist/deno/lib/SqlError.js +0 -11
- package/dist/deno/lib/Statement.js +0 -108
- package/dist/deno/sqlite/SqliteFormatter.js +0 -70
- package/dist/deno/sqlite/SqliteFunctions.js +0 -150
- package/dist/deno/sqlite/SqliteSchema.js +0 -47
- package/dist/deno/sqlite.js +0 -3
- package/dist/deno/util/Callable.js +0 -15
- package/dist/sqlite/index.d.ts +0 -2
- package/dist/sqlite/index.js +0 -3
- package/dist/src/driver/better-sqlite3.js +0 -49
- package/dist/src/driver/sql.js.js +0 -66
- package/dist/src/driver/sqlite3.js +0 -87
- package/dist/src/index.js +0 -24
- package/dist/src/lib/Column.js +0 -63
- package/dist/src/lib/Cursor.js +0 -231
- package/dist/src/lib/Driver.js +0 -316
- package/dist/src/lib/Expr.js +0 -284
- package/dist/src/lib/Fields.js +0 -0
- package/dist/src/lib/Formatter.js +0 -625
- package/dist/src/lib/Functions.js +0 -11
- package/dist/src/lib/Id.js +0 -0
- package/dist/src/lib/Index.js +0 -20
- package/dist/src/lib/Ops.js +0 -45
- package/dist/src/lib/OrderBy.js +0 -9
- package/dist/src/lib/Param.js +0 -27
- package/dist/src/lib/Query.js +0 -74
- package/dist/src/lib/Sanitizer.js +0 -0
- package/dist/src/lib/Schema.js +0 -67
- package/dist/src/lib/Selection.js +0 -7
- package/dist/src/lib/Statement.js +0 -103
- package/dist/src/lib/Table.js +0 -130
- package/dist/src/lib/Target.js +0 -37
- package/dist/src/lib/Update.js +0 -0
- package/dist/src/sqlite/SqliteFormatter.js +0 -67
- package/dist/src/sqlite/SqliteFunctions.js +0 -146
- package/dist/src/sqlite/SqliteSchema.js +0 -47
- package/dist/src/sqlite.js +0 -3
- package/dist/test/DbSuite.js +0 -28
- package/dist/test/TSTestTypes.js +0 -6
- package/dist/test/TestBasic.js +0 -172
- package/dist/test/TestExtend.js +0 -68
- package/dist/test/TestFts5.js +0 -34
- package/dist/test/TestFunctions.js +0 -28
- package/dist/test/TestJoins.js +0 -34
- package/dist/test/TestJson.js +0 -33
- package/dist/test/TestPrepare.js +0 -27
- package/dist/test/TestRawSql.js +0 -31
- package/dist/test/TestSchema.js +0 -69
- package/dist/test/TestSubQueries.js +0 -79
- package/dist/test/TestTransaction.js +0 -54
- package/dist/test/TestUpdate.js +0 -95
- package/dist/test/index.js +0 -14
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// src/lib/Statement.ts
|
|
2
|
-
import { ParamData, ParamType } from "../define/Param.ts";
|
|
3
|
-
var SEPARATE = ", ";
|
|
4
|
-
var WHITESPACE = " ";
|
|
5
|
-
var NEWLINE = "\n";
|
|
6
|
-
var INSERT_PARAM = "?";
|
|
7
|
-
var Statement = class {
|
|
8
|
-
constructor(sanitizer, options = {}) {
|
|
9
|
-
this.sanitizer = sanitizer;
|
|
10
|
-
this.options = options;
|
|
11
|
-
}
|
|
12
|
-
sql = "";
|
|
13
|
-
paramData = [];
|
|
14
|
-
currentIndent = "";
|
|
15
|
-
space() {
|
|
16
|
-
if (this.sql === "")
|
|
17
|
-
return this;
|
|
18
|
-
return this.raw(WHITESPACE);
|
|
19
|
-
}
|
|
20
|
-
add(addition) {
|
|
21
|
-
if (!addition)
|
|
22
|
-
return this;
|
|
23
|
-
return this.space().raw(addition);
|
|
24
|
-
}
|
|
25
|
-
addLine(addition) {
|
|
26
|
-
if (!addition)
|
|
27
|
-
return this;
|
|
28
|
-
return this.newline().raw(addition);
|
|
29
|
-
}
|
|
30
|
-
indent() {
|
|
31
|
-
this.currentIndent = this.currentIndent + " ";
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
dedent() {
|
|
35
|
-
this.currentIndent = this.currentIndent.slice(0, -2);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
newline() {
|
|
39
|
-
if (this.options.skipNewlines)
|
|
40
|
-
return this;
|
|
41
|
-
return this.raw(NEWLINE + this.currentIndent);
|
|
42
|
-
}
|
|
43
|
-
identifier(name) {
|
|
44
|
-
return this.raw(this.sanitizer.escapeIdentifier(name));
|
|
45
|
-
}
|
|
46
|
-
addIdentifier(name) {
|
|
47
|
-
return this.space().identifier(name);
|
|
48
|
-
}
|
|
49
|
-
value(value) {
|
|
50
|
-
this.paramData.push(ParamData.Value(value));
|
|
51
|
-
return this.raw(INSERT_PARAM);
|
|
52
|
-
}
|
|
53
|
-
addValue(value) {
|
|
54
|
-
return this.space().value(value);
|
|
55
|
-
}
|
|
56
|
-
param(data) {
|
|
57
|
-
this.paramData.push(data);
|
|
58
|
-
return this.raw(INSERT_PARAM);
|
|
59
|
-
}
|
|
60
|
-
addParam(data) {
|
|
61
|
-
return this.space().param(data);
|
|
62
|
-
}
|
|
63
|
-
raw(query) {
|
|
64
|
-
if (!query)
|
|
65
|
-
return this;
|
|
66
|
-
this.sql += query;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
openParenthesis() {
|
|
70
|
-
return this.raw("(").indent().newline();
|
|
71
|
-
}
|
|
72
|
-
closeParenthesis() {
|
|
73
|
-
return this.dedent().newline().raw(")");
|
|
74
|
-
}
|
|
75
|
-
*call(parts, separator = SEPARATE) {
|
|
76
|
-
if (parts.length === 0)
|
|
77
|
-
return this.raw("()");
|
|
78
|
-
this.openParenthesis();
|
|
79
|
-
yield* this.separate(parts, separator);
|
|
80
|
-
this.closeParenthesis();
|
|
81
|
-
}
|
|
82
|
-
*separate(parts, separator = SEPARATE) {
|
|
83
|
-
for (let i = 0; i < parts.length; i++) {
|
|
84
|
-
if (i > 0)
|
|
85
|
-
this.raw(separator).newline();
|
|
86
|
-
yield parts[i];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
isEmpty() {
|
|
90
|
-
return this.sql === "";
|
|
91
|
-
}
|
|
92
|
-
params(input) {
|
|
93
|
-
return this.paramData.map((param) => {
|
|
94
|
-
if (param.type === ParamType.Named) {
|
|
95
|
-
if (input && param.name in input)
|
|
96
|
-
return this.sanitizer.formatParamValue(input[param.name]);
|
|
97
|
-
throw new TypeError(`Missing parameter ${param.name}`);
|
|
98
|
-
}
|
|
99
|
-
return this.sanitizer.formatParamValue(param.value);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
toString() {
|
|
103
|
-
return this.sql;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
export {
|
|
107
|
-
Statement
|
|
108
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// src/sqlite/SqliteFormatter.ts
|
|
2
|
-
import { ExprType } from "../define/Expr.ts";
|
|
3
|
-
import { Formatter } from "../lib/Formatter.ts";
|
|
4
|
-
var BACKTICK = "`";
|
|
5
|
-
var ESCAPE_BACKTICK = "``";
|
|
6
|
-
var SINGLE_QUOTE = "'";
|
|
7
|
-
var ESCAPE_SINGLE_QUOTE = "''";
|
|
8
|
-
var MATCH_BACKTICK = /`/g;
|
|
9
|
-
var MATCH_SINGLE_QUOTE = /'/g;
|
|
10
|
-
var SqliteFormatter = class extends Formatter {
|
|
11
|
-
formatParamValue(paramValue) {
|
|
12
|
-
if (paramValue === null || paramValue === void 0)
|
|
13
|
-
return null;
|
|
14
|
-
if (typeof paramValue === "boolean")
|
|
15
|
-
return paramValue ? 1 : 0;
|
|
16
|
-
if (typeof paramValue === "number")
|
|
17
|
-
return paramValue;
|
|
18
|
-
if (typeof paramValue === "string")
|
|
19
|
-
return paramValue;
|
|
20
|
-
return JSON.stringify(paramValue);
|
|
21
|
-
}
|
|
22
|
-
escapeValue(value) {
|
|
23
|
-
if (value === null || value === void 0)
|
|
24
|
-
return "NULL";
|
|
25
|
-
if (typeof value === "boolean")
|
|
26
|
-
return value ? "1" : "0";
|
|
27
|
-
if (typeof value === "number")
|
|
28
|
-
return String(value);
|
|
29
|
-
if (typeof value === "string")
|
|
30
|
-
return this.escapeString(value);
|
|
31
|
-
return "json(" + this.escapeString(JSON.stringify(value)) + ")";
|
|
32
|
-
}
|
|
33
|
-
escapeIdentifier(input) {
|
|
34
|
-
return BACKTICK + input.replace(MATCH_BACKTICK, ESCAPE_BACKTICK) + BACKTICK;
|
|
35
|
-
}
|
|
36
|
-
escapeString(input) {
|
|
37
|
-
return SINGLE_QUOTE + input.replace(MATCH_SINGLE_QUOTE, ESCAPE_SINGLE_QUOTE) + SINGLE_QUOTE;
|
|
38
|
-
}
|
|
39
|
-
formatAccess(ctx, mkSubject, field) {
|
|
40
|
-
const { stmt, formatAsJson } = ctx;
|
|
41
|
-
mkSubject();
|
|
42
|
-
stmt.raw(formatAsJson ? "->" : "->>");
|
|
43
|
-
return this.formatString(ctx, `$.${field}`);
|
|
44
|
-
}
|
|
45
|
-
formatExpr(ctx, expr) {
|
|
46
|
-
const { stmt } = ctx;
|
|
47
|
-
switch (expr.type) {
|
|
48
|
-
case ExprType.Call:
|
|
49
|
-
switch (expr.method) {
|
|
50
|
-
case "match":
|
|
51
|
-
const [from, query] = expr.params;
|
|
52
|
-
this.formatExprValue({ ...ctx, tableAsExpr: true }, from);
|
|
53
|
-
stmt.raw(" MATCH ");
|
|
54
|
-
this.formatExprValue(ctx, query);
|
|
55
|
-
return stmt;
|
|
56
|
-
case "highlight":
|
|
57
|
-
case "snippet":
|
|
58
|
-
stmt.identifier(expr.method);
|
|
59
|
-
for (const param of stmt.call(expr.params))
|
|
60
|
-
this.formatExprValue({ ...ctx, tableAsExpr: true }, param);
|
|
61
|
-
return stmt;
|
|
62
|
-
}
|
|
63
|
-
default:
|
|
64
|
-
return super.formatExpr(ctx, expr);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
export {
|
|
69
|
-
SqliteFormatter
|
|
70
|
-
};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// src/sqlite/SqliteFunctions.ts
|
|
2
|
-
import { Functions } from "../define/Functions.ts";
|
|
3
|
-
var SqliteFunctions = Functions;
|
|
4
|
-
var {
|
|
5
|
-
count,
|
|
6
|
-
iif,
|
|
7
|
-
exists,
|
|
8
|
-
match,
|
|
9
|
-
highlight,
|
|
10
|
-
snippet,
|
|
11
|
-
cast,
|
|
12
|
-
abs,
|
|
13
|
-
changes,
|
|
14
|
-
char,
|
|
15
|
-
coalesce,
|
|
16
|
-
ifnull,
|
|
17
|
-
instr,
|
|
18
|
-
last_insert_rowid,
|
|
19
|
-
length,
|
|
20
|
-
likelihood,
|
|
21
|
-
likely,
|
|
22
|
-
lower,
|
|
23
|
-
ltrim,
|
|
24
|
-
max,
|
|
25
|
-
min,
|
|
26
|
-
nullif,
|
|
27
|
-
prnumberf,
|
|
28
|
-
quote,
|
|
29
|
-
random,
|
|
30
|
-
replace,
|
|
31
|
-
round,
|
|
32
|
-
rtrim,
|
|
33
|
-
sign,
|
|
34
|
-
soundex,
|
|
35
|
-
sqlite_version,
|
|
36
|
-
substr,
|
|
37
|
-
total_changes,
|
|
38
|
-
trim,
|
|
39
|
-
unicode,
|
|
40
|
-
unlikely,
|
|
41
|
-
upper,
|
|
42
|
-
avg,
|
|
43
|
-
group_concat,
|
|
44
|
-
sum,
|
|
45
|
-
acos,
|
|
46
|
-
acosh,
|
|
47
|
-
asin,
|
|
48
|
-
asinh,
|
|
49
|
-
atan,
|
|
50
|
-
atan2,
|
|
51
|
-
atanh,
|
|
52
|
-
ceil,
|
|
53
|
-
cos,
|
|
54
|
-
cosh,
|
|
55
|
-
degrees,
|
|
56
|
-
exp,
|
|
57
|
-
floor,
|
|
58
|
-
ln,
|
|
59
|
-
log,
|
|
60
|
-
log2,
|
|
61
|
-
mod,
|
|
62
|
-
pi,
|
|
63
|
-
pow,
|
|
64
|
-
radians,
|
|
65
|
-
sin,
|
|
66
|
-
sinh,
|
|
67
|
-
sqrt,
|
|
68
|
-
tan,
|
|
69
|
-
tanh,
|
|
70
|
-
trunc,
|
|
71
|
-
date,
|
|
72
|
-
time,
|
|
73
|
-
datetime,
|
|
74
|
-
julianday,
|
|
75
|
-
strftime
|
|
76
|
-
} = SqliteFunctions;
|
|
77
|
-
export {
|
|
78
|
-
SqliteFunctions,
|
|
79
|
-
abs,
|
|
80
|
-
acos,
|
|
81
|
-
acosh,
|
|
82
|
-
asin,
|
|
83
|
-
asinh,
|
|
84
|
-
atan,
|
|
85
|
-
atan2,
|
|
86
|
-
atanh,
|
|
87
|
-
avg,
|
|
88
|
-
cast,
|
|
89
|
-
ceil,
|
|
90
|
-
changes,
|
|
91
|
-
char,
|
|
92
|
-
coalesce,
|
|
93
|
-
cos,
|
|
94
|
-
cosh,
|
|
95
|
-
count,
|
|
96
|
-
date,
|
|
97
|
-
datetime,
|
|
98
|
-
degrees,
|
|
99
|
-
exists,
|
|
100
|
-
exp,
|
|
101
|
-
floor,
|
|
102
|
-
group_concat,
|
|
103
|
-
highlight,
|
|
104
|
-
ifnull,
|
|
105
|
-
iif,
|
|
106
|
-
instr,
|
|
107
|
-
julianday,
|
|
108
|
-
last_insert_rowid,
|
|
109
|
-
length,
|
|
110
|
-
likelihood,
|
|
111
|
-
likely,
|
|
112
|
-
ln,
|
|
113
|
-
log,
|
|
114
|
-
log2,
|
|
115
|
-
lower,
|
|
116
|
-
ltrim,
|
|
117
|
-
match,
|
|
118
|
-
max,
|
|
119
|
-
min,
|
|
120
|
-
mod,
|
|
121
|
-
nullif,
|
|
122
|
-
pi,
|
|
123
|
-
pow,
|
|
124
|
-
prnumberf,
|
|
125
|
-
quote,
|
|
126
|
-
radians,
|
|
127
|
-
random,
|
|
128
|
-
replace,
|
|
129
|
-
round,
|
|
130
|
-
rtrim,
|
|
131
|
-
sign,
|
|
132
|
-
sin,
|
|
133
|
-
sinh,
|
|
134
|
-
snippet,
|
|
135
|
-
soundex,
|
|
136
|
-
sqlite_version,
|
|
137
|
-
sqrt,
|
|
138
|
-
strftime,
|
|
139
|
-
substr,
|
|
140
|
-
sum,
|
|
141
|
-
tan,
|
|
142
|
-
tanh,
|
|
143
|
-
time,
|
|
144
|
-
total_changes,
|
|
145
|
-
trim,
|
|
146
|
-
trunc,
|
|
147
|
-
unicode,
|
|
148
|
-
unlikely,
|
|
149
|
-
upper
|
|
150
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// src/sqlite/SqliteSchema.ts
|
|
2
|
-
import { Cursor } from "../define/Cursor.ts";
|
|
3
|
-
import { Statement } from "../lib/Statement.ts";
|
|
4
|
-
import { SqliteFormatter } from "./SqliteFormatter.ts";
|
|
5
|
-
var SqliteSchema;
|
|
6
|
-
((SqliteSchema2) => {
|
|
7
|
-
const formatter = new SqliteFormatter();
|
|
8
|
-
function tableData(tableName) {
|
|
9
|
-
return Cursor.all`select * from pragma_table_info(${tableName}) order by cid`;
|
|
10
|
-
}
|
|
11
|
-
SqliteSchema2.tableData = tableData;
|
|
12
|
-
function indexData(tableName) {
|
|
13
|
-
return Cursor.all`select * from sqlite_master where type='index' and tbl_name=${tableName}`;
|
|
14
|
-
}
|
|
15
|
-
SqliteSchema2.indexData = indexData;
|
|
16
|
-
function createInstructions(columnData, indexData2) {
|
|
17
|
-
if (columnData.length === 0 && indexData2.length === 0)
|
|
18
|
-
return void 0;
|
|
19
|
-
const columns = columnData.map(columnInstruction);
|
|
20
|
-
const indexes = indexData2.map(indexInstruction).filter((row) => row[1]);
|
|
21
|
-
return {
|
|
22
|
-
columns: Object.fromEntries(columns),
|
|
23
|
-
indexes: Object.fromEntries(indexes)
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
SqliteSchema2.createInstructions = createInstructions;
|
|
27
|
-
function columnInstruction(column) {
|
|
28
|
-
const stmt = new Statement(formatter);
|
|
29
|
-
stmt.identifier(column.name).add(column.type);
|
|
30
|
-
if (column.pk === 1)
|
|
31
|
-
stmt.add("PRIMARY KEY");
|
|
32
|
-
if (column.notnull === 1)
|
|
33
|
-
stmt.add("NOT NULL");
|
|
34
|
-
if (column.dflt_value !== null) {
|
|
35
|
-
stmt.add("DEFAULT").space().openParenthesis().raw(column.dflt_value).closeParenthesis();
|
|
36
|
-
}
|
|
37
|
-
return [column.name, stmt.sql];
|
|
38
|
-
}
|
|
39
|
-
SqliteSchema2.columnInstruction = columnInstruction;
|
|
40
|
-
function indexInstruction(index) {
|
|
41
|
-
return [index.name, index.sql];
|
|
42
|
-
}
|
|
43
|
-
SqliteSchema2.indexInstruction = indexInstruction;
|
|
44
|
-
})(SqliteSchema || (SqliteSchema = {}));
|
|
45
|
-
export {
|
|
46
|
-
SqliteSchema
|
|
47
|
-
};
|
package/dist/deno/sqlite.js
DELETED
package/dist/sqlite/index.d.ts
DELETED
package/dist/sqlite/index.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// src/driver/better-sqlite3.ts
|
|
2
|
-
import { Driver } from "../lib/Driver.js";
|
|
3
|
-
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
-
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
5
|
-
var PreparedStatement = class {
|
|
6
|
-
constructor(stmt) {
|
|
7
|
-
this.stmt = stmt;
|
|
8
|
-
}
|
|
9
|
-
all(params = []) {
|
|
10
|
-
return this.stmt.all(...params);
|
|
11
|
-
}
|
|
12
|
-
run(params = []) {
|
|
13
|
-
return { rowsAffected: this.stmt.run(...params).changes };
|
|
14
|
-
}
|
|
15
|
-
get(params = []) {
|
|
16
|
-
return this.stmt.get(...params);
|
|
17
|
-
}
|
|
18
|
-
execute(params = []) {
|
|
19
|
-
this.stmt.run(...params);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var BetterSqlite3Driver = class extends Driver.Sync {
|
|
23
|
-
constructor(db) {
|
|
24
|
-
super(new SqliteFormatter());
|
|
25
|
-
this.db = db;
|
|
26
|
-
this.tableData = this.prepare(SqliteSchema.tableData);
|
|
27
|
-
this.indexData = this.prepare(SqliteSchema.indexData);
|
|
28
|
-
}
|
|
29
|
-
tableData;
|
|
30
|
-
indexData;
|
|
31
|
-
prepareStatement(stmt) {
|
|
32
|
-
return new PreparedStatement(this.db.prepare(stmt.sql));
|
|
33
|
-
}
|
|
34
|
-
schemaInstructions(tableName) {
|
|
35
|
-
const columnData = this.tableData(tableName);
|
|
36
|
-
const indexData = this.indexData(tableName);
|
|
37
|
-
return SqliteSchema.createInstructions(columnData, indexData);
|
|
38
|
-
}
|
|
39
|
-
export() {
|
|
40
|
-
return this.db.serialize();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
function connect(db) {
|
|
44
|
-
return new BetterSqlite3Driver(db);
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
BetterSqlite3Driver,
|
|
48
|
-
connect
|
|
49
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// src/driver/sql.js.ts
|
|
2
|
-
import { Driver } from "../lib/Driver.js";
|
|
3
|
-
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
-
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
5
|
-
var PreparedStatement = class {
|
|
6
|
-
constructor(db, stmt, discardAfter) {
|
|
7
|
-
this.db = db;
|
|
8
|
-
this.stmt = stmt;
|
|
9
|
-
this.discardAfter = discardAfter;
|
|
10
|
-
}
|
|
11
|
-
all(params) {
|
|
12
|
-
this.stmt.bind(params);
|
|
13
|
-
const res = [];
|
|
14
|
-
while (this.stmt.step())
|
|
15
|
-
res.push(this.stmt.getAsObject());
|
|
16
|
-
if (this.discardAfter)
|
|
17
|
-
this.stmt.free();
|
|
18
|
-
return res;
|
|
19
|
-
}
|
|
20
|
-
run(params) {
|
|
21
|
-
this.stmt.run(params);
|
|
22
|
-
if (this.discardAfter)
|
|
23
|
-
this.stmt.free();
|
|
24
|
-
return { rowsAffected: this.db.getRowsModified() };
|
|
25
|
-
}
|
|
26
|
-
get(params) {
|
|
27
|
-
return this.all(params)[0];
|
|
28
|
-
}
|
|
29
|
-
execute(params) {
|
|
30
|
-
this.stmt.run(params);
|
|
31
|
-
if (this.discardAfter)
|
|
32
|
-
this.stmt.free();
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var SqlJsDriver = class extends Driver.Sync {
|
|
36
|
-
constructor(db) {
|
|
37
|
-
super(new SqliteFormatter());
|
|
38
|
-
this.db = db;
|
|
39
|
-
this.tableData = this.prepare(SqliteSchema.tableData);
|
|
40
|
-
this.indexData = this.prepare(SqliteSchema.indexData);
|
|
41
|
-
}
|
|
42
|
-
tableData;
|
|
43
|
-
indexData;
|
|
44
|
-
prepareStatement(stmt, discardAfter) {
|
|
45
|
-
return new PreparedStatement(
|
|
46
|
-
this.db,
|
|
47
|
-
this.db.prepare(stmt.sql),
|
|
48
|
-
discardAfter
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
schemaInstructions(tableName) {
|
|
52
|
-
const columnData = this.tableData(tableName);
|
|
53
|
-
const indexData = this.indexData(tableName);
|
|
54
|
-
return SqliteSchema.createInstructions(columnData, indexData);
|
|
55
|
-
}
|
|
56
|
-
export() {
|
|
57
|
-
return this.db.export();
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
function connect(db) {
|
|
61
|
-
return new SqlJsDriver(db);
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
SqlJsDriver,
|
|
65
|
-
connect
|
|
66
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// src/driver/sqlite3.ts
|
|
2
|
-
import { Driver } from "../lib/Driver.js";
|
|
3
|
-
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
-
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
5
|
-
var PreparedStatement = class {
|
|
6
|
-
constructor(stmt) {
|
|
7
|
-
this.stmt = stmt;
|
|
8
|
-
}
|
|
9
|
-
all(params) {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
this.stmt.all(params, (err, rows) => {
|
|
12
|
-
if (err)
|
|
13
|
-
reject(err);
|
|
14
|
-
else
|
|
15
|
-
resolve(rows);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
run(params) {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
this.stmt.run(params, function(err) {
|
|
22
|
-
if (err)
|
|
23
|
-
reject(err);
|
|
24
|
-
else
|
|
25
|
-
resolve({ rowsAffected: this.changes });
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
get(params) {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
this.stmt.get(params, (err, row) => {
|
|
32
|
-
if (err)
|
|
33
|
-
reject(err);
|
|
34
|
-
else
|
|
35
|
-
resolve(row);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
execute(params) {
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
this.stmt.run(params, (err) => {
|
|
42
|
-
if (err)
|
|
43
|
-
reject(err);
|
|
44
|
-
else
|
|
45
|
-
resolve();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var Sqlite3Driver = class extends Driver.Async {
|
|
51
|
-
constructor(db) {
|
|
52
|
-
super(new SqliteFormatter());
|
|
53
|
-
this.db = db;
|
|
54
|
-
this.tableData = this.prepare(SqliteSchema.tableData);
|
|
55
|
-
this.indexData = this.prepare(SqliteSchema.indexData);
|
|
56
|
-
}
|
|
57
|
-
lock;
|
|
58
|
-
tableData;
|
|
59
|
-
indexData;
|
|
60
|
-
async executeQuery(query, stmt, params) {
|
|
61
|
-
await this.lock;
|
|
62
|
-
return super.executeQuery(query, stmt, params);
|
|
63
|
-
}
|
|
64
|
-
prepareStatement(stmt) {
|
|
65
|
-
return new PreparedStatement(this.db.prepare(stmt.sql));
|
|
66
|
-
}
|
|
67
|
-
async schemaInstructions(tableName) {
|
|
68
|
-
const columnData = await this.tableData(tableName);
|
|
69
|
-
const indexData = await this.indexData(tableName);
|
|
70
|
-
return SqliteSchema.createInstructions(columnData, indexData);
|
|
71
|
-
}
|
|
72
|
-
isolate() {
|
|
73
|
-
const connection = new Sqlite3Driver(this.db);
|
|
74
|
-
let release, trigger = new Promise((resolve) => {
|
|
75
|
-
release = async () => resolve();
|
|
76
|
-
});
|
|
77
|
-
this.lock = Promise.resolve(this.lock).then(() => trigger);
|
|
78
|
-
return [connection, release];
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
function connect(db) {
|
|
82
|
-
return new Sqlite3Driver(db);
|
|
83
|
-
}
|
|
84
|
-
export {
|
|
85
|
-
Sqlite3Driver,
|
|
86
|
-
connect
|
|
87
|
-
};
|
package/dist/src/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
export * from "./lib/Column.js";
|
|
3
|
-
export * from "./lib/Cursor.js";
|
|
4
|
-
export * from "./lib/Driver.js";
|
|
5
|
-
export * from "./lib/Expr.js";
|
|
6
|
-
export * from "./lib/Fields.js";
|
|
7
|
-
export * from "./lib/Formatter.js";
|
|
8
|
-
import { Functions } from "./lib/Functions.js";
|
|
9
|
-
export * from "./lib/Id.js";
|
|
10
|
-
export * from "./lib/Index.js";
|
|
11
|
-
export * from "./lib/Ops.js";
|
|
12
|
-
export * from "./lib/OrderBy.js";
|
|
13
|
-
export * from "./lib/Param.js";
|
|
14
|
-
export * from "./lib/Query.js";
|
|
15
|
-
export * from "./lib/Sanitizer.js";
|
|
16
|
-
export * from "./lib/Schema.js";
|
|
17
|
-
export * from "./lib/Selection.js";
|
|
18
|
-
export * from "./lib/Statement.js";
|
|
19
|
-
export * from "./lib/Table.js";
|
|
20
|
-
export * from "./lib/Target.js";
|
|
21
|
-
export * from "./lib/Update.js";
|
|
22
|
-
export {
|
|
23
|
-
Functions
|
|
24
|
-
};
|
package/dist/src/lib/Column.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// src/lib/Column.ts
|
|
2
|
-
import { ExprData } from "./Expr.js";
|
|
3
|
-
var ColumnType = /* @__PURE__ */ ((ColumnType2) => {
|
|
4
|
-
ColumnType2["String"] = "String";
|
|
5
|
-
ColumnType2["Integer"] = "Integer";
|
|
6
|
-
ColumnType2["Number"] = "Number";
|
|
7
|
-
ColumnType2["Boolean"] = "Boolean";
|
|
8
|
-
ColumnType2["Json"] = "Json";
|
|
9
|
-
return ColumnType2;
|
|
10
|
-
})(ColumnType || {});
|
|
11
|
-
var Column = class {
|
|
12
|
-
constructor(data) {
|
|
13
|
-
this.data = data;
|
|
14
|
-
}
|
|
15
|
-
name(name) {
|
|
16
|
-
return new Column({ ...this.data, name });
|
|
17
|
-
}
|
|
18
|
-
nullable() {
|
|
19
|
-
return new Column({ ...this.data, nullable: true });
|
|
20
|
-
}
|
|
21
|
-
autoIncrement() {
|
|
22
|
-
return new Column({ ...this.data, autoIncrement: true });
|
|
23
|
-
}
|
|
24
|
-
primaryKey() {
|
|
25
|
-
return new Column({ ...this.data, primaryKey: true });
|
|
26
|
-
}
|
|
27
|
-
references(column2) {
|
|
28
|
-
return new Column({ ...this.data, references: ExprData.create(column2) });
|
|
29
|
-
}
|
|
30
|
-
unique() {
|
|
31
|
-
return new Column({ ...this.data, unique: true });
|
|
32
|
-
}
|
|
33
|
-
defaultValue(value) {
|
|
34
|
-
return new Column({ ...this.data, defaultValue: ExprData.create(value) });
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
((Column2) => {
|
|
38
|
-
})(Column || (Column = {}));
|
|
39
|
-
var column = {
|
|
40
|
-
string() {
|
|
41
|
-
return new Column({ type: "String" /* String */ });
|
|
42
|
-
},
|
|
43
|
-
integer() {
|
|
44
|
-
return new Column({ type: "Integer" /* Integer */ });
|
|
45
|
-
},
|
|
46
|
-
number() {
|
|
47
|
-
return new Column({ type: "Number" /* Number */ });
|
|
48
|
-
},
|
|
49
|
-
boolean() {
|
|
50
|
-
return new Column({ type: "Boolean" /* Boolean */ });
|
|
51
|
-
},
|
|
52
|
-
object() {
|
|
53
|
-
return new Column({ type: "Json" /* Json */ });
|
|
54
|
-
},
|
|
55
|
-
array() {
|
|
56
|
-
return new Column({ type: "Json" /* Json */ });
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
export {
|
|
60
|
-
Column,
|
|
61
|
-
ColumnType,
|
|
62
|
-
column
|
|
63
|
-
};
|