@ignisia/sql 0.3.0 → 0.4.1
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/cjs/column/index.js +2 -9
- package/dist/cjs/database/alter.d.cts +2 -2
- package/dist/cjs/database/column.d.cts +2 -2
- package/dist/cjs/database/contract.d.cts +2 -2
- package/dist/cjs/database/index.d.cts +2 -2
- package/dist/cjs/database/index.js +1 -1
- package/dist/cjs/database/table.d.cts +2 -2
- package/dist/cjs/database/types.d.cts +1 -1
- package/dist/cjs/database/wrapper.d.cts +3 -3
- package/dist/cjs/database/wrapper.js +1 -17
- package/dist/cjs/{index-2jl8MRfX.d.cts → index-BjgeY76W.d.cts} +2 -2
- package/dist/cjs/{index-CnQVnCEI.d.cts → index-K07efKgt.d.cts} +194 -86
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/migration/index.d.cts +2 -2
- package/dist/cjs/migration/type.d.cts +2 -2
- package/dist/cjs/query/ast.d.cts +8 -0
- package/dist/cjs/query/ast.js +2 -0
- package/dist/cjs/query/builder.d.cts +5 -5
- package/dist/cjs/query/builder.js +8 -10
- package/dist/cjs/query/compiler.d.cts +13 -0
- package/dist/cjs/query/compiler.js +114 -0
- package/dist/cjs/query/condition/common.d.cts +46 -0
- package/dist/cjs/query/condition/common.js +50 -0
- package/dist/cjs/query/condition/core.d.cts +8 -0
- package/dist/cjs/query/condition/core.js +91 -0
- package/dist/cjs/query/condition/index.d.cts +10 -0
- package/dist/cjs/query/condition/index.js +26 -0
- package/dist/cjs/query/condition/not.d.cts +46 -0
- package/dist/cjs/query/condition/not.js +51 -0
- package/dist/cjs/query/constants.d.cts +31 -6
- package/dist/cjs/query/constants.js +30 -5
- package/dist/cjs/query/contract.d.cts +2 -2
- package/dist/cjs/query/explain.d.cts +12 -0
- package/dist/cjs/query/explain.js +65 -0
- package/dist/cjs/query/helper.d.cts +3 -3
- package/dist/cjs/query/helper.js +1 -5
- package/dist/cjs/query/index.d.cts +4 -4
- package/dist/cjs/query/index.js +57 -72
- package/dist/cjs/query/join.d.cts +19 -7
- package/dist/cjs/query/join.js +46 -9
- package/dist/cjs/query/sql.d.cts +6 -4
- package/dist/cjs/query/sql.js +64 -25
- package/dist/cjs/query/types.d.cts +2 -2
- package/dist/cjs/query/utilities.d.cts +7 -8
- package/dist/cjs/query/utilities.js +21 -66
- package/dist/cjs/table/index.d.cts +3 -3
- package/dist/cjs/table/types.d.cts +2 -2
- package/dist/cjs/table/utilities.d.cts +2 -2
- package/dist/cjs/types.d.cts +5 -1
- package/dist/cjs/utilities.d.cts +2 -1
- package/dist/cjs/utilities.js +22 -0
- package/dist/esm/column/index.js +3 -10
- package/dist/esm/database/alter.d.ts +2 -2
- package/dist/esm/database/column.d.ts +2 -2
- package/dist/esm/database/contract.d.ts +2 -2
- package/dist/esm/database/index.d.ts +2 -2
- package/dist/esm/database/index.js +2 -2
- package/dist/esm/database/table.d.ts +2 -2
- package/dist/esm/database/types.d.ts +1 -1
- package/dist/esm/database/wrapper.d.ts +3 -3
- package/dist/esm/database/wrapper.js +1 -17
- package/dist/esm/{index-BXOAxB_h.d.ts → index-B4y4GiNB.d.ts} +2 -2
- package/dist/esm/{index-BdpoD4zk.d.ts → index-CARBkj9h.d.ts} +194 -86
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/migration/index.d.ts +2 -2
- package/dist/esm/migration/type.d.ts +2 -2
- package/dist/esm/query/ast.d.ts +8 -0
- package/dist/esm/query/ast.js +1 -0
- package/dist/esm/query/builder.d.ts +5 -5
- package/dist/esm/query/builder.js +8 -10
- package/dist/esm/query/compiler.d.ts +13 -0
- package/dist/esm/query/compiler.js +112 -0
- package/dist/esm/query/condition/common.d.ts +46 -0
- package/dist/esm/query/condition/common.js +45 -0
- package/dist/esm/query/condition/core.d.ts +8 -0
- package/dist/esm/query/condition/core.js +89 -0
- package/dist/esm/query/condition/index.d.ts +10 -0
- package/dist/esm/query/condition/index.js +3 -0
- package/dist/esm/query/condition/not.d.ts +46 -0
- package/dist/esm/query/condition/not.js +46 -0
- package/dist/esm/query/constants.d.ts +31 -6
- package/dist/esm/query/constants.js +28 -6
- package/dist/esm/query/contract.d.ts +2 -2
- package/dist/esm/query/explain.d.ts +12 -0
- package/dist/esm/query/explain.js +64 -0
- package/dist/esm/query/helper.d.ts +3 -3
- package/dist/esm/query/helper.js +3 -6
- package/dist/esm/query/index.d.ts +4 -4
- package/dist/esm/query/index.js +60 -75
- package/dist/esm/query/join.d.ts +19 -7
- package/dist/esm/query/join.js +45 -9
- package/dist/esm/query/sql.d.ts +6 -4
- package/dist/esm/query/sql.js +64 -27
- package/dist/esm/query/types.d.ts +2 -2
- package/dist/esm/query/utilities.d.ts +7 -8
- package/dist/esm/query/utilities.js +22 -66
- package/dist/esm/table/index.d.ts +3 -3
- package/dist/esm/table/types.d.ts +2 -2
- package/dist/esm/table/utilities.d.ts +2 -2
- package/dist/esm/types.d.ts +5 -1
- package/dist/esm/utilities.d.ts +2 -1
- package/dist/esm/utilities.js +22 -1
- package/package.json +11 -5
- package/dist/cjs/query/condition.d.cts +0 -8
- package/dist/cjs/query/condition.js +0 -109
- package/dist/esm/query/condition.d.ts +0 -8
- package/dist/esm/query/condition.js +0 -101
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import './index.js';
|
|
2
|
-
import { Dialect } from '../table/constants.js';
|
|
3
2
|
import { quoteIdentifier } from '../utilities.js';
|
|
4
|
-
import {
|
|
3
|
+
import { QueryType } from './constants.js';
|
|
5
4
|
|
|
6
5
|
// src/query/utilities.ts
|
|
7
6
|
function getTableColumnNames(column, baseAlias, baseTable, joinedTables) {
|
|
@@ -14,50 +13,6 @@ function getTableColumnNames(column, baseAlias, baseTable, joinedTables) {
|
|
|
14
13
|
columns
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
function getCondition(dialect, column, operator, value) {
|
|
18
|
-
switch (operator) {
|
|
19
|
-
case AcceptedOperator.EQ:
|
|
20
|
-
return `${column} = ?`;
|
|
21
|
-
case AcceptedOperator.NE:
|
|
22
|
-
return `${column} != ?`;
|
|
23
|
-
case AcceptedOperator.GT:
|
|
24
|
-
return `${column} > ?`;
|
|
25
|
-
case AcceptedOperator.LT:
|
|
26
|
-
return `${column} < ?`;
|
|
27
|
-
case AcceptedOperator.GTE:
|
|
28
|
-
return `${column} >= ?`;
|
|
29
|
-
case AcceptedOperator.LTE:
|
|
30
|
-
return `${column} <= ?`;
|
|
31
|
-
case AcceptedOperator.IN:
|
|
32
|
-
return `${column} IN (${value.map(() => "?").join(", ")})`;
|
|
33
|
-
case AcceptedOperator.NOT_IN:
|
|
34
|
-
return `${column} NOT IN (${value.map(() => "?").join(", ")})`;
|
|
35
|
-
case AcceptedOperator.LIKE:
|
|
36
|
-
return `${column} LIKE ?`;
|
|
37
|
-
case AcceptedOperator.NOT_LIKE:
|
|
38
|
-
return `${column} NOT LIKE ?`;
|
|
39
|
-
case AcceptedOperator.ILIKE:
|
|
40
|
-
if (dialect === Dialect.POSTGRES) {
|
|
41
|
-
return `${column} ILIKE ?`;
|
|
42
|
-
}
|
|
43
|
-
return `LOWER(${column}) LIKE LOWER(?)`;
|
|
44
|
-
case AcceptedOperator.NOT_ILIKE:
|
|
45
|
-
if (dialect === Dialect.POSTGRES) {
|
|
46
|
-
return `${column} NOT ILIKE ?`;
|
|
47
|
-
}
|
|
48
|
-
return `LOWER(${column}) NOT LIKE LOWER(?)`;
|
|
49
|
-
case AcceptedOperator.IS_NULL:
|
|
50
|
-
return `${column} IS NULL`;
|
|
51
|
-
case AcceptedOperator.IS_NOT_NULL:
|
|
52
|
-
return `${column} IS NOT NULL`;
|
|
53
|
-
case AcceptedOperator.BETWEEN:
|
|
54
|
-
return `${column} BETWEEN ? AND ?`;
|
|
55
|
-
case AcceptedOperator.NOT_BETWEEN:
|
|
56
|
-
return `${column} NOT BETWEEN ? AND ?`;
|
|
57
|
-
default:
|
|
58
|
-
throw new Error("Invalid operator");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
16
|
function getTimestamp(table) {
|
|
62
17
|
const isWithTimestamp = !!table.timestamp;
|
|
63
18
|
const timestamp = /* @__PURE__ */ new Date();
|
|
@@ -71,13 +26,13 @@ function getTimestamp(table) {
|
|
|
71
26
|
if (typeof table.timestamp.createdAt === "string") {
|
|
72
27
|
createdAt = table.timestamp.createdAt;
|
|
73
28
|
}
|
|
74
|
-
isHasCreatedAt = table.timestamp.createdAt
|
|
29
|
+
isHasCreatedAt = table.timestamp.createdAt !== false;
|
|
75
30
|
}
|
|
76
31
|
if (isCustomTimestamp) {
|
|
77
32
|
if (typeof table.timestamp.updatedAt === "string") {
|
|
78
33
|
updatedAt = table.timestamp.updatedAt;
|
|
79
34
|
}
|
|
80
|
-
isHasUpdatedAt = table.timestamp.updatedAt
|
|
35
|
+
isHasUpdatedAt = table.timestamp.updatedAt !== false;
|
|
81
36
|
}
|
|
82
37
|
}
|
|
83
38
|
return {
|
|
@@ -104,23 +59,6 @@ function getParanoid(table) {
|
|
|
104
59
|
deletedAt
|
|
105
60
|
};
|
|
106
61
|
}
|
|
107
|
-
function getWhereConditions(q) {
|
|
108
|
-
if (q.definition.queryType === QueryType.INSERT) return [];
|
|
109
|
-
const conditions = [];
|
|
110
|
-
const base = q.definition.baseAlias ?? q.table.name;
|
|
111
|
-
const { isWithParanoid, deletedAt } = getParanoid(q.table);
|
|
112
|
-
const withDeleted = !!q.definition.withDeleted;
|
|
113
|
-
const isHasConditions = !!q.definition.where?.length;
|
|
114
|
-
if (!withDeleted && isWithParanoid) {
|
|
115
|
-
const suffix = isHasConditions ? " AND" : "";
|
|
116
|
-
const column = `${base}.${quoteIdentifier(deletedAt)}`;
|
|
117
|
-
conditions.unshift(`${column} IS NULL${suffix}`);
|
|
118
|
-
}
|
|
119
|
-
if (q.definition.where?.length) {
|
|
120
|
-
conditions.push(...q.definition.where);
|
|
121
|
-
}
|
|
122
|
-
return conditions;
|
|
123
|
-
}
|
|
124
62
|
function getGroupByConditions(q) {
|
|
125
63
|
if (q.definition.queryType !== QueryType.SELECT) return [];
|
|
126
64
|
if (q.definition.groupBy?.length) return q.definition.groupBy;
|
|
@@ -182,5 +120,23 @@ function parseAliasedRow({
|
|
|
182
120
|
}
|
|
183
121
|
return result;
|
|
184
122
|
}
|
|
123
|
+
function sanitizeParams(params) {
|
|
124
|
+
return params.map((param) => {
|
|
125
|
+
if (param === null || typeof param === "string" || typeof param === "number" || typeof param === "boolean" || typeof param === "bigint") {
|
|
126
|
+
return param;
|
|
127
|
+
}
|
|
128
|
+
if (param === void 0) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (param instanceof Date) {
|
|
132
|
+
return param.toISOString();
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return JSON.stringify(param);
|
|
136
|
+
} catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
185
141
|
|
|
186
|
-
export {
|
|
142
|
+
export { getGroupByConditions, getParanoid, getTableColumnNames, getTableSelectName, getTimestamp, parseAliasedRow, sanitizeParams };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { T as Table } from '../index-
|
|
1
|
+
export { T as Table } from '../index-CARBkj9h.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import './constants.js';
|
|
4
|
-
import '
|
|
4
|
+
import 'bun';
|
|
5
5
|
import '../types.js';
|
|
6
6
|
import '../query/constants.js';
|
|
7
|
-
import '
|
|
7
|
+
import '../column/constants.js';
|
|
8
8
|
import '../column/types.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import 'bun';
|
|
2
|
-
export {
|
|
2
|
+
export { K as ExecOptions, M as MergeTimestampParanoid, H as TableOptions, I as TableOutput, c as TimestampOptions } from '../index-CARBkj9h.js';
|
|
3
3
|
import '../column/index.js';
|
|
4
4
|
import './constants.js';
|
|
5
|
-
import '../column/constants.js';
|
|
6
5
|
import '../types.js';
|
|
7
6
|
import '../query/constants.js';
|
|
7
|
+
import '../column/constants.js';
|
|
8
8
|
import '../column/types.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import '../column/constants.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import './constants.js';
|
|
4
|
-
export {
|
|
4
|
+
export { y as createdAt, F as defineColumns, B as deletedAt, z as updatedAt } from '../index-CARBkj9h.js';
|
|
5
5
|
import '../column/types.js';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../types.js';
|
|
7
8
|
import '../query/constants.js';
|
|
8
|
-
import 'bun';
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
2
|
+
type BuildTuple<N extends number, T extends unknown[] = []> = T['length'] extends N ? T : BuildTuple<N, [...T, unknown]>;
|
|
3
|
+
type Add<A extends number, B extends number, Result extends unknown[] = [...BuildTuple<A>, ...BuildTuple<B>]> = Result['length'] extends number ? Result['length'] : never;
|
|
4
|
+
type Subtract<A extends number, B extends number> = BuildTuple<A> extends [...BuildTuple<B>, ...infer Rest] ? Rest['length'] : never;
|
|
5
|
+
type Multiply<A extends number, B extends number, Result extends unknown[] = []> = B extends 0 ? Result['length'] : Multiply<A, Subtract<B, 1>, [...Result, ...BuildTuple<A>]>;
|
|
2
6
|
|
|
3
|
-
export type { UnionToIntersection };
|
|
7
|
+
export type { Add, BuildTuple, Multiply, Subtract, UnionToIntersection };
|
package/dist/esm/utilities.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare function deepClone<T>(obj: T): T;
|
|
2
|
+
declare function cloneDefinition<T extends Record<string, unknown>>(def: T): T;
|
|
2
3
|
declare function quoteIdentifier<T extends string, U extends `"${T}"`>(identifier: T): U;
|
|
3
4
|
|
|
4
|
-
export { deepClone, quoteIdentifier };
|
|
5
|
+
export { cloneDefinition, deepClone, quoteIdentifier };
|
package/dist/esm/utilities.js
CHANGED
|
@@ -12,8 +12,29 @@ function deepClone(obj) {
|
|
|
12
12
|
}
|
|
13
13
|
return obj;
|
|
14
14
|
}
|
|
15
|
+
function cloneArray(arr) {
|
|
16
|
+
if (arr.length === 0) return [];
|
|
17
|
+
if (typeof arr[0] === "object" && arr[0] !== null) {
|
|
18
|
+
return arr.map((item) => ({ ...item }));
|
|
19
|
+
}
|
|
20
|
+
return arr.slice();
|
|
21
|
+
}
|
|
22
|
+
function cloneDefinition(def) {
|
|
23
|
+
const clone = {};
|
|
24
|
+
for (const key in def) {
|
|
25
|
+
const val = def[key];
|
|
26
|
+
if (val === null || typeof val !== "object") {
|
|
27
|
+
clone[key] = val;
|
|
28
|
+
} else if (Array.isArray(val)) {
|
|
29
|
+
clone[key] = cloneArray(val);
|
|
30
|
+
} else {
|
|
31
|
+
clone[key] = { ...val };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return clone;
|
|
35
|
+
}
|
|
15
36
|
function quoteIdentifier(identifier) {
|
|
16
37
|
return `"${identifier.replace(/"/g, '""')}"`;
|
|
17
38
|
}
|
|
18
39
|
|
|
19
|
-
export { deepClone, quoteIdentifier };
|
|
40
|
+
export { cloneDefinition, deepClone, quoteIdentifier };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": "dist/cjs/index.js",
|
|
4
4
|
"module": "dist/esm/index.js",
|
|
5
5
|
"types": "./dist/esm/index.d.ts",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.4.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
"import": "./dist/esm/query/index.js",
|
|
43
43
|
"require": "./dist/cjs/query/index.js"
|
|
44
44
|
},
|
|
45
|
+
"./query/condition": {
|
|
46
|
+
"types": "./dist/esm/query/condition/index.d.ts",
|
|
47
|
+
"import": "./dist/esm/query/condition/index.js",
|
|
48
|
+
"require": "./dist/cjs/query/condition/index.js"
|
|
49
|
+
},
|
|
45
50
|
"./table": {
|
|
46
51
|
"types": "./dist/esm/table/index.d.ts",
|
|
47
52
|
"import": "./dist/esm/table/index.js",
|
|
@@ -63,16 +68,17 @@
|
|
|
63
68
|
],
|
|
64
69
|
"repository": {
|
|
65
70
|
"type": "git",
|
|
66
|
-
"url": "git+https://github.com/krsbx/
|
|
71
|
+
"url": "git+https://github.com/krsbx/ignisia.git"
|
|
67
72
|
},
|
|
68
73
|
"bugs": {
|
|
69
|
-
"url": "https://github.com/krsbx/
|
|
74
|
+
"url": "https://github.com/krsbx/ignisia/issues"
|
|
70
75
|
},
|
|
71
76
|
"keywords": [
|
|
72
77
|
"bun",
|
|
73
78
|
"sql",
|
|
74
79
|
"database",
|
|
75
80
|
"sqlite",
|
|
76
|
-
"postgres"
|
|
81
|
+
"postgres",
|
|
82
|
+
"mysql"
|
|
77
83
|
]
|
|
78
|
-
}
|
|
84
|
+
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { N as addCondition, I as addRawCondition, V as having, U as or, L as rawHaving, K as rawOr, J as rawWhere, O as where } from '../index-CnQVnCEI.cjs';
|
|
2
|
-
import '../column/index.cjs';
|
|
3
|
-
import './constants.cjs';
|
|
4
|
-
import '../column/constants.cjs';
|
|
5
|
-
import '../types.cjs';
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../table/constants.cjs';
|
|
8
|
-
import '../column/types.cjs';
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var constants = require('./constants');
|
|
4
|
-
var helper = require('./helper');
|
|
5
|
-
var utilities = require('./utilities');
|
|
6
|
-
|
|
7
|
-
function addRawCondition(query, clause, column, logical, params) {
|
|
8
|
-
const validClause = clause.toLowerCase();
|
|
9
|
-
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
10
|
-
const condition = column(helper.rawCol);
|
|
11
|
-
const logicalPrefix = query.definition[validClause].length > 0 ? logical : "";
|
|
12
|
-
query.definition[validClause].push(`${logicalPrefix} ${condition}`.trim());
|
|
13
|
-
if (!query.definition.params) query.definition.params = [];
|
|
14
|
-
if (typeof params === "undefined") {
|
|
15
|
-
return query;
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(params)) {
|
|
18
|
-
query.definition.params.push(...params);
|
|
19
|
-
} else {
|
|
20
|
-
query.definition.params.push(params);
|
|
21
|
-
}
|
|
22
|
-
return query;
|
|
23
|
-
}
|
|
24
|
-
function rawWhere(column, params) {
|
|
25
|
-
return addRawCondition(
|
|
26
|
-
this,
|
|
27
|
-
constants.ConditionClause.WHERE,
|
|
28
|
-
column,
|
|
29
|
-
constants.LogicalOperator.AND,
|
|
30
|
-
params
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function rawOr(column, params) {
|
|
34
|
-
return addRawCondition(
|
|
35
|
-
this,
|
|
36
|
-
constants.ConditionClause.WHERE,
|
|
37
|
-
column,
|
|
38
|
-
constants.LogicalOperator.OR,
|
|
39
|
-
params
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
function rawHaving(column, params) {
|
|
43
|
-
return addRawCondition(
|
|
44
|
-
this,
|
|
45
|
-
constants.ConditionClause.HAVING,
|
|
46
|
-
column,
|
|
47
|
-
constants.LogicalOperator.AND,
|
|
48
|
-
params
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
function addCondition(query, clause, column, operator, value, logical) {
|
|
52
|
-
if (!query.table.dialect) {
|
|
53
|
-
throw new Error("No DB Dialect defined");
|
|
54
|
-
}
|
|
55
|
-
const validClause = clause.toLowerCase();
|
|
56
|
-
const condition = utilities.getCondition(query.table.dialect, column, operator, value);
|
|
57
|
-
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
58
|
-
const logicalPrefix = query.definition[validClause].length > 0 ? logical : "";
|
|
59
|
-
query.definition[validClause].push(`${logicalPrefix} ${condition}`.trim());
|
|
60
|
-
if (operator === constants.AcceptedOperator.IS_NULL || operator === constants.AcceptedOperator.IS_NOT_NULL) {
|
|
61
|
-
return query;
|
|
62
|
-
}
|
|
63
|
-
if (!query.definition.params) query.definition.params = [];
|
|
64
|
-
if (Array.isArray(value)) {
|
|
65
|
-
query.definition.params.push(...value);
|
|
66
|
-
} else {
|
|
67
|
-
query.definition.params.push(value);
|
|
68
|
-
}
|
|
69
|
-
return query;
|
|
70
|
-
}
|
|
71
|
-
function where(column, operator, value) {
|
|
72
|
-
return addCondition(
|
|
73
|
-
this,
|
|
74
|
-
constants.ConditionClause.WHERE,
|
|
75
|
-
column,
|
|
76
|
-
operator,
|
|
77
|
-
value || null,
|
|
78
|
-
constants.LogicalOperator.AND
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
function or(column, operator, value) {
|
|
82
|
-
return addCondition(
|
|
83
|
-
this,
|
|
84
|
-
constants.ConditionClause.WHERE,
|
|
85
|
-
column,
|
|
86
|
-
operator,
|
|
87
|
-
value || null,
|
|
88
|
-
constants.LogicalOperator.OR
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
function having(column, operator, value) {
|
|
92
|
-
return addCondition(
|
|
93
|
-
this,
|
|
94
|
-
constants.ConditionClause.HAVING,
|
|
95
|
-
column,
|
|
96
|
-
operator,
|
|
97
|
-
value,
|
|
98
|
-
constants.LogicalOperator.AND
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
exports.addCondition = addCondition;
|
|
103
|
-
exports.addRawCondition = addRawCondition;
|
|
104
|
-
exports.having = having;
|
|
105
|
-
exports.or = or;
|
|
106
|
-
exports.rawHaving = rawHaving;
|
|
107
|
-
exports.rawOr = rawOr;
|
|
108
|
-
exports.rawWhere = rawWhere;
|
|
109
|
-
exports.where = where;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { N as addCondition, I as addRawCondition, V as having, U as or, L as rawHaving, K as rawOr, J as rawWhere, O as where } from '../index-BdpoD4zk.js';
|
|
2
|
-
import '../column/index.js';
|
|
3
|
-
import './constants.js';
|
|
4
|
-
import '../column/constants.js';
|
|
5
|
-
import '../types.js';
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../table/constants.js';
|
|
8
|
-
import '../column/types.js';
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { LogicalOperator, ConditionClause, AcceptedOperator } from './constants.js';
|
|
2
|
-
import { rawCol } from './helper.js';
|
|
3
|
-
import { getCondition } from './utilities.js';
|
|
4
|
-
|
|
5
|
-
// src/query/condition.ts
|
|
6
|
-
function addRawCondition(query, clause, column, logical, params) {
|
|
7
|
-
const validClause = clause.toLowerCase();
|
|
8
|
-
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
9
|
-
const condition = column(rawCol);
|
|
10
|
-
const logicalPrefix = query.definition[validClause].length > 0 ? logical : "";
|
|
11
|
-
query.definition[validClause].push(`${logicalPrefix} ${condition}`.trim());
|
|
12
|
-
if (!query.definition.params) query.definition.params = [];
|
|
13
|
-
if (typeof params === "undefined") {
|
|
14
|
-
return query;
|
|
15
|
-
}
|
|
16
|
-
if (Array.isArray(params)) {
|
|
17
|
-
query.definition.params.push(...params);
|
|
18
|
-
} else {
|
|
19
|
-
query.definition.params.push(params);
|
|
20
|
-
}
|
|
21
|
-
return query;
|
|
22
|
-
}
|
|
23
|
-
function rawWhere(column, params) {
|
|
24
|
-
return addRawCondition(
|
|
25
|
-
this,
|
|
26
|
-
ConditionClause.WHERE,
|
|
27
|
-
column,
|
|
28
|
-
LogicalOperator.AND,
|
|
29
|
-
params
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
function rawOr(column, params) {
|
|
33
|
-
return addRawCondition(
|
|
34
|
-
this,
|
|
35
|
-
ConditionClause.WHERE,
|
|
36
|
-
column,
|
|
37
|
-
LogicalOperator.OR,
|
|
38
|
-
params
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
function rawHaving(column, params) {
|
|
42
|
-
return addRawCondition(
|
|
43
|
-
this,
|
|
44
|
-
ConditionClause.HAVING,
|
|
45
|
-
column,
|
|
46
|
-
LogicalOperator.AND,
|
|
47
|
-
params
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
function addCondition(query, clause, column, operator, value, logical) {
|
|
51
|
-
if (!query.table.dialect) {
|
|
52
|
-
throw new Error("No DB Dialect defined");
|
|
53
|
-
}
|
|
54
|
-
const validClause = clause.toLowerCase();
|
|
55
|
-
const condition = getCondition(query.table.dialect, column, operator, value);
|
|
56
|
-
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
57
|
-
const logicalPrefix = query.definition[validClause].length > 0 ? logical : "";
|
|
58
|
-
query.definition[validClause].push(`${logicalPrefix} ${condition}`.trim());
|
|
59
|
-
if (operator === AcceptedOperator.IS_NULL || operator === AcceptedOperator.IS_NOT_NULL) {
|
|
60
|
-
return query;
|
|
61
|
-
}
|
|
62
|
-
if (!query.definition.params) query.definition.params = [];
|
|
63
|
-
if (Array.isArray(value)) {
|
|
64
|
-
query.definition.params.push(...value);
|
|
65
|
-
} else {
|
|
66
|
-
query.definition.params.push(value);
|
|
67
|
-
}
|
|
68
|
-
return query;
|
|
69
|
-
}
|
|
70
|
-
function where(column, operator, value) {
|
|
71
|
-
return addCondition(
|
|
72
|
-
this,
|
|
73
|
-
ConditionClause.WHERE,
|
|
74
|
-
column,
|
|
75
|
-
operator,
|
|
76
|
-
value || null,
|
|
77
|
-
LogicalOperator.AND
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
function or(column, operator, value) {
|
|
81
|
-
return addCondition(
|
|
82
|
-
this,
|
|
83
|
-
ConditionClause.WHERE,
|
|
84
|
-
column,
|
|
85
|
-
operator,
|
|
86
|
-
value || null,
|
|
87
|
-
LogicalOperator.OR
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
function having(column, operator, value) {
|
|
91
|
-
return addCondition(
|
|
92
|
-
this,
|
|
93
|
-
ConditionClause.HAVING,
|
|
94
|
-
column,
|
|
95
|
-
operator,
|
|
96
|
-
value,
|
|
97
|
-
LogicalOperator.AND
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export { addCondition, addRawCondition, having, or, rawHaving, rawOr, rawWhere, where };
|