rado 0.1.35 → 0.1.37
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/Cursor.d.ts +18 -12
- package/dist/lib/Cursor.js +49 -27
- package/dist/lib/Driver.d.ts +1 -0
- package/dist/lib/Formatter.d.ts +8 -0
- package/dist/lib/Formatter.js +2 -0
- package/dist/lib/Table.d.ts +1 -1
- package/dist/lib/Table.js +1 -1
- package/dist/sqlite/SqliteFormatter.js +13 -10
- package/dist/sqlite/SqliteFunctions.d.ts +4 -0
- package/package.json +1 -1
package/dist/lib/Cursor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Driver } from './Driver';
|
|
1
2
|
import { EV, Expr } from './Expr';
|
|
2
3
|
import { OrderBy } from './OrderBy';
|
|
3
4
|
import { Query } from './Query';
|
|
@@ -10,26 +11,27 @@ export declare class Cursor<T> {
|
|
|
10
11
|
constructor(query: Query<T>);
|
|
11
12
|
static all(strings: TemplateStringsArray, ...params: Array<any>): Cursor<any>;
|
|
12
13
|
query(): Query<T>;
|
|
14
|
+
run(driver: Driver.Sync): T;
|
|
15
|
+
run(driver: Driver.Async): Promise<T>;
|
|
13
16
|
toJSON(): Query<T>;
|
|
14
17
|
}
|
|
15
18
|
export declare namespace Cursor {
|
|
16
|
-
class
|
|
17
|
-
take(limit: number | undefined): Limitable<T>;
|
|
18
|
-
skip(offset: number | undefined): Limitable<T>;
|
|
19
|
-
}
|
|
20
|
-
class Filterable<T> extends Limitable<T> {
|
|
21
|
-
where(...where: Array<EV<boolean>>): Filterable<T>;
|
|
22
|
-
}
|
|
23
|
-
class Delete extends Filterable<{
|
|
19
|
+
class Delete extends Cursor<{
|
|
24
20
|
rowsAffected: number;
|
|
25
21
|
}> {
|
|
26
22
|
query(): Query.Delete;
|
|
23
|
+
where(...where: Array<EV<boolean>>): Delete;
|
|
24
|
+
take(limit: number | undefined): Delete;
|
|
25
|
+
skip(offset: number | undefined): Delete;
|
|
27
26
|
}
|
|
28
|
-
class Update<T> extends
|
|
27
|
+
class Update<T> extends Cursor<{
|
|
29
28
|
rowsAffected: number;
|
|
30
29
|
}> {
|
|
31
30
|
query: () => Query.Update;
|
|
32
31
|
set(set: UpdateSet<T>): Update<T>;
|
|
32
|
+
where(...where: Array<EV<boolean>>): Update<T>;
|
|
33
|
+
take(limit: number | undefined): Update<T>;
|
|
34
|
+
skip(offset: number | undefined): Update<T>;
|
|
33
35
|
}
|
|
34
36
|
class InsertValuesReturning<T> extends Cursor<T> {
|
|
35
37
|
}
|
|
@@ -44,7 +46,7 @@ export declare namespace Cursor {
|
|
|
44
46
|
constructor(into: Schema);
|
|
45
47
|
values(...data: Array<Table.Insert<T>>): InsertValues;
|
|
46
48
|
}
|
|
47
|
-
class
|
|
49
|
+
class CreateTable extends Cursor<void> {
|
|
48
50
|
protected table: Schema;
|
|
49
51
|
constructor(table: Schema);
|
|
50
52
|
}
|
|
@@ -52,7 +54,7 @@ export declare namespace Cursor {
|
|
|
52
54
|
protected queries: Array<Query>;
|
|
53
55
|
constructor(queries: Array<Query>);
|
|
54
56
|
}
|
|
55
|
-
class SelectMultiple<T> extends
|
|
57
|
+
class SelectMultiple<T> extends Cursor<Array<T>> {
|
|
56
58
|
query(): Query.Select;
|
|
57
59
|
leftJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectMultiple<T>;
|
|
58
60
|
innerJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectMultiple<T>;
|
|
@@ -63,9 +65,11 @@ export declare namespace Cursor {
|
|
|
63
65
|
first(): SelectSingle<T | undefined>;
|
|
64
66
|
sure(): SelectSingle<T>;
|
|
65
67
|
where(...where: Array<EV<boolean>>): SelectMultiple<T>;
|
|
68
|
+
take(limit: number | undefined): SelectMultiple<T>;
|
|
69
|
+
skip(offset: number | undefined): SelectMultiple<T>;
|
|
66
70
|
toExpr(): Expr<T>;
|
|
67
71
|
}
|
|
68
|
-
class SelectSingle<T> extends
|
|
72
|
+
class SelectSingle<T> extends Cursor<T> {
|
|
69
73
|
query(): Query.Select;
|
|
70
74
|
leftJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectSingle<T>;
|
|
71
75
|
innerJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectSingle<T>;
|
|
@@ -73,6 +77,8 @@ export declare namespace Cursor {
|
|
|
73
77
|
orderBy(...orderBy: Array<OrderBy>): SelectSingle<T>;
|
|
74
78
|
groupBy(...groupBy: Array<Expr<any>>): SelectSingle<T>;
|
|
75
79
|
where(...where: Array<EV<boolean>>): SelectSingle<T>;
|
|
80
|
+
take(limit: number | undefined): SelectSingle<T>;
|
|
81
|
+
skip(offset: number | undefined): SelectSingle<T>;
|
|
76
82
|
all(): SelectMultiple<T>;
|
|
77
83
|
toExpr(): Expr<T>;
|
|
78
84
|
}
|
package/dist/lib/Cursor.js
CHANGED
|
@@ -21,41 +21,51 @@ var Cursor = class {
|
|
|
21
21
|
query() {
|
|
22
22
|
throw new Error("Not implemented");
|
|
23
23
|
}
|
|
24
|
+
run(driver) {
|
|
25
|
+
return driver.executeQuery(this.query());
|
|
26
|
+
}
|
|
24
27
|
toJSON() {
|
|
25
28
|
return this.query();
|
|
26
29
|
}
|
|
27
30
|
};
|
|
31
|
+
function addWhere(query, where) {
|
|
32
|
+
const conditions = where.slice();
|
|
33
|
+
if (query.where)
|
|
34
|
+
conditions.push(query.where);
|
|
35
|
+
return {
|
|
36
|
+
...query,
|
|
37
|
+
where: Expr.and(...conditions).expr
|
|
38
|
+
};
|
|
39
|
+
}
|
|
28
40
|
((Cursor2) => {
|
|
29
|
-
class
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
skip(offset) {
|
|
34
|
-
return new Limitable({ ...this.query(), offset });
|
|
41
|
+
class Delete extends Cursor2 {
|
|
42
|
+
query() {
|
|
43
|
+
return super.query();
|
|
35
44
|
}
|
|
36
|
-
}
|
|
37
|
-
Cursor2.Limitable = Limitable;
|
|
38
|
-
class Filterable extends Limitable {
|
|
39
45
|
where(...where) {
|
|
40
|
-
|
|
41
|
-
const query = this.query();
|
|
42
|
-
return new Filterable({
|
|
43
|
-
...query,
|
|
44
|
-
where: (query.where ? condition.and(new Expr(query.where)) : condition).expr
|
|
45
|
-
});
|
|
46
|
+
return new Delete(addWhere(this.query(), where));
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
48
|
+
take(limit) {
|
|
49
|
+
return new Delete({ ...this.query(), limit });
|
|
50
|
+
}
|
|
51
|
+
skip(offset) {
|
|
52
|
+
return new Delete({ ...this.query(), offset });
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
Cursor2.Delete = Delete;
|
|
55
|
-
class Update extends
|
|
56
|
+
class Update extends Cursor2 {
|
|
56
57
|
set(set) {
|
|
57
58
|
return new Update({ ...this.query(), set });
|
|
58
59
|
}
|
|
60
|
+
where(...where) {
|
|
61
|
+
return new Update(addWhere(this.query(), where));
|
|
62
|
+
}
|
|
63
|
+
take(limit) {
|
|
64
|
+
return new Update({ ...this.query(), limit });
|
|
65
|
+
}
|
|
66
|
+
skip(offset) {
|
|
67
|
+
return new Update({ ...this.query(), offset });
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
Cursor2.Update = Update;
|
|
61
71
|
class InsertValuesReturning extends Cursor2 {
|
|
@@ -81,13 +91,13 @@ var Cursor = class {
|
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
Cursor2.Insert = Insert;
|
|
84
|
-
class
|
|
94
|
+
class CreateTable extends Cursor2 {
|
|
85
95
|
constructor(table) {
|
|
86
96
|
super(Schema.create(table));
|
|
87
97
|
this.table = table;
|
|
88
98
|
}
|
|
89
99
|
}
|
|
90
|
-
Cursor2.
|
|
100
|
+
Cursor2.CreateTable = CreateTable;
|
|
91
101
|
class Batch extends Cursor2 {
|
|
92
102
|
constructor(queries) {
|
|
93
103
|
super(Query.Batch({ queries }));
|
|
@@ -95,7 +105,7 @@ var Cursor = class {
|
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
Cursor2.Batch = Batch;
|
|
98
|
-
class SelectMultiple extends
|
|
108
|
+
class SelectMultiple extends Cursor2 {
|
|
99
109
|
query() {
|
|
100
110
|
return super.query();
|
|
101
111
|
}
|
|
@@ -161,14 +171,20 @@ var Cursor = class {
|
|
|
161
171
|
});
|
|
162
172
|
}
|
|
163
173
|
where(...where) {
|
|
164
|
-
return new SelectMultiple(
|
|
174
|
+
return new SelectMultiple(addWhere(this.query(), where));
|
|
175
|
+
}
|
|
176
|
+
take(limit) {
|
|
177
|
+
return new SelectMultiple({ ...this.query(), limit });
|
|
178
|
+
}
|
|
179
|
+
skip(offset) {
|
|
180
|
+
return new SelectMultiple({ ...this.query(), offset });
|
|
165
181
|
}
|
|
166
182
|
toExpr() {
|
|
167
183
|
return new Expr(ExprData.Query(this.query()));
|
|
168
184
|
}
|
|
169
185
|
}
|
|
170
186
|
Cursor2.SelectMultiple = SelectMultiple;
|
|
171
|
-
class SelectSingle extends
|
|
187
|
+
class SelectSingle extends Cursor2 {
|
|
172
188
|
query() {
|
|
173
189
|
return super.query();
|
|
174
190
|
}
|
|
@@ -215,7 +231,13 @@ var Cursor = class {
|
|
|
215
231
|
});
|
|
216
232
|
}
|
|
217
233
|
where(...where) {
|
|
218
|
-
return new SelectSingle(
|
|
234
|
+
return new SelectSingle(addWhere(this.query(), where));
|
|
235
|
+
}
|
|
236
|
+
take(limit) {
|
|
237
|
+
return new SelectSingle({ ...this.query(), limit });
|
|
238
|
+
}
|
|
239
|
+
skip(offset) {
|
|
240
|
+
return new SelectSingle({ ...this.query(), offset });
|
|
219
241
|
}
|
|
220
242
|
all() {
|
|
221
243
|
return new SelectMultiple({ ...this.query(), singleResult: false });
|
package/dist/lib/Driver.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ interface AsyncPreparedStatement {
|
|
|
90
90
|
get<T>(params?: Array<any>): Promise<T>;
|
|
91
91
|
execute(params?: Array<any>): Promise<void>;
|
|
92
92
|
}
|
|
93
|
+
export type Driver = SyncDriver | AsyncDriver;
|
|
93
94
|
export declare namespace Driver {
|
|
94
95
|
type Sync = SyncDriver;
|
|
95
96
|
const Sync: typeof SyncDriver;
|
package/dist/lib/Formatter.d.ts
CHANGED
|
@@ -8,7 +8,15 @@ import { Target } from './Target';
|
|
|
8
8
|
export interface FormatContext {
|
|
9
9
|
stmt: Statement;
|
|
10
10
|
nameResult?: string;
|
|
11
|
+
/** Skip prefixing fields with their table name */
|
|
11
12
|
skipTableName?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* In SQLite table names are used as expressions in the FTS5 plugin.
|
|
15
|
+
* To distinguish between formatting a row of the table and just the table name
|
|
16
|
+
* this flag can be used.
|
|
17
|
+
**/
|
|
18
|
+
tableAsExpr?: boolean;
|
|
19
|
+
/** Inline all parameters */
|
|
12
20
|
forceInline?: boolean;
|
|
13
21
|
formatAsJson?: boolean;
|
|
14
22
|
formatSubject?: (mkSubject: () => void) => void;
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -574,6 +574,8 @@ var Formatter = class {
|
|
|
574
574
|
const table = Target.source(expr.target);
|
|
575
575
|
if (!table)
|
|
576
576
|
throw new Error(`Cannot select empty target`);
|
|
577
|
+
if (ctx.tableAsExpr)
|
|
578
|
+
return stmt.identifier(table.alias || table.name);
|
|
577
579
|
return this.formatExpr(
|
|
578
580
|
ctx,
|
|
579
581
|
ExprData.Record(
|
package/dist/lib/Table.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Table<T> extends Cursor.SelectMultiple<Table.Normalize<T>>
|
|
|
16
16
|
insertAll(data: Array<Table.Insert<T>>): Cursor.InsertValues;
|
|
17
17
|
set(data: Update<Table.Normalize<T>>): Cursor.Update<Table.Normalize<T>>;
|
|
18
18
|
delete(): Cursor.Delete;
|
|
19
|
-
createTable(): Cursor.
|
|
19
|
+
createTable(): Cursor.CreateTable;
|
|
20
20
|
as(alias: string): this;
|
|
21
21
|
alias(): Record<string, this>;
|
|
22
22
|
get(name: string): Expr<any>;
|
package/dist/lib/Table.js
CHANGED
|
@@ -59,7 +59,7 @@ var Table = class extends Cursor.SelectMultiple {
|
|
|
59
59
|
return new Cursor.Delete(Query.Delete({ table: this.schema() }));
|
|
60
60
|
}
|
|
61
61
|
createTable() {
|
|
62
|
-
return new Cursor.
|
|
62
|
+
return new Cursor.CreateTable(this.schema());
|
|
63
63
|
}
|
|
64
64
|
as(alias) {
|
|
65
65
|
return new Table({ ...this.schema(), alias });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/sqlite/SqliteFormatter.ts
|
|
2
2
|
import { ExprType } from "../lib/Expr.js";
|
|
3
3
|
import { Formatter } from "../lib/Formatter.js";
|
|
4
|
-
import { TargetType } from "../lib/Target.js";
|
|
5
4
|
function escapeWithin(input, outer) {
|
|
6
5
|
let buf = outer;
|
|
7
6
|
for (const char of input) {
|
|
@@ -52,15 +51,19 @@ var SqliteFormatter = class extends Formatter {
|
|
|
52
51
|
const { stmt } = ctx;
|
|
53
52
|
switch (expr.type) {
|
|
54
53
|
case ExprType.Call:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
switch (expr.method) {
|
|
55
|
+
case "match":
|
|
56
|
+
const [from, query] = expr.params;
|
|
57
|
+
this.formatExprValue({ ...ctx, tableAsExpr: true }, from);
|
|
58
|
+
stmt.raw(" MATCH ");
|
|
59
|
+
this.formatExprValue(ctx, query);
|
|
60
|
+
return stmt;
|
|
61
|
+
case "highlight":
|
|
62
|
+
case "snippet":
|
|
63
|
+
stmt.identifier(expr.method);
|
|
64
|
+
for (const param of stmt.call(expr.params))
|
|
65
|
+
this.formatExprValue({ ...ctx, tableAsExpr: true }, param);
|
|
66
|
+
return stmt;
|
|
64
67
|
}
|
|
65
68
|
default:
|
|
66
69
|
return super.formatExpr(ctx, expr);
|
|
@@ -13,6 +13,10 @@ export type SqliteFunctions = {
|
|
|
13
13
|
exists(cursor: Cursor<any>): Expr<boolean>;
|
|
14
14
|
/** Use the match operator for the FTS5 module */
|
|
15
15
|
match(table: Table<any>, searchTerm: EV<string>): Expr<boolean>;
|
|
16
|
+
/** The highlight() function returns a copy of the text from a specified column of the current row with extra markup text inserted to mark the start and end of phrase matches. */
|
|
17
|
+
highlight(table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>): Expr<string>;
|
|
18
|
+
/** The snippet() function is similar to highlight(), except that instead of returning entire column values, it automatically selects and extracts a short fragment of document text to process and return. */
|
|
19
|
+
snippet(table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>, snip: EV<string>, maxTokens: EV<number>): Expr<string>;
|
|
16
20
|
cast(x: EV<any>, type: 'text'): Expr<string>;
|
|
17
21
|
cast(x: EV<any>, type: 'real'): Expr<number>;
|
|
18
22
|
cast(x: EV<any>, type: 'integer'): Expr<number>;
|