@ignisia/sql 0.2.0 → 0.2.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/dist/column/constants.js +97 -8
- package/dist/column/index.js +105 -8
- package/dist/column/types.js +1 -2
- package/dist/database/alter.js +87 -15
- package/dist/database/column.js +33 -11
- package/dist/database/contract.js +1 -0
- package/dist/database/index.js +92 -19
- package/dist/database/table.js +37 -19
- package/dist/database/types.js +1 -0
- package/dist/database/wrapper.js +92 -9
- package/dist/index.js +5 -32
- package/dist/migration/index.js +48 -6
- package/dist/migration/runner.js +7 -20
- package/dist/migration/type.js +1 -0
- package/dist/query/builder.js +66 -16
- package/dist/query/condition.js +97 -24
- package/dist/query/constants.js +54 -19
- package/dist/query/contract.js +1 -0
- package/dist/query/helper.js +30 -18
- package/dist/query/index.js +195 -10
- package/dist/query/join.js +16 -6
- package/dist/query/sql.js +99 -16
- package/dist/query/types.js +1 -0
- package/dist/query/utilities.js +175 -24
- package/dist/table/constants.js +5 -5
- package/dist/table/index.js +52 -14
- package/dist/table/types.js +1 -0
- package/dist/table/utilities.js +50 -15
- package/dist/types.js +1 -0
- package/dist/utilities.js +18 -8
- package/package.json +37 -2
- package/dist/chunk-62FKD35V.js +0 -65
- package/dist/chunk-CIWX3UCZ.js +0 -51
- package/dist/chunk-EIUC7HJS.js +0 -686
- package/dist/chunk-FYSNJAGD.js +0 -19
- package/dist/chunk-G3LSCLIQ.js +0 -104
- package/dist/chunk-GLOHF5CP.js +0 -9
- package/dist/chunk-GY7R637S.js +0 -113
- package/dist/chunk-HKTHKQLK.js +0 -98
- package/dist/chunk-JF7OSNH4.js +0 -40
- package/dist/chunk-KVCIOW7L.js +0 -59
- package/dist/chunk-OYM2PNYZ.js +0 -44
- package/dist/chunk-UI7U54OT.js +0 -112
- package/dist/chunk-V4OMHVJN.js +0 -96
- package/dist/chunk-WVJGTZFI.js +0 -60
- package/dist/chunk-Y7FSRHH3.js +0 -22
package/dist/query/sql.js
CHANGED
|
@@ -1,16 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { buildDeleteQuery, buildUpdateQuery, buildInsertQuery, buildSelectQuery } from './builder';
|
|
2
|
+
import { QueryType, QueryHooksType } from './constants';
|
|
3
|
+
import { getWhereConditions, getGroupByConditions, parseAliasedRow } from './utilities';
|
|
4
|
+
|
|
5
|
+
function buildQuery(query) {
|
|
6
|
+
let index = 0;
|
|
7
|
+
return query.replace(/\?/g, () => {
|
|
8
|
+
index++;
|
|
9
|
+
return `$${index}`;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function toQuery() {
|
|
13
|
+
let sql = "";
|
|
14
|
+
switch (this.definition.queryType) {
|
|
15
|
+
case QueryType.SELECT:
|
|
16
|
+
sql = buildSelectQuery(this);
|
|
17
|
+
break;
|
|
18
|
+
case QueryType.INSERT:
|
|
19
|
+
sql = buildInsertQuery(this);
|
|
20
|
+
break;
|
|
21
|
+
case QueryType.UPDATE:
|
|
22
|
+
sql = buildUpdateQuery(this);
|
|
23
|
+
break;
|
|
24
|
+
case QueryType.DELETE:
|
|
25
|
+
sql = buildDeleteQuery(this);
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
throw new Error("No query type defined");
|
|
29
|
+
}
|
|
30
|
+
if (this.definition?.joins?.length) {
|
|
31
|
+
sql += ` ${this.definition.joins.join(" ")}`;
|
|
32
|
+
}
|
|
33
|
+
const whereConditions = getWhereConditions(this);
|
|
34
|
+
if (whereConditions.length) {
|
|
35
|
+
sql += ` WHERE ${whereConditions.join(" ")}`;
|
|
36
|
+
}
|
|
37
|
+
const groupByConditions = getGroupByConditions(this);
|
|
38
|
+
if (groupByConditions.length) {
|
|
39
|
+
sql += ` GROUP BY ${groupByConditions.join(", ")}`;
|
|
40
|
+
}
|
|
41
|
+
if (this.definition?.having?.length) {
|
|
42
|
+
sql += ` HAVING ${this.definition.having.join(" ")}`;
|
|
43
|
+
}
|
|
44
|
+
if (this.definition?.orderBy?.length) {
|
|
45
|
+
sql += ` ORDER BY ${this.definition.orderBy.map((order) => [order.column, order.direction].join(" ")).join(", ")}`;
|
|
46
|
+
}
|
|
47
|
+
if (this.definition?.limit !== null) {
|
|
48
|
+
sql += ` LIMIT ?`;
|
|
49
|
+
if (!this.definition.params) this.definition.params = [];
|
|
50
|
+
this.definition.params.push(this.definition.limit);
|
|
51
|
+
}
|
|
52
|
+
if (this.definition?.offset !== null) {
|
|
53
|
+
sql += ` OFFSET ?`;
|
|
54
|
+
if (!this.definition.params) this.definition.params = [];
|
|
55
|
+
this.definition.params.push(this.definition.offset);
|
|
56
|
+
}
|
|
57
|
+
if (this.definition.queryType === QueryType.UPDATE || this.definition.queryType === QueryType.DELETE) {
|
|
58
|
+
sql += ` RETURNING *`;
|
|
59
|
+
}
|
|
60
|
+
sql = buildQuery(sql);
|
|
61
|
+
return { query: sql + ";", params: this.definition.params };
|
|
62
|
+
}
|
|
63
|
+
function toString() {
|
|
64
|
+
return this.toQuery().query;
|
|
65
|
+
}
|
|
66
|
+
async function exec() {
|
|
67
|
+
if (!this.table.client) throw new Error("Database client not defined");
|
|
68
|
+
const { query, params } = this.toQuery();
|
|
69
|
+
if (this.hooks?.before?.size) {
|
|
70
|
+
for (const hook of this.hooks.before.values()) {
|
|
71
|
+
hook({
|
|
72
|
+
query,
|
|
73
|
+
params,
|
|
74
|
+
type: this.definition.queryType,
|
|
75
|
+
hook: QueryHooksType.BEFORE
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const result = await this.table.client.exec(query, params);
|
|
80
|
+
if (this.hooks?.after?.size) {
|
|
81
|
+
for (const hook of this.hooks.after.values()) {
|
|
82
|
+
hook({
|
|
83
|
+
query,
|
|
84
|
+
params,
|
|
85
|
+
type: this.definition.queryType,
|
|
86
|
+
hook: QueryHooksType.AFTER
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result.map(
|
|
91
|
+
(r) => parseAliasedRow({
|
|
92
|
+
row: r,
|
|
93
|
+
selects: this.definition.select ?? [],
|
|
94
|
+
root: this.definition?.baseAlias ?? this.table.name
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { buildQuery, exec, toQuery, toString };
|
package/dist/query/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/query/utilities.js
CHANGED
|
@@ -1,24 +1,175 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import '.';
|
|
2
|
+
import { Dialect } from '../table/constants';
|
|
3
|
+
import { quoteIdentifier } from '../utilities';
|
|
4
|
+
import { AcceptedOperator, QueryType } from './constants';
|
|
5
|
+
|
|
6
|
+
function getTableColumnNames(column, baseAlias, baseTable, joinedTables) {
|
|
7
|
+
const [tableAlias] = column.split(".");
|
|
8
|
+
const isOnBase = tableAlias === baseAlias;
|
|
9
|
+
const from = isOnBase ? baseAlias : tableAlias;
|
|
10
|
+
const columns = isOnBase ? Object.keys(baseTable.columns) : Object.keys(joinedTables?.[from]?.columns ?? {});
|
|
11
|
+
return {
|
|
12
|
+
from,
|
|
13
|
+
columns
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function getCondition(dialect, column, operator, value) {
|
|
17
|
+
switch (operator) {
|
|
18
|
+
case AcceptedOperator.EQ:
|
|
19
|
+
return `${column} = ?`;
|
|
20
|
+
case AcceptedOperator.NE:
|
|
21
|
+
return `${column} != ?`;
|
|
22
|
+
case AcceptedOperator.GT:
|
|
23
|
+
return `${column} > ?`;
|
|
24
|
+
case AcceptedOperator.LT:
|
|
25
|
+
return `${column} < ?`;
|
|
26
|
+
case AcceptedOperator.GTE:
|
|
27
|
+
return `${column} >= ?`;
|
|
28
|
+
case AcceptedOperator.LTE:
|
|
29
|
+
return `${column} <= ?`;
|
|
30
|
+
case AcceptedOperator.IN:
|
|
31
|
+
return `${column} IN (${value.map(() => "?").join(", ")})`;
|
|
32
|
+
case AcceptedOperator.NOT_IN:
|
|
33
|
+
return `${column} NOT IN (${value.map(() => "?").join(", ")})`;
|
|
34
|
+
case AcceptedOperator.LIKE:
|
|
35
|
+
return `${column} LIKE ?`;
|
|
36
|
+
case AcceptedOperator.NOT_LIKE:
|
|
37
|
+
return `${column} NOT LIKE ?`;
|
|
38
|
+
case AcceptedOperator.ILIKE:
|
|
39
|
+
if (dialect === Dialect.POSTGRES) {
|
|
40
|
+
return `${column} ILIKE ?`;
|
|
41
|
+
}
|
|
42
|
+
return `LOWER(${column}) LIKE LOWER(?)`;
|
|
43
|
+
case AcceptedOperator.NOT_ILIKE:
|
|
44
|
+
if (dialect === Dialect.POSTGRES) {
|
|
45
|
+
return `${column} NOT ILIKE ?`;
|
|
46
|
+
}
|
|
47
|
+
return `LOWER(${column}) NOT LIKE LOWER(?)`;
|
|
48
|
+
case AcceptedOperator.IS_NULL:
|
|
49
|
+
return `${column} IS NULL`;
|
|
50
|
+
case AcceptedOperator.IS_NOT_NULL:
|
|
51
|
+
return `${column} IS NOT NULL`;
|
|
52
|
+
case AcceptedOperator.BETWEEN:
|
|
53
|
+
return `${column} BETWEEN ? AND ?`;
|
|
54
|
+
case AcceptedOperator.NOT_BETWEEN:
|
|
55
|
+
return `${column} NOT BETWEEN ? AND ?`;
|
|
56
|
+
default:
|
|
57
|
+
throw new Error("Invalid operator");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function getTimestamp(table) {
|
|
61
|
+
const isWithTimestamp = !!table.timestamp;
|
|
62
|
+
const timestamp = /* @__PURE__ */ new Date();
|
|
63
|
+
let createdAt = "createdAt";
|
|
64
|
+
let updatedAt = "updatedAt";
|
|
65
|
+
if (isWithTimestamp) {
|
|
66
|
+
const isCustomTimestamp = typeof table.timestamp === "object";
|
|
67
|
+
if (isCustomTimestamp && table.timestamp.createdAt) {
|
|
68
|
+
createdAt = table.timestamp.createdAt;
|
|
69
|
+
}
|
|
70
|
+
if (isCustomTimestamp && table.timestamp.updatedAt) {
|
|
71
|
+
updatedAt = table.timestamp.updatedAt;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
isWithTimestamp,
|
|
76
|
+
timestamp,
|
|
77
|
+
createdAt,
|
|
78
|
+
updatedAt
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function getParanoid(table) {
|
|
82
|
+
const isWithParanoid = !!table.paranoid;
|
|
83
|
+
const timestamp = /* @__PURE__ */ new Date();
|
|
84
|
+
let deletedAt = "deletedAt";
|
|
85
|
+
if (isWithParanoid) {
|
|
86
|
+
if (typeof table.paranoid === "string") {
|
|
87
|
+
deletedAt = table.paranoid;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
isWithParanoid,
|
|
92
|
+
timestamp,
|
|
93
|
+
deletedAt
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function getWhereConditions(q) {
|
|
97
|
+
if (q.definition.queryType === QueryType.INSERT) return [];
|
|
98
|
+
const conditions = [];
|
|
99
|
+
const base = q.definition.baseAlias ?? q.table.name;
|
|
100
|
+
const { isWithParanoid, deletedAt } = getParanoid(q.table);
|
|
101
|
+
const withDeleted = !!q.definition.withDeleted;
|
|
102
|
+
const isHasConditions = !!q.definition.where?.length;
|
|
103
|
+
if (!withDeleted && isWithParanoid) {
|
|
104
|
+
const suffix = isHasConditions ? " AND" : "";
|
|
105
|
+
const column = `${base}.${quoteIdentifier(deletedAt)}`;
|
|
106
|
+
conditions.unshift(`${column} IS NULL${suffix}`);
|
|
107
|
+
}
|
|
108
|
+
if (q.definition.where?.length) {
|
|
109
|
+
conditions.push(...q.definition.where);
|
|
110
|
+
}
|
|
111
|
+
return conditions;
|
|
112
|
+
}
|
|
113
|
+
function getGroupByConditions(q) {
|
|
114
|
+
if (q.definition.queryType !== QueryType.SELECT) return [];
|
|
115
|
+
if (q.definition.groupBy?.length) return q.definition.groupBy;
|
|
116
|
+
if (q.definition.aggregates?.length) {
|
|
117
|
+
if (q.definition.select?.length)
|
|
118
|
+
return q.definition.select.map((col) => {
|
|
119
|
+
if (typeof col === "string" && col.endsWith("*")) {
|
|
120
|
+
const { from: from2, columns } = getTableColumnNames(
|
|
121
|
+
col,
|
|
122
|
+
q.definition.baseAlias ?? q.table.name,
|
|
123
|
+
q.table,
|
|
124
|
+
q.definition.joinedTables ?? {}
|
|
125
|
+
);
|
|
126
|
+
return columns.map((column) => `${from2}.${quoteIdentifier(column)}`).join(" ");
|
|
127
|
+
}
|
|
128
|
+
return col;
|
|
129
|
+
});
|
|
130
|
+
const from = q.definition.baseAlias ?? q.table.name;
|
|
131
|
+
return Object.keys(q.table.columns).map(
|
|
132
|
+
(col) => `${from}.${quoteIdentifier(col)}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
function getTableSelectName(q) {
|
|
138
|
+
if (!q.definition.baseAlias) return q.table.name;
|
|
139
|
+
return `${q.table.name} AS ${q.definition.baseAlias}`;
|
|
140
|
+
}
|
|
141
|
+
function parseAliasedRow({
|
|
142
|
+
row,
|
|
143
|
+
selects,
|
|
144
|
+
root = null
|
|
145
|
+
}) {
|
|
146
|
+
let result = {};
|
|
147
|
+
for (const key in row) {
|
|
148
|
+
const [table, column] = key.split(".");
|
|
149
|
+
if (!column) {
|
|
150
|
+
const alias = selects.find(
|
|
151
|
+
(s) => typeof s === "object" && s.as === table
|
|
152
|
+
);
|
|
153
|
+
if (alias) {
|
|
154
|
+
const [oriTab] = alias.column.split(".");
|
|
155
|
+
if (!result[oriTab]) result[oriTab] = {};
|
|
156
|
+
result[oriTab][table] = row[key];
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
result[key] = row[key];
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (!result[table]) result[table] = {};
|
|
163
|
+
result[table][column] = row[key];
|
|
164
|
+
}
|
|
165
|
+
if (root) {
|
|
166
|
+
result = {
|
|
167
|
+
...result,
|
|
168
|
+
...result[root]
|
|
169
|
+
};
|
|
170
|
+
delete result[root];
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { getCondition, getGroupByConditions, getParanoid, getTableColumnNames, getTableSelectName, getTimestamp, getWhereConditions, parseAliasedRow };
|
package/dist/table/constants.js
CHANGED
package/dist/table/index.js
CHANGED
|
@@ -1,14 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { QueryBuilder } from '../query';
|
|
2
|
+
import { defineColumns } from './utilities';
|
|
3
|
+
|
|
4
|
+
class Table {
|
|
5
|
+
client;
|
|
6
|
+
dialect;
|
|
7
|
+
name;
|
|
8
|
+
columns;
|
|
9
|
+
timestamp;
|
|
10
|
+
paranoid;
|
|
11
|
+
_output;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.dialect = options.dialect;
|
|
14
|
+
this.name = options.name;
|
|
15
|
+
this.columns = options.columns;
|
|
16
|
+
this.paranoid = options.paranoid || null;
|
|
17
|
+
this.timestamp = options.timestamp || null;
|
|
18
|
+
this.client = null;
|
|
19
|
+
for (const column of Object.values(this.columns)) {
|
|
20
|
+
column.dialect(options.dialect);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
infer() {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
static define(options) {
|
|
27
|
+
const columns = defineColumns(options);
|
|
28
|
+
return new Table({
|
|
29
|
+
...options,
|
|
30
|
+
columns
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async create(db = this.client) {
|
|
34
|
+
if (!db) throw new Error("Database client not defined");
|
|
35
|
+
const sql = `CREATE TABLE IF NOT EXISTS ${this.name} (${Object.entries(
|
|
36
|
+
this.columns
|
|
37
|
+
).map(([name, column]) => `${name} ${column.toQuery().query}`).join(", ")});`;
|
|
38
|
+
await db.exec(sql);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
async drop(db = this.client) {
|
|
42
|
+
if (!db) throw new Error("Database client not defined");
|
|
43
|
+
const sql = `DROP TABLE IF EXISTS ${this.name};`;
|
|
44
|
+
await db.exec(sql);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
query() {
|
|
48
|
+
return new QueryBuilder(this);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { Table };
|
package/dist/table/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/table/utilities.js
CHANGED
|
@@ -1,15 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
1
|
+
import { Column } from '../column';
|
|
2
|
+
|
|
3
|
+
const createdAt = Column.define({
|
|
4
|
+
type: "DATETIME"
|
|
5
|
+
}).default("CURRENT_TIMESTAMP");
|
|
6
|
+
const updatedAt = Column.define({
|
|
7
|
+
type: "DATETIME"
|
|
8
|
+
});
|
|
9
|
+
const deletedAt = Column.define({
|
|
10
|
+
type: "DATETIME"
|
|
11
|
+
});
|
|
12
|
+
function defineColumns(options) {
|
|
13
|
+
const columns = {
|
|
14
|
+
...options.columns
|
|
15
|
+
};
|
|
16
|
+
const tracker = {
|
|
17
|
+
deletedAt: "deletedAt"
|
|
18
|
+
};
|
|
19
|
+
if (options.timestamp) {
|
|
20
|
+
const timestamp = {
|
|
21
|
+
createdAt: "createdAt",
|
|
22
|
+
updatedAt: "updatedAt"
|
|
23
|
+
};
|
|
24
|
+
if (typeof options.timestamp === "object") {
|
|
25
|
+
if (typeof options.timestamp.createdAt === "string") {
|
|
26
|
+
timestamp.createdAt = options.timestamp.createdAt;
|
|
27
|
+
}
|
|
28
|
+
if (typeof options.timestamp.updatedAt === "string") {
|
|
29
|
+
timestamp.updatedAt = options.timestamp.updatedAt;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!columns[timestamp.createdAt]) {
|
|
33
|
+
columns[timestamp.createdAt] = createdAt;
|
|
34
|
+
}
|
|
35
|
+
if (!columns[timestamp.updatedAt]) {
|
|
36
|
+
columns[timestamp.updatedAt] = updatedAt;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (options.paranoid) {
|
|
40
|
+
if (typeof options.paranoid !== "boolean") {
|
|
41
|
+
tracker.deletedAt = options.paranoid;
|
|
42
|
+
}
|
|
43
|
+
if (!columns[tracker.deletedAt]) {
|
|
44
|
+
columns[tracker.deletedAt] = deletedAt;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return columns;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createdAt, defineColumns, deletedAt, updatedAt };
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/utilities.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
function deepClone(obj) {
|
|
2
|
+
if (Array.isArray(obj)) {
|
|
3
|
+
return obj.map((item) => deepClone(item));
|
|
4
|
+
}
|
|
5
|
+
if (obj && typeof obj === "object") {
|
|
6
|
+
const clonedObj = {};
|
|
7
|
+
for (const key in obj) {
|
|
8
|
+
clonedObj[key] = deepClone(obj[key]);
|
|
9
|
+
}
|
|
10
|
+
return clonedObj;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function quoteIdentifier(identifier) {
|
|
15
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { deepClone, quoteIdentifier };
|
package/package.json
CHANGED
|
@@ -2,8 +2,43 @@
|
|
|
2
2
|
"name": "@ignisia/sql",
|
|
3
3
|
"module": "dist/index.js",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.1",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./*": {
|
|
13
|
+
"import": "./dist/*.js",
|
|
14
|
+
"types": "./dist/*.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./**/*": {
|
|
17
|
+
"import": "./dist/**/*.js",
|
|
18
|
+
"types": "./dist/**/*.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
"./column": {
|
|
22
|
+
"import": "./dist/column/index.js",
|
|
23
|
+
"types": "./dist/column/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./database": {
|
|
26
|
+
"import": "./dist/database/index.js",
|
|
27
|
+
"types": "./dist/database/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./migration": {
|
|
30
|
+
"import": "./dist/migration/index.js",
|
|
31
|
+
"types": "./dist/migration/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./query": {
|
|
34
|
+
"import": "./dist/query/index.js",
|
|
35
|
+
"types": "./dist/query/index.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./table": {
|
|
38
|
+
"import": "./dist/table/index.js",
|
|
39
|
+
"types": "./dist/table/index.d.ts"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
7
42
|
"scripts": {
|
|
8
43
|
"build": "bun run build.ts"
|
|
9
44
|
},
|
|
@@ -17,4 +52,4 @@
|
|
|
17
52
|
"files": [
|
|
18
53
|
"dist"
|
|
19
54
|
]
|
|
20
|
-
}
|
|
55
|
+
}
|
package/dist/chunk-62FKD35V.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/query/constants.ts
|
|
2
|
-
var LogicalOperator = {
|
|
3
|
-
AND: "AND",
|
|
4
|
-
OR: "OR"
|
|
5
|
-
};
|
|
6
|
-
var ConditionClause = {
|
|
7
|
-
WHERE: "WHERE",
|
|
8
|
-
HAVING: "HAVING"
|
|
9
|
-
};
|
|
10
|
-
var AcceptedOperator = {
|
|
11
|
-
EQ: "eq",
|
|
12
|
-
NE: "ne",
|
|
13
|
-
GT: "gt",
|
|
14
|
-
LT: "lt",
|
|
15
|
-
GTE: "gte",
|
|
16
|
-
LTE: "lte",
|
|
17
|
-
IN: "in",
|
|
18
|
-
NOT_IN: "notIn",
|
|
19
|
-
LIKE: "like",
|
|
20
|
-
NOT_LIKE: "notLike",
|
|
21
|
-
ILIKE: "ilike",
|
|
22
|
-
NOT_ILIKE: "notILike",
|
|
23
|
-
IS_NULL: "isNull",
|
|
24
|
-
IS_NOT_NULL: "isNotNull",
|
|
25
|
-
BETWEEN: "between",
|
|
26
|
-
NOT_BETWEEN: "notBetween"
|
|
27
|
-
};
|
|
28
|
-
var QueryType = {
|
|
29
|
-
SELECT: "SELECT",
|
|
30
|
-
INSERT: "INSERT",
|
|
31
|
-
UPDATE: "UPDATE",
|
|
32
|
-
DELETE: "DELETE"
|
|
33
|
-
};
|
|
34
|
-
var OrderBy = {
|
|
35
|
-
ASC: "ASC",
|
|
36
|
-
DESC: "DESC"
|
|
37
|
-
};
|
|
38
|
-
var AggregationFunction = {
|
|
39
|
-
COUNT: "COUNT",
|
|
40
|
-
SUM: "SUM",
|
|
41
|
-
MIN: "MIN",
|
|
42
|
-
MAX: "MAX",
|
|
43
|
-
AVG: "AVG"
|
|
44
|
-
};
|
|
45
|
-
var AcceptedJoin = {
|
|
46
|
-
INNER: "INNER",
|
|
47
|
-
LEFT: "LEFT",
|
|
48
|
-
RIGHT: "RIGHT",
|
|
49
|
-
NATURAL: "NATURAL"
|
|
50
|
-
};
|
|
51
|
-
var QueryHooksType = {
|
|
52
|
-
AFTER: "after",
|
|
53
|
-
BEFORE: "before"
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
LogicalOperator,
|
|
58
|
-
ConditionClause,
|
|
59
|
-
AcceptedOperator,
|
|
60
|
-
QueryType,
|
|
61
|
-
OrderBy,
|
|
62
|
-
AggregationFunction,
|
|
63
|
-
AcceptedJoin,
|
|
64
|
-
QueryHooksType
|
|
65
|
-
};
|
package/dist/chunk-CIWX3UCZ.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// src/migration/index.ts
|
|
2
|
-
var Migration = class _Migration {
|
|
3
|
-
db;
|
|
4
|
-
_up;
|
|
5
|
-
_down;
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.db = options.db;
|
|
8
|
-
this._up = options.up;
|
|
9
|
-
this._down = options.down;
|
|
10
|
-
}
|
|
11
|
-
get up() {
|
|
12
|
-
return this._up;
|
|
13
|
-
}
|
|
14
|
-
get down() {
|
|
15
|
-
return this._down;
|
|
16
|
-
}
|
|
17
|
-
static setUp(migrator, fn) {
|
|
18
|
-
migrator._up = () => fn(migrator.db);
|
|
19
|
-
return migrator;
|
|
20
|
-
}
|
|
21
|
-
static setDown(migrator, fn) {
|
|
22
|
-
migrator._down = () => fn(migrator.db);
|
|
23
|
-
return migrator;
|
|
24
|
-
}
|
|
25
|
-
static define(db, options) {
|
|
26
|
-
const migration = new _Migration({
|
|
27
|
-
db,
|
|
28
|
-
up: options?.up ? () => options.up(db) : null,
|
|
29
|
-
down: options?.down ? () => options.down(db) : null
|
|
30
|
-
});
|
|
31
|
-
return {
|
|
32
|
-
migration,
|
|
33
|
-
setUp(fn) {
|
|
34
|
-
return _Migration.setUp(
|
|
35
|
-
migration,
|
|
36
|
-
fn
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
setDown(fn) {
|
|
40
|
-
return _Migration.setDown(
|
|
41
|
-
migration,
|
|
42
|
-
fn
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
Migration
|
|
51
|
-
};
|