@stamhoofd/sql 2.115.1 → 2.117.0
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/ModelCache.d.ts +13 -0
- package/dist/src/ModelCache.d.ts.map +1 -0
- package/dist/src/ModelCache.js +57 -0
- package/dist/src/ModelCache.js.map +1 -0
- package/dist/src/QueryableModel.d.ts +21 -7
- package/dist/src/QueryableModel.d.ts.map +1 -1
- package/dist/src/QueryableModel.js +56 -7
- package/dist/src/QueryableModel.js.map +1 -1
- package/dist/src/SQLExpressions.js +1 -1
- package/dist/src/SQLExpressions.js.map +1 -1
- package/dist/src/SQLJoin.d.ts +9 -9
- package/dist/src/SQLJoin.d.ts.map +1 -1
- package/dist/src/SQLJoin.js +7 -7
- package/dist/src/SQLJoin.js.map +1 -1
- package/dist/src/SQLJsonExpressions.d.ts +3 -3
- package/dist/src/SQLJsonExpressions.d.ts.map +1 -1
- package/dist/src/SQLJsonExpressions.js +21 -21
- package/dist/src/SQLJsonExpressions.js.map +1 -1
- package/dist/src/SQLLogger.d.ts +2 -1
- package/dist/src/SQLLogger.d.ts.map +1 -1
- package/dist/src/SQLLogger.js +16 -3
- package/dist/src/SQLLogger.js.map +1 -1
- package/dist/src/SQLOrderBy.d.ts +3 -3
- package/dist/src/SQLOrderBy.d.ts.map +1 -1
- package/dist/src/SQLOrderBy.js +6 -6
- package/dist/src/SQLOrderBy.js.map +1 -1
- package/dist/src/SQLSelect.d.ts +1 -0
- package/dist/src/SQLSelect.d.ts.map +1 -1
- package/dist/src/SQLSelect.js +3 -0
- package/dist/src/SQLSelect.js.map +1 -1
- package/dist/src/SQLWhere.d.ts +4 -4
- package/dist/src/SQLWhere.d.ts.map +1 -1
- package/dist/src/SQLWhere.js +26 -26
- package/dist/src/SQLWhere.js.map +1 -1
- package/dist/src/filters/SQLFilter.d.ts +4 -4
- package/dist/src/filters/SQLFilter.d.ts.map +1 -1
- package/dist/src/filters/SQLFilter.js +26 -23
- package/dist/src/filters/SQLFilter.js.map +1 -1
- package/dist/src/filters/compilers/contains.d.ts +1 -1
- package/dist/src/filters/compilers/contains.d.ts.map +1 -1
- package/dist/src/filters/compilers/contains.js +10 -10
- package/dist/src/filters/compilers/contains.js.map +1 -1
- package/dist/src/filters/compilers/equals.d.ts +1 -1
- package/dist/src/filters/compilers/equals.d.ts.map +1 -1
- package/dist/src/filters/compilers/equals.js +17 -17
- package/dist/src/filters/compilers/equals.js.map +1 -1
- package/dist/src/filters/compilers/greater.d.ts +1 -1
- package/dist/src/filters/compilers/greater.d.ts.map +1 -1
- package/dist/src/filters/compilers/greater.js +7 -7
- package/dist/src/filters/compilers/greater.js.map +1 -1
- package/dist/src/filters/compilers/in.d.ts +1 -1
- package/dist/src/filters/compilers/in.d.ts.map +1 -1
- package/dist/src/filters/compilers/in.js +16 -16
- package/dist/src/filters/compilers/in.js.map +1 -1
- package/dist/src/filters/compilers/index.d.ts +4 -4
- package/dist/src/filters/compilers/index.d.ts.map +1 -1
- package/dist/src/filters/compilers/index.js +4 -4
- package/dist/src/filters/compilers/index.js.map +1 -1
- package/dist/src/filters/compilers/less.d.ts +1 -1
- package/dist/src/filters/compilers/less.d.ts.map +1 -1
- package/dist/src/filters/compilers/less.js +7 -7
- package/dist/src/filters/compilers/less.js.map +1 -1
- package/dist/src/filters/helpers/isJSONColumn.d.ts +1 -1
- package/dist/src/filters/helpers/isJSONColumn.d.ts.map +1 -1
- package/dist/src/filters/helpers/isJSONColumn.js +6 -6
- package/dist/src/filters/helpers/isJSONColumn.js.map +1 -1
- package/dist/src/filters/helpers/normalizeCompareValue.d.ts +1 -1
- package/dist/src/filters/helpers/normalizeCompareValue.d.ts.map +1 -1
- package/dist/src/filters/helpers/normalizeCompareValue.js +14 -14
- package/dist/src/filters/helpers/normalizeCompareValue.js.map +1 -1
- package/dist/tests/filters/$and.test.js +31 -31
- package/dist/tests/filters/$and.test.js.map +1 -1
- package/dist/tests/filters/$contains.test.js +45 -45
- package/dist/tests/filters/$contains.test.js.map +1 -1
- package/dist/tests/filters/$eq.test.js +88 -88
- package/dist/tests/filters/$eq.test.js.map +1 -1
- package/dist/tests/filters/$gt.test.js +32 -32
- package/dist/tests/filters/$gt.test.js.map +1 -1
- package/dist/tests/filters/$gte.test.js +26 -26
- package/dist/tests/filters/$gte.test.js.map +1 -1
- package/dist/tests/filters/$in.test.js +45 -45
- package/dist/tests/filters/$in.test.js.map +1 -1
- package/dist/tests/filters/$lt.test.js +26 -26
- package/dist/tests/filters/$lt.test.js.map +1 -1
- package/dist/tests/filters/$lte.test.js +26 -26
- package/dist/tests/filters/$lte.test.js.map +1 -1
- package/dist/tests/filters/$neq.test.js +6 -6
- package/dist/tests/filters/$neq.test.js.map +1 -1
- package/dist/tests/filters/$not.test.js +9 -9
- package/dist/tests/filters/$not.test.js.map +1 -1
- package/dist/tests/filters/$or.test.js +25 -25
- package/dist/tests/filters/$or.test.js.map +1 -1
- package/dist/tests/filters/SQLTranslatedStringHelper.test.js +50 -50
- package/dist/tests/filters/SQLTranslatedStringHelper.test.js.map +1 -1
- package/dist/tests/filters/dot-syntax.test.js +20 -20
- package/dist/tests/filters/dot-syntax.test.js.map +1 -1
- package/dist/tests/filters/exists.test.js +26 -36
- package/dist/tests/filters/exists.test.js.map +1 -1
- package/dist/tests/filters/joined-relations.test.js +43 -43
- package/dist/tests/filters/joined-relations.test.js.map +1 -1
- package/dist/tests/filters/special-cases.test.js +19 -19
- package/dist/tests/filters/special-cases.test.js.map +1 -1
- package/dist/tests/filters/wildcard.test.js +12 -12
- package/dist/tests/filters/wildcard.test.js.map +1 -1
- package/dist/tests/utils/index.d.ts +3 -3
- package/dist/tests/utils/index.d.ts.map +1 -1
- package/dist/tests/utils/index.js +12 -12
- package/dist/tests/utils/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/ModelCache.ts +61 -0
- package/src/QueryableModel.ts +71 -8
- package/src/SQLExpressions.ts +1 -1
- package/src/SQLJoin.ts +3 -3
- package/src/SQLJsonExpressions.ts +3 -3
- package/src/SQLLogger.ts +18 -3
- package/src/SQLOrderBy.ts +4 -4
- package/src/SQLSelect.ts +5 -0
- package/src/SQLWhere.ts +5 -5
- package/src/filters/SQLFilter.ts +11 -8
- package/src/filters/compilers/contains.ts +5 -5
- package/src/filters/compilers/equals.ts +6 -6
- package/src/filters/compilers/greater.ts +4 -4
- package/src/filters/compilers/in.ts +6 -6
- package/src/filters/compilers/index.ts +4 -4
- package/src/filters/compilers/less.ts +4 -4
- package/src/filters/helpers/isJSONColumn.ts +1 -1
- package/src/filters/helpers/normalizeCompareValue.ts +1 -1
package/src/QueryableModel.ts
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { Model, SQLResultNamespacedRow } from '@simonbackx/simple-database';
|
|
2
|
-
import { SQLSelect } from './SQLSelect';
|
|
3
|
-
import { SQL } from './SQL';
|
|
4
|
-
import { SQLDelete } from './SQLDelete';
|
|
5
|
-
import { SQLUpdate } from './SQLUpdate';
|
|
6
|
-
import { SQLInsert } from './SQLInsert';
|
|
7
|
-
import { SQLExpression } from './SQLExpression';
|
|
2
|
+
import { SQLSelect } from './SQLSelect.js';
|
|
3
|
+
import { SQL } from './SQL.js';
|
|
4
|
+
import { SQLDelete } from './SQLDelete.js';
|
|
5
|
+
import { SQLUpdate } from './SQLUpdate.js';
|
|
6
|
+
import { SQLInsert } from './SQLInsert.js';
|
|
7
|
+
import { SQLExpression } from './SQLExpression.js';
|
|
8
|
+
import { ModelCache } from './ModelCache.js';
|
|
8
9
|
|
|
9
10
|
export class QueryableModel extends Model {
|
|
10
|
-
|
|
11
|
+
rawSelectedRow: SQLResultNamespacedRow | null = null;
|
|
12
|
+
static cache: ModelCache<QueryableModel> | null = null;
|
|
13
|
+
|
|
14
|
+
static select<T extends typeof Model & typeof QueryableModel>(this: T, ...columns: (SQLExpression | string)[]): SQLSelect<InstanceType<T>> {
|
|
11
15
|
const transformer = (row: SQLResultNamespacedRow): InstanceType<T> => {
|
|
12
|
-
const d = (this as T).fromRow(row[this.table]
|
|
16
|
+
const d = (this as T).fromRow(row[this.table]) as InstanceType<T> | undefined;
|
|
17
|
+
|
|
18
|
+
if (this.cache && d) {
|
|
19
|
+
this.cache.store(d);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If there are any other namespaces, include it as metadata
|
|
13
23
|
|
|
14
24
|
if (!d) {
|
|
15
25
|
console.error('Could not transform row', row, 'into model', this.table, 'check if the primary key is returned in the query');
|
|
16
26
|
throw new Error('Missing data for model ' + this.table);
|
|
17
27
|
}
|
|
28
|
+
if (d instanceof QueryableModel) {
|
|
29
|
+
d.rawSelectedRow = row;
|
|
30
|
+
}
|
|
18
31
|
|
|
19
32
|
return d;
|
|
20
33
|
};
|
|
@@ -68,4 +81,54 @@ export class QueryableModel extends Model {
|
|
|
68
81
|
}
|
|
69
82
|
}
|
|
70
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get a model by its primary key
|
|
87
|
+
* @param id primary key
|
|
88
|
+
*/
|
|
89
|
+
static override async getByID<T extends typeof Model>(this: T & typeof QueryableModel, id: number | string, required: true): Promise<InstanceType<T>>;
|
|
90
|
+
static override async getByID<T extends typeof Model>(this: T & typeof QueryableModel, id: number | string): Promise<InstanceType<T> | undefined>;
|
|
91
|
+
static override async getByID<T extends typeof Model>(this: T & typeof QueryableModel, id: number | string, required?: boolean): Promise<InstanceType<T> | undefined> {
|
|
92
|
+
if (this.cache) {
|
|
93
|
+
const hit = this.cache.getById(id);
|
|
94
|
+
if (hit) {
|
|
95
|
+
console.log('Cache hit, get by id', this.name, id);
|
|
96
|
+
return hit as InstanceType<T>;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return ((await (this as any as typeof QueryableModel).select().where(this.primary.name, id).first(required ?? false)) ?? undefined) as any as InstanceType<T> | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get multiple models by their ID
|
|
104
|
+
* @param ids primary key of the models you want to fetch
|
|
105
|
+
*/
|
|
106
|
+
static override async getByIDs<T extends typeof Model>(this: T & typeof QueryableModel, ...ids: (number | string)[]): Promise<InstanceType<T>[]> {
|
|
107
|
+
if (ids.length === 0) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (this.cache) {
|
|
112
|
+
const hits: InstanceType<T>[] = [];
|
|
113
|
+
const remaining: (number | string)[] = [];
|
|
114
|
+
for (const id of ids) {
|
|
115
|
+
const hit = this.cache.getById(id);
|
|
116
|
+
if (hit) {
|
|
117
|
+
console.log('Cache hit, get by id', this.name, id);
|
|
118
|
+
hits.push(hit as InstanceType<T>);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
remaining.push(id);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
ids = remaining;
|
|
125
|
+
if (remaining.length === 0) {
|
|
126
|
+
return hits;
|
|
127
|
+
}
|
|
128
|
+
const fetched = await (this as any as typeof QueryableModel).select().where(this.primary.name, ids).limit(ids.length).fetch() as any as InstanceType<T>[];
|
|
129
|
+
return [...fetched, ...hits];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (this as any as typeof QueryableModel).select().where(this.primary.name, ids).limit(ids.length).fetch() as any as InstanceType<T>[];
|
|
133
|
+
}
|
|
71
134
|
}
|
package/src/SQLExpressions.ts
CHANGED
package/src/SQLJoin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SQLExpression, SQLExpressionOptions, SQLNamedExpression, SQLQuery, joinSQLQuery } from './SQLExpression';
|
|
2
|
-
import { SQLSelect } from './SQLSelect';
|
|
3
|
-
import { Whereable } from './SQLWhere';
|
|
1
|
+
import { SQLExpression, SQLExpressionOptions, SQLNamedExpression, SQLQuery, joinSQLQuery } from './SQLExpression.js';
|
|
2
|
+
import { SQLSelect } from './SQLSelect.js';
|
|
3
|
+
import { Whereable } from './SQLWhere.js';
|
|
4
4
|
|
|
5
5
|
export enum SQLJoinType {
|
|
6
6
|
Left = 'Left',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SQLExpression, SQLExpressionOptions, SQLQuery, joinSQLQuery } from './SQLExpression';
|
|
2
|
-
import { SQLJSONFalse, SQLJSONNull, SQLJSONTrue, SQLSafeValue, SQLScalar, SQLScalarValue } from './SQLExpressions';
|
|
3
|
-
import { SQLWhere } from './SQLWhere';
|
|
1
|
+
import { SQLExpression, SQLExpressionOptions, SQLQuery, joinSQLQuery } from './SQLExpression.js';
|
|
2
|
+
import { SQLJSONFalse, SQLJSONNull, SQLJSONTrue, SQLSafeValue, SQLScalar, SQLScalarValue } from './SQLExpressions.js';
|
|
3
|
+
import { SQLWhere } from './SQLWhere.js';
|
|
4
4
|
|
|
5
5
|
export function scalarToSQLJSONExpression(s: SQLScalarValue | null): SQLExpression {
|
|
6
6
|
if (s === null) {
|
package/src/SQLLogger.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { StyledText } from '@simonbackx/simple-logging';
|
|
|
4
4
|
class StaticSQLLogger {
|
|
5
5
|
slowQueryThresholdMs: number | null = null;
|
|
6
6
|
explainAllAndLogInefficient = false;
|
|
7
|
+
customLoggers: ((query: string, params: any[], elapsedTimeMs: number) => void)[] = [];
|
|
7
8
|
|
|
8
9
|
async explain(query: string, params: any[]) {
|
|
9
10
|
// Run an EXPLAIN on the query to see what is going on
|
|
@@ -18,14 +19,19 @@ class StaticSQLLogger {
|
|
|
18
19
|
return null;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
async logInefficientExplainResult(query: string, params: any[], explainResult: any) {
|
|
22
|
+
async logInefficientExplainResult(query: string, params: any[], explainResult: any, elapsedTimeMs?: number) {
|
|
22
23
|
if (!explainResult) {
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
26
|
+
if (elapsedTimeMs !== undefined && elapsedTimeMs < 20) {
|
|
27
|
+
// Probably fine
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
if (explainResult['type'] === 'ALL') {
|
|
26
32
|
console.warn(
|
|
27
33
|
new StyledText('[FULL TABLE SCAN] ').addClass('error').addTag('query'),
|
|
28
|
-
|
|
34
|
+
`Inefficient query detected${elapsedTimeMs !== undefined ? ' (' + elapsedTimeMs.toFixed(0) + 'ms)' : ''}:`,
|
|
29
35
|
query,
|
|
30
36
|
params,
|
|
31
37
|
'EXPLAIN result:',
|
|
@@ -55,8 +61,17 @@ class StaticSQLLogger {
|
|
|
55
61
|
console.trace('Slow SQL query (' + elapsedTimeMs.toFixed(2) + 'ms)\nQuery: ' + query, params);
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
for (const logger of this.customLoggers) {
|
|
65
|
+
try {
|
|
66
|
+
logger(query, params, elapsedTimeMs);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error('Error in custom SQL logger', e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
58
73
|
if (this.explainAllAndLogInefficient) {
|
|
59
|
-
await this.logInefficientExplainResult(query, params, await this.explain(query, params));
|
|
74
|
+
await this.logInefficientExplainResult(query, params, await this.explain(query, params), elapsedTimeMs);
|
|
60
75
|
return result;
|
|
61
76
|
}
|
|
62
77
|
|
package/src/SQLOrderBy.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SQLExpression, SQLExpressionOptions, SQLQuery, joinSQLQuery } from './SQLExpression';
|
|
2
|
-
import { SQLColumnExpression } from './SQLExpressions';
|
|
1
|
+
import { SQLExpression, SQLExpressionOptions, SQLQuery, joinSQLQuery } from './SQLExpression.js';
|
|
2
|
+
import { SQLColumnExpression } from './SQLExpressions.js';
|
|
3
3
|
|
|
4
|
-
type Constructor<T =
|
|
4
|
+
type Constructor<T = object> = new (...args: any[]) => T;
|
|
5
5
|
|
|
6
|
-
export function Orderable<Sup extends Constructor<
|
|
6
|
+
export function Orderable<Sup extends Constructor<object>>(Base: Sup) {
|
|
7
7
|
return class extends Base {
|
|
8
8
|
_orderBy: SQLOrderBy | null = null;
|
|
9
9
|
|
package/src/SQLSelect.ts
CHANGED
|
@@ -98,6 +98,10 @@ export class SQLSelect<T extends object = SQLResultNamespacedRow> extends Wherea
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
getSQL(options?: SQLExpressionOptions): SQLQuery {
|
|
101
|
+
if (!this._from) {
|
|
102
|
+
throw new Error('Forgot to define .from(...) for SQLSelect');
|
|
103
|
+
}
|
|
104
|
+
|
|
101
105
|
const query: SQLQuery[] = [
|
|
102
106
|
'SELECT',
|
|
103
107
|
];
|
|
@@ -229,6 +233,7 @@ export class SQLSelect<T extends object = SQLResultNamespacedRow> extends Wherea
|
|
|
229
233
|
|
|
230
234
|
first(required: false): Promise<T | null>;
|
|
231
235
|
first(required: true): Promise<T>;
|
|
236
|
+
first(required: boolean): Promise<T | null>;
|
|
232
237
|
async first(required = true): Promise<T | null> {
|
|
233
238
|
const rows = await this.limit(1).fetch();
|
|
234
239
|
if (rows.length === 0) {
|
package/src/SQLWhere.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SQLExpression, SQLExpressionOptions, SQLQuery, joinSQLQuery, normalizeSQLQuery } from './SQLExpression';
|
|
2
|
-
import { SQLArray, SQLColumnExpression, SQLDynamicExpression, SQLNull, readDynamicSQLExpression } from './SQLExpressions';
|
|
3
|
-
import { SQLJoin, SQLJoinType } from './SQLJoin';
|
|
4
|
-
import { SQLSelect } from './SQLSelect';
|
|
1
|
+
import { SQLExpression, SQLExpressionOptions, SQLQuery, joinSQLQuery, normalizeSQLQuery } from './SQLExpression.js';
|
|
2
|
+
import { SQLArray, SQLColumnExpression, SQLDynamicExpression, SQLNull, readDynamicSQLExpression } from './SQLExpressions.js';
|
|
3
|
+
import { SQLJoin, SQLJoinType } from './SQLJoin.js';
|
|
4
|
+
import { SQLSelect } from './SQLSelect.js';
|
|
5
5
|
|
|
6
|
-
type Constructor<T =
|
|
6
|
+
type Constructor<T = object> = new (...args: any[]) => T;
|
|
7
7
|
|
|
8
8
|
export enum SQLWhereSign {
|
|
9
9
|
Equal = '=',
|
package/src/filters/SQLFilter.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
2
2
|
import { compileFilter, FilterCompiler, FilterDefinitions, filterDefinitionsToCompiler, RequiredFilterCompiler, StamhoofdFilter } from '@stamhoofd/structures';
|
|
3
|
-
import { SQLExpression, SQLExpressionOptions, SQLQuery } from '../SQLExpression';
|
|
4
|
-
import { SQLJoin } from '../SQLJoin';
|
|
5
|
-
import { SQLJsonValue } from '../SQLJsonExpressions';
|
|
6
|
-
import { SQLSelect } from '../SQLSelect';
|
|
7
|
-
import { SQLWhere, SQLWhereAnd, SQLWhereExists, SQLWhereJoin, SQLWhereNot, SQLWhereOr } from '../SQLWhere';
|
|
8
|
-
import { $equalsSQLFilterCompiler, $greaterThanSQLFilterCompiler, $inSQLFilterCompiler, $lessThanSQLFilterCompiler } from './compilers';
|
|
9
|
-
import { $containsSQLFilterCompiler } from './compilers/contains';
|
|
3
|
+
import { SQLExpression, SQLExpressionOptions, SQLQuery } from '../SQLExpression.js';
|
|
4
|
+
import { SQLJoin } from '../SQLJoin.js';
|
|
5
|
+
import { SQLJsonValue } from '../SQLJsonExpressions.js';
|
|
6
|
+
import { SQLSelect } from '../SQLSelect.js';
|
|
7
|
+
import { SQLWhere, SQLWhereAnd, SQLWhereExists, SQLWhereJoin, SQLWhereNot, SQLWhereOr } from '../SQLWhere.js';
|
|
8
|
+
import { $equalsSQLFilterCompiler, $greaterThanSQLFilterCompiler, $inSQLFilterCompiler, $lessThanSQLFilterCompiler } from './compilers/index.js';
|
|
9
|
+
import { $containsSQLFilterCompiler } from './compilers/contains.js';
|
|
10
|
+
import { SQLSafeValue } from '../SQLExpressions.js';
|
|
10
11
|
|
|
11
12
|
export type SQLSyncFilterRunner = (column: SQLCurrentColumn) => SQLWhere;
|
|
12
13
|
export type SQLFilterRunner = (column: SQLCurrentColumn) => Promise<SQLWhere> | SQLWhere;
|
|
@@ -123,7 +124,9 @@ export function createExistsFilter(baseSelect: InstanceType<typeof SQLSelect> &
|
|
|
123
124
|
type: SQLValueType.Table,
|
|
124
125
|
nullable: false,
|
|
125
126
|
});
|
|
126
|
-
const q = baseSelect.clone()
|
|
127
|
+
const q = baseSelect.clone();
|
|
128
|
+
q._columns = [new SQLSafeValue(1)];
|
|
129
|
+
q.andWhere(w);
|
|
127
130
|
return new SQLWhereExists(q);
|
|
128
131
|
};
|
|
129
132
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
2
2
|
import { assertFilterCompareValue, StamhoofdFilter } from '@stamhoofd/structures';
|
|
3
|
-
import { scalarToSQLExpression, SQLLower, SQLNull } from '../../SQLExpressions';
|
|
4
|
-
import { SQLJsonSearch } from '../../SQLJsonExpressions';
|
|
5
|
-
import { SQLWhereEqual, SQLWhereLike, SQLWhereSign } from '../../SQLWhere';
|
|
6
|
-
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner, SQLValueType } from '../SQLFilter';
|
|
7
|
-
import { normalizeCompareValue } from '../helpers/normalizeCompareValue';
|
|
3
|
+
import { scalarToSQLExpression, SQLLower, SQLNull } from '../../SQLExpressions.js';
|
|
4
|
+
import { SQLJsonSearch } from '../../SQLJsonExpressions.js';
|
|
5
|
+
import { SQLWhereEqual, SQLWhereLike, SQLWhereSign } from '../../SQLWhere.js';
|
|
6
|
+
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner, SQLValueType } from '../SQLFilter.js';
|
|
7
|
+
import { normalizeCompareValue } from '../helpers/normalizeCompareValue.js';
|
|
8
8
|
|
|
9
9
|
export function $containsSQLFilterCompiler(filter: StamhoofdFilter): SQLSyncFilterRunner {
|
|
10
10
|
return (originalColumn: SQLCurrentColumn) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { assertFilterCompareValue, StamhoofdFilter } from '@stamhoofd/structures';
|
|
2
|
-
import { scalarToSQLExpression, SQLLower, SQLNull } from '../../SQLExpressions';
|
|
3
|
-
import { SQLJsonContains, SQLJsonSearch, SQLJsonValue } from '../../SQLJsonExpressions';
|
|
4
|
-
import { SQLWhere, SQLWhereEqual, SQLWhereLike, SQLWhereOr, SQLWhereSign } from '../../SQLWhere';
|
|
5
|
-
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner, SQLValueType } from '../SQLFilter';
|
|
6
|
-
import { isJSONColumn } from '../helpers/isJSONColumn';
|
|
7
|
-
import { normalizeCompareValue } from '../helpers/normalizeCompareValue';
|
|
2
|
+
import { scalarToSQLExpression, SQLLower, SQLNull } from '../../SQLExpressions.js';
|
|
3
|
+
import { SQLJsonContains, SQLJsonSearch, SQLJsonValue } from '../../SQLJsonExpressions.js';
|
|
4
|
+
import { SQLWhere, SQLWhereEqual, SQLWhereLike, SQLWhereOr, SQLWhereSign } from '../../SQLWhere.js';
|
|
5
|
+
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner, SQLValueType } from '../SQLFilter.js';
|
|
6
|
+
import { isJSONColumn } from '../helpers/isJSONColumn.js';
|
|
7
|
+
import { normalizeCompareValue } from '../helpers/normalizeCompareValue.js';
|
|
8
8
|
|
|
9
9
|
export function $equalsSQLFilterCompiler(filter: StamhoofdFilter): SQLSyncFilterRunner {
|
|
10
10
|
return (originalColumn: SQLCurrentColumn) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assertFilterCompareValue, StamhoofdFilter } from '@stamhoofd/structures';
|
|
2
|
-
import { scalarToSQLExpression } from '../../SQLExpressions';
|
|
3
|
-
import { SQLWhereEqual, SQLWhereSign } from '../../SQLWhere';
|
|
4
|
-
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner } from '../SQLFilter';
|
|
5
|
-
import { normalizeCompareValue } from '../helpers/normalizeCompareValue';
|
|
2
|
+
import { scalarToSQLExpression } from '../../SQLExpressions.js';
|
|
3
|
+
import { SQLWhereEqual, SQLWhereSign } from '../../SQLWhere.js';
|
|
4
|
+
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner } from '../SQLFilter.js';
|
|
5
|
+
import { normalizeCompareValue } from '../helpers/normalizeCompareValue.js';
|
|
6
6
|
|
|
7
7
|
export function $greaterThanSQLFilterCompiler(filter: StamhoofdFilter): SQLSyncFilterRunner {
|
|
8
8
|
return (originalColumn: SQLCurrentColumn) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
2
2
|
import { assertFilterCompareValue, StamhoofdFilter } from '@stamhoofd/structures';
|
|
3
|
-
import { scalarToSQLExpression, SQLArray } from '../../SQLExpressions';
|
|
4
|
-
import { SQLJsonOverlaps } from '../../SQLJsonExpressions';
|
|
5
|
-
import { SQLWhereEqual, SQLWhereOr, SQLWhereSign } from '../../SQLWhere';
|
|
6
|
-
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner, SQLValueType } from '../SQLFilter';
|
|
7
|
-
import { normalizeCompareValue } from '../helpers/normalizeCompareValue';
|
|
8
|
-
import { $equalsSQLFilterCompiler } from './equals';
|
|
3
|
+
import { scalarToSQLExpression, SQLArray } from '../../SQLExpressions.js';
|
|
4
|
+
import { SQLJsonOverlaps } from '../../SQLJsonExpressions.js';
|
|
5
|
+
import { SQLWhereEqual, SQLWhereOr, SQLWhereSign } from '../../SQLWhere.js';
|
|
6
|
+
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner, SQLValueType } from '../SQLFilter.js';
|
|
7
|
+
import { normalizeCompareValue } from '../helpers/normalizeCompareValue.js';
|
|
8
|
+
import { $equalsSQLFilterCompiler } from './equals.js';
|
|
9
9
|
|
|
10
10
|
export function $inSQLFilterCompiler(filter: StamhoofdFilter): SQLSyncFilterRunner {
|
|
11
11
|
return (originalColumn: SQLCurrentColumn) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './less';
|
|
2
|
-
export * from './greater';
|
|
3
|
-
export * from './equals';
|
|
4
|
-
export * from './in';
|
|
1
|
+
export * from './less.js';
|
|
2
|
+
export * from './greater.js';
|
|
3
|
+
export * from './equals.js';
|
|
4
|
+
export * from './in.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assertFilterCompareValue, StamhoofdFilter } from '@stamhoofd/structures';
|
|
2
|
-
import { scalarToSQLExpression } from '../../SQLExpressions';
|
|
3
|
-
import { SQLWhereEqual, SQLWhereSign } from '../../SQLWhere';
|
|
4
|
-
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner } from '../SQLFilter';
|
|
5
|
-
import { normalizeCompareValue } from '../helpers/normalizeCompareValue';
|
|
2
|
+
import { scalarToSQLExpression } from '../../SQLExpressions.js';
|
|
3
|
+
import { SQLWhereEqual, SQLWhereSign } from '../../SQLWhere.js';
|
|
4
|
+
import { normalizeColumn, SQLCurrentColumn, SQLSyncFilterRunner } from '../SQLFilter.js';
|
|
5
|
+
import { normalizeCompareValue } from '../helpers/normalizeCompareValue.js';
|
|
6
6
|
|
|
7
7
|
export function $lessThanSQLFilterCompiler(filter: StamhoofdFilter): SQLSyncFilterRunner {
|
|
8
8
|
return (originalColumn: SQLCurrentColumn) => {
|