rado 0.1.23 → 0.1.24
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 +1 -1
- package/dist/driver/better-sqlite3.d.ts +17 -17
- package/dist/driver/sql.js.d.ts +17 -17
- package/dist/driver/sqlite3.d.ts +20 -20
- package/dist/index.d.ts +20 -20
- package/dist/lib/Column.d.ts +57 -57
- package/dist/lib/Cursor.d.ts +77 -77
- package/dist/lib/Driver.d.ts +89 -89
- package/dist/lib/Expr.d.ts +154 -154
- package/dist/lib/Fields.d.ts +13 -13
- package/dist/lib/Formatter.d.ts +56 -56
- package/dist/lib/Functions.d.ts +7 -7
- package/dist/lib/Id.d.ts +3 -3
- package/dist/lib/Index.d.ts +17 -17
- package/dist/lib/Ops.d.ts +8 -8
- package/dist/lib/OrderBy.d.ts +9 -9
- package/dist/lib/Param.d.ts +15 -15
- package/dist/lib/Query.d.ts +108 -108
- package/dist/lib/Sanitizer.d.ts +4 -4
- package/dist/lib/Schema.d.ts +18 -18
- package/dist/lib/Schema.js +2 -2
- package/dist/lib/Selection.d.ts +20 -20
- package/dist/lib/Statement.d.ts +61 -61
- package/dist/lib/Table.d.ts +58 -58
- package/dist/lib/Target.d.ts +30 -30
- package/dist/lib/Update.d.ts +4 -4
- package/dist/sqlite/SqliteFormatter.d.ts +11 -11
- package/dist/sqlite/SqliteFunctions.d.ts +156 -156
- package/dist/sqlite/SqliteSchema.d.ts +24 -24
- package/dist/sqlite.d.ts +2 -2
- package/package.json +47 -47
- package/dist/Column.d.ts +0 -41
- package/dist/Column.js +0 -58
- package/dist/Cursor.d.ts +0 -77
- package/dist/Cursor.js +0 -211
- package/dist/Driver.d.ts +0 -72
- package/dist/Driver.js +0 -145
- package/dist/Expr.d.ts +0 -149
- package/dist/Expr.js +0 -284
- package/dist/Fields.d.ts +0 -9
- package/dist/Fields.js +0 -0
- package/dist/Formatter.d.ts +0 -50
- package/dist/Formatter.js +0 -453
- package/dist/Functions.d.ts +0 -8
- package/dist/Functions.js +0 -11
- package/dist/Key.d.ts +0 -5
- package/dist/Ops.d.ts +0 -8
- package/dist/Ops.js +0 -46
- package/dist/OrderBy.d.ts +0 -9
- package/dist/OrderBy.js +0 -9
- package/dist/Param.d.ts +0 -15
- package/dist/Param.js +0 -18
- package/dist/Query.d.ts +0 -94
- package/dist/Query.js +0 -57
- package/dist/Sanitizer.d.ts +0 -4
- package/dist/Sanitizer.js +0 -0
- package/dist/Schema.d.ts +0 -10
- package/dist/Selection.d.ts +0 -18
- package/dist/Selection.js +0 -0
- package/dist/Statement.d.ts +0 -57
- package/dist/Statement.js +0 -184
- package/dist/Table.d.ts +0 -47
- package/dist/Table.js +0 -82
- package/dist/Target.d.ts +0 -30
- package/dist/Target.js +0 -37
- package/dist/Update.d.ts +0 -4
- package/dist/Update.js +0 -0
- package/dist/sqlite/index.d.ts +0 -2
- package/dist/sqlite/index.js +0 -3
package/dist/Cursor.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { EV, Expr } from './Expr';
|
|
2
|
-
import { OrderBy } from './OrderBy';
|
|
3
|
-
import { Query } from './Query';
|
|
4
|
-
import { Schema } from './Schema';
|
|
5
|
-
import { Selection } from './Selection';
|
|
6
|
-
import { Table } from './Table';
|
|
7
|
-
import { Update as UpdateSet } from './Update';
|
|
8
|
-
export declare class Cursor<T> {
|
|
9
|
-
/** @internal */
|
|
10
|
-
protected __cursorType: T;
|
|
11
|
-
constructor(query: Query<T>);
|
|
12
|
-
query(): Query<T>;
|
|
13
|
-
toJSON(): Query<T>;
|
|
14
|
-
}
|
|
15
|
-
export declare namespace Cursor {
|
|
16
|
-
class Limitable<T> extends Cursor<T> {
|
|
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<T> extends Filterable<{
|
|
24
|
-
rowsAffected: number;
|
|
25
|
-
}> {
|
|
26
|
-
query(): Query.Delete;
|
|
27
|
-
}
|
|
28
|
-
class Update<T> extends Filterable<{
|
|
29
|
-
rowsAffected: number;
|
|
30
|
-
}> {
|
|
31
|
-
query: () => Query.Update;
|
|
32
|
-
set(set: UpdateSet<T>): Update<T>;
|
|
33
|
-
}
|
|
34
|
-
class InsertValuesReturning<T> extends Cursor<T> {
|
|
35
|
-
}
|
|
36
|
-
class InsertValues extends Cursor<{
|
|
37
|
-
rowsAffected: number;
|
|
38
|
-
}> {
|
|
39
|
-
query(): Query.Insert;
|
|
40
|
-
returning<X extends Selection>(selection: X): InsertValuesReturning<Selection.Infer<X>>;
|
|
41
|
-
}
|
|
42
|
-
class Insert<T> {
|
|
43
|
-
protected into: Schema;
|
|
44
|
-
constructor(into: Schema);
|
|
45
|
-
values(...data: Array<Table.Insert<T>>): InsertValues;
|
|
46
|
-
}
|
|
47
|
-
class Create extends Cursor<void> {
|
|
48
|
-
protected table: Schema;
|
|
49
|
-
constructor(table: Schema);
|
|
50
|
-
}
|
|
51
|
-
class Batch<T = void> extends Cursor<T> {
|
|
52
|
-
protected queries: Array<Query>;
|
|
53
|
-
constructor(queries: Array<Query>);
|
|
54
|
-
}
|
|
55
|
-
class SelectMultiple<T> extends Filterable<Array<T>> {
|
|
56
|
-
query(): Query.Select;
|
|
57
|
-
leftJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectMultiple<T>;
|
|
58
|
-
innerJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectMultiple<T>;
|
|
59
|
-
select<X extends Selection>(selection: X): SelectMultiple<Selection.Infer<X>>;
|
|
60
|
-
count(): SelectSingle<number>;
|
|
61
|
-
orderBy(...orderBy: Array<OrderBy>): SelectMultiple<T>;
|
|
62
|
-
groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<T>;
|
|
63
|
-
first(): SelectSingle<T | undefined>;
|
|
64
|
-
where(...where: Array<EV<boolean>>): SelectMultiple<T>;
|
|
65
|
-
toExpr(): Expr<T>;
|
|
66
|
-
}
|
|
67
|
-
class SelectSingle<T> extends Filterable<T> {
|
|
68
|
-
query(): Query.Select;
|
|
69
|
-
leftJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectSingle<T>;
|
|
70
|
-
innerJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectSingle<T>;
|
|
71
|
-
select<X extends Selection>(selection: X): SelectSingle<Selection.Infer<X>>;
|
|
72
|
-
orderBy(...orderBy: Array<OrderBy>): SelectSingle<T>;
|
|
73
|
-
groupBy(...groupBy: Array<Expr<any>>): SelectSingle<T>;
|
|
74
|
-
where(...where: Array<EV<boolean>>): SelectSingle<T>;
|
|
75
|
-
toExpr(): Expr<T>;
|
|
76
|
-
}
|
|
77
|
-
}
|
package/dist/Cursor.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
// src/Cursor.ts
|
|
2
|
-
import { Expr, ExprData } from "./Expr";
|
|
3
|
-
import { Functions } from "./Functions";
|
|
4
|
-
import { Query } from "./Query";
|
|
5
|
-
import { Target } from "./Target";
|
|
6
|
-
var Cursor = class {
|
|
7
|
-
constructor(query) {
|
|
8
|
-
Object.defineProperty(this, "query", {
|
|
9
|
-
enumerable: false,
|
|
10
|
-
value: () => query
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
query() {
|
|
14
|
-
throw new Error("Not implemented");
|
|
15
|
-
}
|
|
16
|
-
toJSON() {
|
|
17
|
-
return this.query();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
((Cursor2) => {
|
|
21
|
-
class Limitable extends Cursor2 {
|
|
22
|
-
take(limit) {
|
|
23
|
-
return new Limitable({ ...this.query(), limit });
|
|
24
|
-
}
|
|
25
|
-
skip(offset) {
|
|
26
|
-
return new Limitable({ ...this.query(), offset });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
Cursor2.Limitable = Limitable;
|
|
30
|
-
class Filterable extends Limitable {
|
|
31
|
-
where(...where) {
|
|
32
|
-
const condition = Expr.and(...where);
|
|
33
|
-
const query = this.query();
|
|
34
|
-
return new Filterable({
|
|
35
|
-
...query,
|
|
36
|
-
where: (query.where ? condition.and(new Expr(query.where)) : condition).expr
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
Cursor2.Filterable = Filterable;
|
|
41
|
-
class Delete extends Filterable {
|
|
42
|
-
query() {
|
|
43
|
-
return super.query();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
Cursor2.Delete = Delete;
|
|
47
|
-
class Update extends Filterable {
|
|
48
|
-
set(set) {
|
|
49
|
-
return new Update({ ...this.query(), set });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
Cursor2.Update = Update;
|
|
53
|
-
class InsertValuesReturning extends Cursor2 {
|
|
54
|
-
}
|
|
55
|
-
Cursor2.InsertValuesReturning = InsertValuesReturning;
|
|
56
|
-
class InsertValues extends Cursor2 {
|
|
57
|
-
query() {
|
|
58
|
-
return super.query();
|
|
59
|
-
}
|
|
60
|
-
returning(selection) {
|
|
61
|
-
return new InsertValuesReturning(
|
|
62
|
-
Query.Insert({ ...this.query(), selection: ExprData.create(selection) })
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
Cursor2.InsertValues = InsertValues;
|
|
67
|
-
class Insert {
|
|
68
|
-
constructor(into) {
|
|
69
|
-
this.into = into;
|
|
70
|
-
}
|
|
71
|
-
values(...data) {
|
|
72
|
-
return new InsertValues(Query.Insert({ into: this.into, data }));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
Cursor2.Insert = Insert;
|
|
76
|
-
class Create extends Cursor2 {
|
|
77
|
-
constructor(table) {
|
|
78
|
-
super(Query.CreateTable({ table, ifNotExists: true }));
|
|
79
|
-
this.table = table;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
Cursor2.Create = Create;
|
|
83
|
-
class Batch extends Cursor2 {
|
|
84
|
-
constructor(queries) {
|
|
85
|
-
super(Query.Batch({ queries }));
|
|
86
|
-
this.queries = queries;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
Cursor2.Batch = Batch;
|
|
90
|
-
class SelectMultiple extends Filterable {
|
|
91
|
-
query() {
|
|
92
|
-
return super.query();
|
|
93
|
-
}
|
|
94
|
-
leftJoin(that, ...on) {
|
|
95
|
-
const query = this.query();
|
|
96
|
-
return new SelectMultiple({
|
|
97
|
-
...query,
|
|
98
|
-
from: Target.Join(
|
|
99
|
-
query.from,
|
|
100
|
-
Target.Table(that.data()),
|
|
101
|
-
"left",
|
|
102
|
-
Expr.and(...on).expr
|
|
103
|
-
)
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
innerJoin(that, ...on) {
|
|
107
|
-
const query = this.query();
|
|
108
|
-
return new SelectMultiple({
|
|
109
|
-
...query,
|
|
110
|
-
from: Target.Join(
|
|
111
|
-
query.from,
|
|
112
|
-
Target.Table(that.data()),
|
|
113
|
-
"inner",
|
|
114
|
-
Expr.and(...on).expr
|
|
115
|
-
)
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
select(selection) {
|
|
119
|
-
return new SelectMultiple({
|
|
120
|
-
...this.query(),
|
|
121
|
-
selection: ExprData.create(selection)
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
count() {
|
|
125
|
-
return new SelectSingle({
|
|
126
|
-
...this.query(),
|
|
127
|
-
selection: Functions.count().expr,
|
|
128
|
-
singleResult: true
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
orderBy(...orderBy) {
|
|
132
|
-
return new SelectMultiple({
|
|
133
|
-
...this.query(),
|
|
134
|
-
orderBy
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
groupBy(...groupBy) {
|
|
138
|
-
return new SelectMultiple({
|
|
139
|
-
...this.query(),
|
|
140
|
-
groupBy: groupBy.map(ExprData.create)
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
first() {
|
|
144
|
-
return new SelectSingle({ ...this.query(), singleResult: true });
|
|
145
|
-
}
|
|
146
|
-
where(...where) {
|
|
147
|
-
return new SelectMultiple(super.where(...where).query());
|
|
148
|
-
}
|
|
149
|
-
toExpr() {
|
|
150
|
-
return new Expr(ExprData.Query(this.query()));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
Cursor2.SelectMultiple = SelectMultiple;
|
|
154
|
-
class SelectSingle extends Filterable {
|
|
155
|
-
query() {
|
|
156
|
-
return super.query();
|
|
157
|
-
}
|
|
158
|
-
leftJoin(that, ...on) {
|
|
159
|
-
const query = this.query();
|
|
160
|
-
return new SelectSingle({
|
|
161
|
-
...query,
|
|
162
|
-
from: Target.Join(
|
|
163
|
-
query.from,
|
|
164
|
-
Target.Table(that.data()),
|
|
165
|
-
"left",
|
|
166
|
-
Expr.and(...on).expr
|
|
167
|
-
)
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
innerJoin(that, ...on) {
|
|
171
|
-
const query = this.query();
|
|
172
|
-
return new SelectSingle({
|
|
173
|
-
...query,
|
|
174
|
-
from: Target.Join(
|
|
175
|
-
query.from,
|
|
176
|
-
Target.Table(that.data()),
|
|
177
|
-
"inner",
|
|
178
|
-
Expr.and(...on).expr
|
|
179
|
-
)
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
select(selection) {
|
|
183
|
-
return new SelectSingle({
|
|
184
|
-
...this.query(),
|
|
185
|
-
selection: ExprData.create(selection)
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
orderBy(...orderBy) {
|
|
189
|
-
return new SelectSingle({
|
|
190
|
-
...this.query(),
|
|
191
|
-
orderBy
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
groupBy(...groupBy) {
|
|
195
|
-
return new SelectSingle({
|
|
196
|
-
...this.query(),
|
|
197
|
-
groupBy: groupBy.map(ExprData.create)
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
where(...where) {
|
|
201
|
-
return new SelectSingle(super.where(...where).query());
|
|
202
|
-
}
|
|
203
|
-
toExpr() {
|
|
204
|
-
return new Expr(ExprData.Query(this.query()));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
Cursor2.SelectSingle = SelectSingle;
|
|
208
|
-
})(Cursor || (Cursor = {}));
|
|
209
|
-
export {
|
|
210
|
-
Cursor
|
|
211
|
-
};
|
package/dist/Driver.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Cursor } from './Cursor';
|
|
2
|
-
import { Formatter } from './Formatter';
|
|
3
|
-
import { Query } from './Query';
|
|
4
|
-
import { Schema } from './Schema';
|
|
5
|
-
import { Statement } from './Statement';
|
|
6
|
-
declare class Callable extends Function {
|
|
7
|
-
constructor(fn: Function);
|
|
8
|
-
}
|
|
9
|
-
declare abstract class DriverBase extends Callable {
|
|
10
|
-
formatter: Formatter;
|
|
11
|
-
constructor(formatter: Formatter);
|
|
12
|
-
all(strings: TemplateStringsArray, ...params: Array<any>): any;
|
|
13
|
-
get(strings: TemplateStringsArray, ...params: Array<any>): any;
|
|
14
|
-
executeTemplate(expectedReturn: Query.RawReturn, strings: TemplateStringsArray, ...params: Array<any>): any;
|
|
15
|
-
abstract executeQuery(query: Query<any>): any;
|
|
16
|
-
}
|
|
17
|
-
export declare namespace Driver {
|
|
18
|
-
export interface Sync {
|
|
19
|
-
<T>(query: Cursor<T>): T;
|
|
20
|
-
(strings: TemplateStringsArray, ...values: any[]): any;
|
|
21
|
-
}
|
|
22
|
-
export abstract class Sync extends DriverBase {
|
|
23
|
-
transactionId: number;
|
|
24
|
-
abstract rows(stmt: Statement.Compiled): Array<object>;
|
|
25
|
-
abstract values(stmt: Statement.Compiled): Array<Array<any>>;
|
|
26
|
-
abstract execute(stmt: Statement.Compiled): void;
|
|
27
|
-
abstract mutate(stmt: Statement.Compiled): {
|
|
28
|
-
rowsAffected: number;
|
|
29
|
-
};
|
|
30
|
-
abstract schema(tableName: string): Schema;
|
|
31
|
-
executeQuery<T>(query: Query<T>): T;
|
|
32
|
-
all<T>(strings: TemplateStringsArray, ...params: Array<any>): Array<T>;
|
|
33
|
-
get<T>(strings: TemplateStringsArray, ...params: Array<any>): T;
|
|
34
|
-
transaction<T>(run: (query: Sync) => T): T;
|
|
35
|
-
toAsync(): SyncWrapper;
|
|
36
|
-
}
|
|
37
|
-
export interface Async {
|
|
38
|
-
<T>(query: Cursor<T>): Promise<T>;
|
|
39
|
-
(strings: TemplateStringsArray, ...values: any[]): Promise<any>;
|
|
40
|
-
}
|
|
41
|
-
export abstract class Async extends DriverBase {
|
|
42
|
-
transactionId: number;
|
|
43
|
-
abstract isolate(): [connection: Async, release: () => Promise<void>];
|
|
44
|
-
abstract rows(stmt: Statement.Compiled): Promise<Array<object>>;
|
|
45
|
-
abstract values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
|
|
46
|
-
abstract execute(stmt: Statement.Compiled): Promise<void>;
|
|
47
|
-
abstract mutate(stmt: Statement.Compiled): Promise<{
|
|
48
|
-
rowsAffected: number;
|
|
49
|
-
}>;
|
|
50
|
-
abstract schema(tableName: string): Promise<Schema>;
|
|
51
|
-
executeQuery<T>(query: Query<T>): Promise<T>;
|
|
52
|
-
all<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<Array<T>>;
|
|
53
|
-
get<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<T>;
|
|
54
|
-
transaction<T>(run: (query: Async) => T): Promise<T>;
|
|
55
|
-
}
|
|
56
|
-
class SyncWrapper extends Async {
|
|
57
|
-
private sync;
|
|
58
|
-
lock: Promise<void> | undefined;
|
|
59
|
-
constructor(sync: Sync);
|
|
60
|
-
executeQuery<T>(query: Query<T>): Promise<T>;
|
|
61
|
-
rows(stmt: Statement.Compiled): Promise<Array<object>>;
|
|
62
|
-
values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
|
|
63
|
-
execute(stmt: Statement.Compiled): Promise<void>;
|
|
64
|
-
mutate(stmt: Statement.Compiled): Promise<{
|
|
65
|
-
rowsAffected: number;
|
|
66
|
-
}>;
|
|
67
|
-
schema(tableName: string): Promise<Schema>;
|
|
68
|
-
isolate(): [connection: Async, release: () => Promise<void>];
|
|
69
|
-
}
|
|
70
|
-
export {};
|
|
71
|
-
}
|
|
72
|
-
export {};
|
package/dist/Driver.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// src/Driver.ts
|
|
2
|
-
import { Cursor } from "./Cursor";
|
|
3
|
-
import { Query, QueryType } from "./Query";
|
|
4
|
-
var Callable = class extends Function {
|
|
5
|
-
constructor(fn) {
|
|
6
|
-
super();
|
|
7
|
-
return new Proxy(this, {
|
|
8
|
-
apply(_, thisArg, input) {
|
|
9
|
-
return fn.apply(thisArg, input);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var DriverBase = class extends Callable {
|
|
15
|
-
constructor() {
|
|
16
|
-
super((...args) => {
|
|
17
|
-
const [input, ...rest] = args;
|
|
18
|
-
if (input instanceof Cursor)
|
|
19
|
-
return this.executeQuery(input.query());
|
|
20
|
-
return this.executeTemplate(void 0, input, ...rest);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
all(strings, ...params) {
|
|
24
|
-
return this.executeTemplate("rows", strings, ...params);
|
|
25
|
-
}
|
|
26
|
-
get(strings, ...params) {
|
|
27
|
-
return this.executeTemplate("row", strings, ...params);
|
|
28
|
-
}
|
|
29
|
-
executeTemplate(expectedReturn, strings, ...params) {
|
|
30
|
-
if (strings.some((chunk) => chunk.includes("?")))
|
|
31
|
-
throw new TypeError("SQL injection hazard");
|
|
32
|
-
return this.executeQuery(Query.Raw({ strings, params, expectedReturn }));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var Driver;
|
|
36
|
-
((Driver2) => {
|
|
37
|
-
class Sync extends DriverBase {
|
|
38
|
-
transactionId = 0;
|
|
39
|
-
executeQuery(query) {
|
|
40
|
-
switch (query.type) {
|
|
41
|
-
case QueryType.Batch:
|
|
42
|
-
let result;
|
|
43
|
-
const stmts = query.queries;
|
|
44
|
-
for (const query2 of stmts)
|
|
45
|
-
result = this.execute(query2);
|
|
46
|
-
return result;
|
|
47
|
-
default:
|
|
48
|
-
return this.execute(query);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
all(strings, ...params) {
|
|
52
|
-
return super.all(strings, ...params);
|
|
53
|
-
}
|
|
54
|
-
get(strings, ...params) {
|
|
55
|
-
return super.get(strings, ...params);
|
|
56
|
-
}
|
|
57
|
-
transaction(run) {
|
|
58
|
-
const id = `t${this.transactionId++}`;
|
|
59
|
-
this.execute(
|
|
60
|
-
Query.Transaction({ op: Query.TransactionOperation.Begin, id })
|
|
61
|
-
);
|
|
62
|
-
try {
|
|
63
|
-
const res = run(this);
|
|
64
|
-
this.execute(
|
|
65
|
-
Query.Transaction({ op: Query.TransactionOperation.Commit, id })
|
|
66
|
-
);
|
|
67
|
-
return res;
|
|
68
|
-
} catch (e) {
|
|
69
|
-
this.execute(
|
|
70
|
-
Query.Transaction({ op: Query.TransactionOperation.Rollback, id })
|
|
71
|
-
);
|
|
72
|
-
throw e;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
toAsync() {
|
|
76
|
-
return new SyncWrapper(this);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
Driver2.Sync = Sync;
|
|
80
|
-
class Async extends DriverBase {
|
|
81
|
-
transactionId = 0;
|
|
82
|
-
async executeQuery(query) {
|
|
83
|
-
switch (query.type) {
|
|
84
|
-
case QueryType.Batch:
|
|
85
|
-
let result;
|
|
86
|
-
const stmts = query.queries;
|
|
87
|
-
for (const query2 of stmts)
|
|
88
|
-
result = await this.execute(query2);
|
|
89
|
-
return result;
|
|
90
|
-
default:
|
|
91
|
-
return this.execute(query);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
all(strings, ...params) {
|
|
95
|
-
return super.all(strings, ...params);
|
|
96
|
-
}
|
|
97
|
-
get(strings, ...params) {
|
|
98
|
-
return super.get(strings, ...params);
|
|
99
|
-
}
|
|
100
|
-
async transaction(run) {
|
|
101
|
-
const id = `t${this.transactionId++}`;
|
|
102
|
-
const [connection, release] = this.isolate();
|
|
103
|
-
await connection.execute(
|
|
104
|
-
Query.Transaction({ op: Query.TransactionOperation.Begin, id })
|
|
105
|
-
);
|
|
106
|
-
try {
|
|
107
|
-
const res = await run(connection);
|
|
108
|
-
await connection.execute(
|
|
109
|
-
Query.Transaction({ op: Query.TransactionOperation.Commit, id })
|
|
110
|
-
);
|
|
111
|
-
return res;
|
|
112
|
-
} catch (e) {
|
|
113
|
-
await connection.execute(
|
|
114
|
-
Query.Transaction({ op: Query.TransactionOperation.Rollback, id })
|
|
115
|
-
);
|
|
116
|
-
throw e;
|
|
117
|
-
} finally {
|
|
118
|
-
await release();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
Driver2.Async = Async;
|
|
123
|
-
class SyncWrapper extends Async {
|
|
124
|
-
constructor(sync) {
|
|
125
|
-
super();
|
|
126
|
-
this.sync = sync;
|
|
127
|
-
}
|
|
128
|
-
lock;
|
|
129
|
-
async execute(query) {
|
|
130
|
-
await this.lock;
|
|
131
|
-
return this.sync.execute(query);
|
|
132
|
-
}
|
|
133
|
-
isolate() {
|
|
134
|
-
const connection = new SyncWrapper(this.sync);
|
|
135
|
-
let release, trigger = new Promise((resolve) => {
|
|
136
|
-
release = async () => resolve();
|
|
137
|
-
});
|
|
138
|
-
this.lock = Promise.resolve(this.lock).then(() => trigger);
|
|
139
|
-
return [connection, release];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
})(Driver || (Driver = {}));
|
|
143
|
-
export {
|
|
144
|
-
Driver
|
|
145
|
-
};
|
package/dist/Expr.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { Cursor } from './Cursor';
|
|
2
|
-
import { Fields } from './Fields';
|
|
3
|
-
import { OrderBy } from './OrderBy';
|
|
4
|
-
import { ParamData } from './Param';
|
|
5
|
-
import { Query } from './Query';
|
|
6
|
-
import { Selection } from './Selection';
|
|
7
|
-
import { Target } from './Target';
|
|
8
|
-
export declare const enum UnOp {
|
|
9
|
-
Not = "Not",
|
|
10
|
-
IsNull = "IsNull"
|
|
11
|
-
}
|
|
12
|
-
export declare const enum BinOp {
|
|
13
|
-
Add = "Add",
|
|
14
|
-
Subt = "Subt",
|
|
15
|
-
Mult = "Mult",
|
|
16
|
-
Mod = "Mod",
|
|
17
|
-
Div = "Div",
|
|
18
|
-
Greater = "Greater",
|
|
19
|
-
GreaterOrEqual = "GreaterOrEqual",
|
|
20
|
-
Less = "Less",
|
|
21
|
-
LessOrEqual = "LessOrEqual",
|
|
22
|
-
Equals = "Equals",
|
|
23
|
-
NotEquals = "NotEquals",
|
|
24
|
-
And = "And",
|
|
25
|
-
Or = "Or",
|
|
26
|
-
Like = "Like",
|
|
27
|
-
Glob = "Glob",
|
|
28
|
-
Match = "Match",
|
|
29
|
-
In = "In",
|
|
30
|
-
NotIn = "NotIn",
|
|
31
|
-
Concat = "Concat"
|
|
32
|
-
}
|
|
33
|
-
export declare const enum ExprType {
|
|
34
|
-
UnOp = "UnOp",
|
|
35
|
-
BinOp = "BinOp",
|
|
36
|
-
Field = "Field",
|
|
37
|
-
Param = "Param",
|
|
38
|
-
Call = "Call",
|
|
39
|
-
Query = "Query",
|
|
40
|
-
Record = "Record",
|
|
41
|
-
Row = "Row",
|
|
42
|
-
Map = "Map",
|
|
43
|
-
Filter = "Filter",
|
|
44
|
-
Merge = "Merge",
|
|
45
|
-
Case = "Case"
|
|
46
|
-
}
|
|
47
|
-
export type ExprData = {
|
|
48
|
-
type: ExprType.UnOp;
|
|
49
|
-
op: UnOp;
|
|
50
|
-
expr: ExprData;
|
|
51
|
-
} | {
|
|
52
|
-
type: ExprType.BinOp;
|
|
53
|
-
op: BinOp;
|
|
54
|
-
a: ExprData;
|
|
55
|
-
b: ExprData;
|
|
56
|
-
} | {
|
|
57
|
-
type: ExprType.Field;
|
|
58
|
-
expr: ExprData;
|
|
59
|
-
field: string;
|
|
60
|
-
} | {
|
|
61
|
-
type: ExprType.Param;
|
|
62
|
-
param: ParamData;
|
|
63
|
-
} | {
|
|
64
|
-
type: ExprType.Call;
|
|
65
|
-
method: string;
|
|
66
|
-
params: Array<ExprData>;
|
|
67
|
-
} | {
|
|
68
|
-
type: ExprType.Query;
|
|
69
|
-
query: Query.Select;
|
|
70
|
-
} | {
|
|
71
|
-
type: ExprType.Record;
|
|
72
|
-
fields: Record<string, ExprData>;
|
|
73
|
-
} | {
|
|
74
|
-
type: ExprType.Merge;
|
|
75
|
-
a: ExprData;
|
|
76
|
-
b: ExprData;
|
|
77
|
-
} | {
|
|
78
|
-
type: ExprType.Row;
|
|
79
|
-
target: Target;
|
|
80
|
-
} | {
|
|
81
|
-
type: ExprType.Map;
|
|
82
|
-
target: Target;
|
|
83
|
-
result: ExprData;
|
|
84
|
-
} | {
|
|
85
|
-
type: ExprType.Filter;
|
|
86
|
-
target: Target;
|
|
87
|
-
condition: ExprData;
|
|
88
|
-
} | {
|
|
89
|
-
type: ExprType.Case;
|
|
90
|
-
expr: ExprData;
|
|
91
|
-
cases: Record<string, ExprData>;
|
|
92
|
-
defaultCase?: ExprData;
|
|
93
|
-
};
|
|
94
|
-
export declare const ExprData: {
|
|
95
|
-
UnOp(op: UnOp, expr: ExprData): ExprData;
|
|
96
|
-
BinOp(op: BinOp, a: ExprData, b: ExprData): ExprData;
|
|
97
|
-
Field(expr: ExprData, field: string): ExprData;
|
|
98
|
-
Param(param: ParamData): ExprData;
|
|
99
|
-
Call(method: string, params: Array<ExprData>): ExprData;
|
|
100
|
-
Query(query: Query.Select): ExprData;
|
|
101
|
-
Record(fields: Record<string, ExprData>): ExprData;
|
|
102
|
-
Merge(a: ExprData, b: ExprData): ExprData;
|
|
103
|
-
Row(target: Target): ExprData;
|
|
104
|
-
Map(target: Target, result: ExprData): ExprData;
|
|
105
|
-
Filter(target: Target, condition: ExprData): ExprData;
|
|
106
|
-
Case(expr: ExprData, cases: Record<string, ExprData>, defaultCase?: ExprData): ExprData;
|
|
107
|
-
create(input: any): ExprData;
|
|
108
|
-
};
|
|
109
|
-
/** Expression or value of type T */
|
|
110
|
-
export type EV<T> = Expr<T> | T;
|
|
111
|
-
export declare class Expr<T> {
|
|
112
|
-
expr: ExprData;
|
|
113
|
-
static NULL: ExprData;
|
|
114
|
-
static value<T>(value: T): Expr<T>;
|
|
115
|
-
static create<T>(input: EV<T>): Expr<T>;
|
|
116
|
-
static and(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
117
|
-
static or(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
118
|
-
constructor(expr: ExprData);
|
|
119
|
-
asc(): OrderBy;
|
|
120
|
-
desc(): OrderBy;
|
|
121
|
-
not(): Expr<boolean>;
|
|
122
|
-
or(this: Expr<boolean>, that: EV<boolean>): Expr<boolean>;
|
|
123
|
-
and(this: Expr<boolean>, that: EV<boolean>): Expr<boolean>;
|
|
124
|
-
isNull(): Expr<boolean>;
|
|
125
|
-
isNotNull(): Expr<boolean>;
|
|
126
|
-
isNot(that: EV<T>): Expr<boolean>;
|
|
127
|
-
is(that: EV<T> | Cursor.SelectSingle<T>): Expr<boolean>;
|
|
128
|
-
isIn(that: EV<Array<T>> | Cursor<T>): Expr<boolean>;
|
|
129
|
-
isNotIn(that: EV<Array<T>> | Cursor<T>): Expr<boolean>;
|
|
130
|
-
add(this: Expr<number>, that: EV<number>): Expr<number>;
|
|
131
|
-
substract(this: Expr<number>, that: EV<number>): Expr<number>;
|
|
132
|
-
multiply(this: Expr<number>, that: EV<number>): Expr<number>;
|
|
133
|
-
remainder(this: Expr<number>, that: EV<number>): Expr<number>;
|
|
134
|
-
divide(this: Expr<number>, that: EV<number>): Expr<number>;
|
|
135
|
-
greater(that: EV<any>): Expr<boolean>;
|
|
136
|
-
greaterOrEqual(that: EV<any>): Expr<boolean>;
|
|
137
|
-
less(that: EV<any>): Expr<boolean>;
|
|
138
|
-
lessOrEqual(that: EV<any>): Expr<boolean>;
|
|
139
|
-
concat(this: Expr<string>, that: EV<string>): Expr<string>;
|
|
140
|
-
like(this: Expr<string>, that: EV<string>): Expr<boolean>;
|
|
141
|
-
glob(this: Expr<string>, that: EV<string>): Expr<boolean>;
|
|
142
|
-
match(this: Expr<string>, that: EV<string>): Expr<boolean>;
|
|
143
|
-
with<X extends Selection>(that: X): Selection.With<T, X>;
|
|
144
|
-
at<T>(this: Expr<Array<T>>, index: number): Expr<T | null>;
|
|
145
|
-
filter<T>(this: Expr<Array<T>>, fn: (cursor: Fields<T>) => Expr<boolean>): Expr<Array<T>>;
|
|
146
|
-
map<T, X extends Selection>(this: Expr<Array<T>>, fn: (cursor: Fields<T>) => X): Expr<Array<Selection.Infer<X>>>;
|
|
147
|
-
sure(): Expr<NonNullable<T>>;
|
|
148
|
-
get<T>(name: string): Expr<T>;
|
|
149
|
-
}
|