@snowtop/ent 0.1.0-alpha60 → 0.1.0-alpha65
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/core/base.d.ts +10 -2
- package/core/clause.d.ts +12 -0
- package/core/clause.js +35 -14
- package/core/ent.d.ts +28 -4
- package/core/ent.js +48 -3
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/schema/schema.d.ts +8 -0
- package/testutils/db/temp_db.js +1 -0
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +15 -5
package/core/base.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface QueryDataOptions {
|
|
|
72
72
|
orderby?: string;
|
|
73
73
|
groupby?: string;
|
|
74
74
|
limit?: number;
|
|
75
|
+
disableTransformations?: boolean;
|
|
75
76
|
}
|
|
76
77
|
export interface LoadRowOptions extends QueryableDataOptions {
|
|
77
78
|
}
|
|
@@ -85,13 +86,20 @@ export interface EditRowOptions extends CreateRowOptions {
|
|
|
85
86
|
whereClause: clause.Clause;
|
|
86
87
|
}
|
|
87
88
|
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
88
|
-
loaderFactory:
|
|
89
|
+
loaderFactory: LoaderFactoryWithOptions;
|
|
89
90
|
ent: EntConstructor<TEnt, TViewer>;
|
|
90
91
|
}
|
|
92
|
+
interface LoaderFactoryWithOptions extends LoaderFactory<any, Data | null> {
|
|
93
|
+
options?: SelectDataOptions;
|
|
94
|
+
}
|
|
91
95
|
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends LoadableEntOptions<TEnt, TViewer>, SelectBaseDataOptions {
|
|
92
96
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
93
97
|
}
|
|
94
|
-
export interface
|
|
98
|
+
export interface SelectCustomDataOptions extends SelectBaseDataOptions {
|
|
99
|
+
clause?: clause.Clause;
|
|
100
|
+
loaderFactory?: LoaderFactoryWithOptions;
|
|
101
|
+
}
|
|
102
|
+
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends SelectCustomDataOptions {
|
|
95
103
|
ent: EntConstructor<TEnt, TViewer>;
|
|
96
104
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
97
105
|
}
|
package/core/clause.d.ts
CHANGED
|
@@ -56,6 +56,18 @@ export declare function PostgresArrayNotContainsValue(col: string, value: any):
|
|
|
56
56
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
57
57
|
*/
|
|
58
58
|
export declare function PostgresArrayNotContains(col: string, value: any[]): Clause;
|
|
59
|
+
/**
|
|
60
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
61
|
+
* only works with postgres gin indexes
|
|
62
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
63
|
+
*/
|
|
64
|
+
export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
|
|
65
|
+
/**
|
|
66
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
67
|
+
* only works with postgres gin indexes
|
|
68
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
69
|
+
*/
|
|
70
|
+
export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
|
|
59
71
|
/**
|
|
60
72
|
* @deprecated use PostgresArrayContainsValue
|
|
61
73
|
*/
|
package/core/clause.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.In = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = void 0;
|
|
22
|
+
exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.In = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = void 0;
|
|
23
23
|
const db_1 = __importStar(require("./db"));
|
|
24
24
|
function isSensitive(val) {
|
|
25
25
|
return (val !== null &&
|
|
@@ -157,18 +157,19 @@ class arraySimpleClause {
|
|
|
157
157
|
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
class
|
|
161
|
-
constructor(col, value, not) {
|
|
160
|
+
class postgresArrayOperator {
|
|
161
|
+
constructor(col, value, op, not) {
|
|
162
162
|
this.col = col;
|
|
163
163
|
this.value = value;
|
|
164
|
+
this.op = op;
|
|
164
165
|
this.not = not;
|
|
165
166
|
}
|
|
166
167
|
clause(idx) {
|
|
167
168
|
if (db_1.default.getDialect() === db_1.Dialect.Postgres) {
|
|
168
169
|
if (this.not) {
|
|
169
|
-
return `NOT ${this.col}
|
|
170
|
+
return `NOT ${this.col} ${this.op} $${idx}`;
|
|
170
171
|
}
|
|
171
|
-
return `${this.col}
|
|
172
|
+
return `${this.col} ${this.op} $${idx}`;
|
|
172
173
|
}
|
|
173
174
|
throw new Error(`not supported`);
|
|
174
175
|
}
|
|
@@ -189,14 +190,14 @@ class postgresArrayContains {
|
|
|
189
190
|
}
|
|
190
191
|
instanceKey() {
|
|
191
192
|
if (this.not) {
|
|
192
|
-
return `NOT:${this.col}
|
|
193
|
+
return `NOT:${this.col}${this.op}${rawValue(this.value)}`;
|
|
193
194
|
}
|
|
194
|
-
return `${this.col}
|
|
195
|
+
return `${this.col}${this.op}${rawValue(this.value)}`;
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
|
-
class
|
|
198
|
-
constructor(col, value, not) {
|
|
199
|
-
super(col, value, not);
|
|
198
|
+
class postgresArrayOperatorList extends postgresArrayOperator {
|
|
199
|
+
constructor(col, value, op, not) {
|
|
200
|
+
super(col, value, op, not);
|
|
200
201
|
}
|
|
201
202
|
values() {
|
|
202
203
|
return [
|
|
@@ -374,13 +375,15 @@ class websearchTosQueryClause extends tsQueryClause {
|
|
|
374
375
|
return "websearch_to_tsquery";
|
|
375
376
|
}
|
|
376
377
|
}
|
|
378
|
+
// postgres array operators
|
|
379
|
+
// https://www.postgresql.org/docs/current/functions-array.html
|
|
377
380
|
/**
|
|
378
381
|
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
379
382
|
* only works with postgres gin indexes
|
|
380
383
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
381
384
|
*/
|
|
382
385
|
function PostgresArrayContainsValue(col, value) {
|
|
383
|
-
return new
|
|
386
|
+
return new postgresArrayOperator(col, value, "@>");
|
|
384
387
|
}
|
|
385
388
|
exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
|
|
386
389
|
/**
|
|
@@ -389,7 +392,7 @@ exports.PostgresArrayContainsValue = PostgresArrayContainsValue;
|
|
|
389
392
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
390
393
|
*/
|
|
391
394
|
function PostgresArrayContains(col, value) {
|
|
392
|
-
return new
|
|
395
|
+
return new postgresArrayOperatorList(col, value, "@>");
|
|
393
396
|
}
|
|
394
397
|
exports.PostgresArrayContains = PostgresArrayContains;
|
|
395
398
|
/**
|
|
@@ -398,7 +401,7 @@ exports.PostgresArrayContains = PostgresArrayContains;
|
|
|
398
401
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
399
402
|
*/
|
|
400
403
|
function PostgresArrayNotContainsValue(col, value) {
|
|
401
|
-
return new
|
|
404
|
+
return new postgresArrayOperator(col, value, "@>", true);
|
|
402
405
|
}
|
|
403
406
|
exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
|
|
404
407
|
/**
|
|
@@ -407,9 +410,27 @@ exports.PostgresArrayNotContainsValue = PostgresArrayNotContainsValue;
|
|
|
407
410
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
408
411
|
*/
|
|
409
412
|
function PostgresArrayNotContains(col, value) {
|
|
410
|
-
return new
|
|
413
|
+
return new postgresArrayOperatorList(col, value, "@>", true);
|
|
411
414
|
}
|
|
412
415
|
exports.PostgresArrayNotContains = PostgresArrayNotContains;
|
|
416
|
+
/**
|
|
417
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
418
|
+
* only works with postgres gin indexes
|
|
419
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
420
|
+
*/
|
|
421
|
+
function PostgresArrayOverlaps(col, value) {
|
|
422
|
+
return new postgresArrayOperatorList(col, value, "&&");
|
|
423
|
+
}
|
|
424
|
+
exports.PostgresArrayOverlaps = PostgresArrayOverlaps;
|
|
425
|
+
/**
|
|
426
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
427
|
+
* only works with postgres gin indexes
|
|
428
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
429
|
+
*/
|
|
430
|
+
function PostgresArrayNotOverlaps(col, value) {
|
|
431
|
+
return new postgresArrayOperatorList(col, value, "&&", true);
|
|
432
|
+
}
|
|
433
|
+
exports.PostgresArrayNotOverlaps = PostgresArrayNotOverlaps;
|
|
413
434
|
/**
|
|
414
435
|
* @deprecated use PostgresArrayContainsValue
|
|
415
436
|
*/
|
package/core/ent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Queryer, SyncQueryer } from "./db";
|
|
2
|
-
import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, QueryableDataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context,
|
|
2
|
+
import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, QueryableDataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context, CreateRowOptions, QueryDataOptions, SelectCustomDataOptions } from "./base";
|
|
3
3
|
import { Executor } from "../action/action";
|
|
4
4
|
import * as clause from "./clause";
|
|
5
5
|
import { Builder } from "../action";
|
|
@@ -15,13 +15,37 @@ export declare function loadEnts<TEnt extends Ent<TViewer>, TViewer extends View
|
|
|
15
15
|
export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<TEnt[]>;
|
|
16
16
|
export declare function loadEntsFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, clause: clause.Clause, options: LoadEntOptions<TEnt, TViewer>): Promise<Map<ID, TEnt>>;
|
|
17
17
|
export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer>, query: CustomQuery): Promise<TEnt[]>;
|
|
18
|
-
interface
|
|
18
|
+
interface parameterizedQueryOptions {
|
|
19
19
|
query: string;
|
|
20
20
|
values?: any[];
|
|
21
21
|
logValues?: any[];
|
|
22
22
|
}
|
|
23
|
-
export declare type CustomQuery = string |
|
|
24
|
-
|
|
23
|
+
export declare type CustomQuery = string | parameterizedQueryOptions | clause.Clause | QueryDataOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
26
|
+
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
27
|
+
* (e.g. soft delete) is applied.
|
|
28
|
+
*
|
|
29
|
+
* Passing a full SQL string or Paramterized SQL string doesn't apply it and the given string is sent to the
|
|
30
|
+
* database as written.
|
|
31
|
+
*
|
|
32
|
+
* e.g.
|
|
33
|
+
* Foo.loadCustom(opts, 'SELECT * FROM foo') // doesn't change the query
|
|
34
|
+
* Foo.loadCustom(opts, { query: 'SELECT * FROM foo WHERE id = ?', values: [1]}) // doesn't change the query
|
|
35
|
+
* Foo.loadCustom(opts, query.Eq('time', Date.now())) // changes the query
|
|
36
|
+
* Foo.loadCustom(opts, {
|
|
37
|
+
* clause: query.LessEq('time', Date.now()),
|
|
38
|
+
* limit: 100,
|
|
39
|
+
* orderby: 'time',
|
|
40
|
+
* }) // changes the query
|
|
41
|
+
* Foo.loadCustom(opts, {
|
|
42
|
+
* clause: query.LessEq('time', Date.now()),
|
|
43
|
+
* limit: 100,
|
|
44
|
+
* orderby: 'time',
|
|
45
|
+
* disableTransformations: false
|
|
46
|
+
* }) // doesn't change the query
|
|
47
|
+
*/
|
|
48
|
+
export declare function loadCustomData(options: SelectCustomDataOptions, query: CustomQuery, context: Context | undefined): Promise<Data[]>;
|
|
25
49
|
export declare function loadDerivedEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt | null>;
|
|
26
50
|
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
27
51
|
export declare function loadRowX(options: LoadRowOptions): Promise<Data>;
|
package/core/ent.js
CHANGED
|
@@ -226,32 +226,77 @@ function isClause(opts) {
|
|
|
226
226
|
const cls = opts;
|
|
227
227
|
return cls.clause !== undefined && cls.values !== undefined;
|
|
228
228
|
}
|
|
229
|
-
function
|
|
229
|
+
function isParameterizedQuery(opts) {
|
|
230
230
|
return opts.query !== undefined;
|
|
231
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
234
|
+
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
235
|
+
* (e.g. soft delete) is applied.
|
|
236
|
+
*
|
|
237
|
+
* Passing a full SQL string or Paramterized SQL string doesn't apply it and the given string is sent to the
|
|
238
|
+
* database as written.
|
|
239
|
+
*
|
|
240
|
+
* e.g.
|
|
241
|
+
* Foo.loadCustom(opts, 'SELECT * FROM foo') // doesn't change the query
|
|
242
|
+
* Foo.loadCustom(opts, { query: 'SELECT * FROM foo WHERE id = ?', values: [1]}) // doesn't change the query
|
|
243
|
+
* Foo.loadCustom(opts, query.Eq('time', Date.now())) // changes the query
|
|
244
|
+
* Foo.loadCustom(opts, {
|
|
245
|
+
* clause: query.LessEq('time', Date.now()),
|
|
246
|
+
* limit: 100,
|
|
247
|
+
* orderby: 'time',
|
|
248
|
+
* }) // changes the query
|
|
249
|
+
* Foo.loadCustom(opts, {
|
|
250
|
+
* clause: query.LessEq('time', Date.now()),
|
|
251
|
+
* limit: 100,
|
|
252
|
+
* orderby: 'time',
|
|
253
|
+
* disableTransformations: false
|
|
254
|
+
* }) // doesn't change the query
|
|
255
|
+
*/
|
|
232
256
|
async function loadCustomData(options, query, context) {
|
|
257
|
+
//loaderFactory not here...
|
|
258
|
+
// options.
|
|
259
|
+
function getClause(cls) {
|
|
260
|
+
let optClause = options.clause || options.loaderFactory?.options?.clause;
|
|
261
|
+
if (typeof optClause === "function") {
|
|
262
|
+
optClause = optClause();
|
|
263
|
+
}
|
|
264
|
+
if (!optClause) {
|
|
265
|
+
return cls;
|
|
266
|
+
}
|
|
267
|
+
return clause.And(cls, optClause);
|
|
268
|
+
}
|
|
233
269
|
if (typeof query === "string") {
|
|
234
270
|
// no caching, perform raw query
|
|
235
271
|
return await performRawQuery(query, [], []);
|
|
236
272
|
}
|
|
237
273
|
else if (isClause(query)) {
|
|
274
|
+
// if a Clause is passed in and we have a default clause
|
|
275
|
+
// associated with the query, pass that in
|
|
276
|
+
// if we want to disableTransformations, need to indicate that with
|
|
277
|
+
// disableTransformations option
|
|
238
278
|
// this will have rudimentary caching but nothing crazy
|
|
239
279
|
return await loadRows({
|
|
240
280
|
...options,
|
|
241
|
-
clause: query,
|
|
281
|
+
clause: getClause(query),
|
|
242
282
|
context: context,
|
|
243
283
|
});
|
|
244
284
|
}
|
|
245
|
-
else if (
|
|
285
|
+
else if (isParameterizedQuery(query)) {
|
|
246
286
|
// no caching, perform raw query
|
|
247
287
|
return await performRawQuery(query.query, query.values || [], query.logValues);
|
|
248
288
|
}
|
|
249
289
|
else {
|
|
290
|
+
let cls = query.clause;
|
|
291
|
+
if (!query.disableTransformations) {
|
|
292
|
+
cls = getClause(cls);
|
|
293
|
+
}
|
|
250
294
|
// this will have rudimentary caching but nothing crazy
|
|
251
295
|
return await loadRows({
|
|
252
296
|
...query,
|
|
253
297
|
...options,
|
|
254
298
|
context: context,
|
|
299
|
+
clause: cls,
|
|
255
300
|
});
|
|
256
301
|
}
|
|
257
302
|
}
|
package/index.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ declare const query: {
|
|
|
24
24
|
PostgresArrayContains: typeof q.PostgresArrayContains;
|
|
25
25
|
PostgresArrayNotContainsValue: typeof q.PostgresArrayNotContainsValue;
|
|
26
26
|
PostgresArrayNotContains: typeof q.PostgresArrayNotContains;
|
|
27
|
+
PostgresArrayOverlaps: typeof q.PostgresArrayOverlaps;
|
|
28
|
+
PostgresArrayNotOverlaps: typeof q.PostgresArrayNotOverlaps;
|
|
27
29
|
TsQuery: typeof q.TsQuery;
|
|
28
30
|
PlainToTsQuery: typeof q.PlainToTsQuery;
|
|
29
31
|
PhraseToTsQuery: typeof q.PhraseToTsQuery;
|
package/index.js
CHANGED
|
@@ -121,6 +121,8 @@ const query = {
|
|
|
121
121
|
PostgresArrayContains: q.PostgresArrayContains,
|
|
122
122
|
PostgresArrayNotContainsValue: q.PostgresArrayNotContainsValue,
|
|
123
123
|
PostgresArrayNotContains: q.PostgresArrayNotContains,
|
|
124
|
+
PostgresArrayOverlaps: q.PostgresArrayOverlaps,
|
|
125
|
+
PostgresArrayNotOverlaps: q.PostgresArrayNotOverlaps,
|
|
124
126
|
TsQuery: q.TsQuery,
|
|
125
127
|
PlainToTsQuery: q.PlainToTsQuery,
|
|
126
128
|
PhraseToTsQuery: q.PhraseToTsQuery,
|
package/package.json
CHANGED
package/schema/schema.d.ts
CHANGED
|
@@ -151,6 +151,7 @@ export interface Type {
|
|
|
151
151
|
importType?: ImportType;
|
|
152
152
|
subFields?: FieldMap;
|
|
153
153
|
unionFields?: FieldMap;
|
|
154
|
+
[x: string]: any;
|
|
154
155
|
}
|
|
155
156
|
export interface ForeignKey {
|
|
156
157
|
schema: string;
|
|
@@ -158,6 +159,7 @@ export interface ForeignKey {
|
|
|
158
159
|
name?: string;
|
|
159
160
|
disableIndex?: boolean;
|
|
160
161
|
disableBuilderType?: boolean;
|
|
162
|
+
[x: string]: any;
|
|
161
163
|
}
|
|
162
164
|
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
163
165
|
export interface InverseFieldEdge {
|
|
@@ -247,6 +249,7 @@ export interface ActionField {
|
|
|
247
249
|
list?: boolean;
|
|
248
250
|
actionName?: string;
|
|
249
251
|
excludedFields?: string[];
|
|
252
|
+
[x: string]: any;
|
|
250
253
|
}
|
|
251
254
|
export interface Action {
|
|
252
255
|
operation: ActionOperation;
|
|
@@ -260,6 +263,7 @@ export interface Action {
|
|
|
260
263
|
optionalFields?: string[];
|
|
261
264
|
requiredFields?: string[];
|
|
262
265
|
noFields?: boolean;
|
|
266
|
+
[x: string]: any;
|
|
263
267
|
}
|
|
264
268
|
export declare const NoFields = "__NO_FIELDS__";
|
|
265
269
|
export declare function requiredField(field: string): string;
|
|
@@ -270,6 +274,7 @@ export interface Constraint {
|
|
|
270
274
|
columns: string[];
|
|
271
275
|
fkey?: ForeignKeyInfo;
|
|
272
276
|
condition?: string;
|
|
277
|
+
[x: string]: any;
|
|
273
278
|
}
|
|
274
279
|
export interface FullTextWeight {
|
|
275
280
|
A?: string[];
|
|
@@ -283,6 +288,7 @@ export interface FullText {
|
|
|
283
288
|
languageColumn?: string;
|
|
284
289
|
indexType?: "gin" | "gist";
|
|
285
290
|
weights?: FullTextWeight;
|
|
291
|
+
[x: string]: any;
|
|
286
292
|
}
|
|
287
293
|
export interface Index {
|
|
288
294
|
name: string;
|
|
@@ -290,11 +296,13 @@ export interface Index {
|
|
|
290
296
|
unique?: boolean;
|
|
291
297
|
fulltext?: FullText;
|
|
292
298
|
indexType?: "gin" | "btree";
|
|
299
|
+
[x: string]: any;
|
|
293
300
|
}
|
|
294
301
|
export interface ForeignKeyInfo {
|
|
295
302
|
tableName: string;
|
|
296
303
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
297
304
|
columns: string[];
|
|
305
|
+
[x: string]: any;
|
|
298
306
|
}
|
|
299
307
|
export declare enum ConstraintType {
|
|
300
308
|
PrimaryKey = "primary",
|
package/testutils/db/temp_db.js
CHANGED
package/testutils/parse_sql.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export declare class EqOp {
|
|
|
9
9
|
constructor(col: string, value: any);
|
|
10
10
|
apply(data: Data): boolean;
|
|
11
11
|
}
|
|
12
|
+
export declare class NotEqOp {
|
|
13
|
+
private col;
|
|
14
|
+
private value;
|
|
15
|
+
constructor(col: string, value: any);
|
|
16
|
+
apply(data: Data): boolean;
|
|
17
|
+
}
|
|
12
18
|
export declare class GreaterOp {
|
|
13
19
|
private col;
|
|
14
20
|
private value;
|
package/testutils/parse_sql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.performQuery = exports.OrOp = exports.AndOp = exports.InOp = exports.LessEqOp = exports.GreaterEqOp = exports.LessOp = exports.GreaterOp = exports.EqOp = exports.getDataToReturn = void 0;
|
|
3
|
+
exports.performQuery = exports.OrOp = exports.AndOp = exports.InOp = exports.LessEqOp = exports.GreaterEqOp = exports.LessOp = exports.GreaterOp = exports.NotEqOp = exports.EqOp = exports.getDataToReturn = void 0;
|
|
4
4
|
const node_sql_parser_1 = require("node-sql-parser");
|
|
5
5
|
function getTableName(table) {
|
|
6
6
|
if (Array.isArray(table)) {
|
|
@@ -184,6 +184,16 @@ class EqOp {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
exports.EqOp = EqOp;
|
|
187
|
+
class NotEqOp {
|
|
188
|
+
constructor(col, value) {
|
|
189
|
+
this.col = col;
|
|
190
|
+
this.value = value;
|
|
191
|
+
}
|
|
192
|
+
apply(data) {
|
|
193
|
+
return data[this.col] !== this.value;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.NotEqOp = NotEqOp;
|
|
187
197
|
class GreaterOp {
|
|
188
198
|
constructor(col, value) {
|
|
189
199
|
this.col = col;
|
|
@@ -308,11 +318,11 @@ function getOp(where, values) {
|
|
|
308
318
|
case "OR":
|
|
309
319
|
return new OrOp([getOp(where.left, values), getOp(where.right, values)]);
|
|
310
320
|
case "IS":
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
321
|
+
return new EqOp(getColumnFromRef(where.left), where.right?.value);
|
|
322
|
+
case "IS NOT":
|
|
323
|
+
return new NotEqOp(getColumnFromRef(where.left), where.right?.value);
|
|
314
324
|
default:
|
|
315
|
-
console.
|
|
325
|
+
console.debug(where);
|
|
316
326
|
throw new Error(`unsupported op ${where.operator}`);
|
|
317
327
|
}
|
|
318
328
|
}
|