@ignisia/sql 0.2.2 → 0.3.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/cjs/column/constants.d.cts +58 -5
- package/dist/cjs/column/constants.js +79 -22
- package/dist/cjs/column/index.d.cts +1 -0
- package/dist/cjs/column/index.js +30 -10
- package/dist/cjs/column/utils.d.cts +133 -0
- package/dist/cjs/column/utils.js +34 -0
- package/dist/cjs/database/alter.d.cts +3 -2
- package/dist/cjs/database/alter.js +15 -15
- package/dist/cjs/database/column.d.cts +3 -2
- package/dist/cjs/database/column.js +9 -7
- package/dist/cjs/database/contract.d.cts +3 -2
- package/dist/cjs/database/index.d.cts +3 -2
- package/dist/cjs/database/index.js +14 -1
- package/dist/cjs/database/table.d.cts +3 -2
- package/dist/cjs/database/table.js +12 -4
- package/dist/cjs/database/types.d.cts +2 -1
- package/dist/cjs/database/wrapper.d.cts +17 -21
- package/dist/cjs/database/wrapper.js +44 -52
- package/dist/cjs/{index---zaMa69.d.cts → index-2jl8MRfX.d.cts} +4 -2
- package/dist/cjs/{index-CwiFQh0I.d.cts → index-CnQVnCEI.d.cts} +80 -46
- package/dist/cjs/index.d.cts +3 -2
- package/dist/cjs/migration/index.d.cts +3 -2
- package/dist/cjs/migration/runner.js +1 -1
- package/dist/cjs/migration/type.d.cts +3 -2
- package/dist/cjs/query/builder.d.cts +2 -1
- package/dist/cjs/query/condition.d.cts +2 -1
- package/dist/cjs/query/condition.js +5 -2
- package/dist/cjs/query/contract.d.cts +3 -2
- package/dist/cjs/query/helper.d.cts +2 -1
- package/dist/cjs/query/index.d.cts +2 -1
- package/dist/cjs/query/index.js +16 -7
- package/dist/cjs/query/join.d.cts +2 -1
- package/dist/cjs/query/sql.d.cts +5 -4
- package/dist/cjs/query/sql.js +36 -8
- package/dist/cjs/query/types.d.cts +2 -1
- package/dist/cjs/query/utilities.d.cts +4 -1
- package/dist/cjs/query/utilities.js +15 -5
- package/dist/cjs/table/constants.d.cts +1 -0
- package/dist/cjs/table/constants.js +1 -0
- package/dist/cjs/table/index.d.cts +2 -1
- package/dist/cjs/table/index.js +29 -9
- package/dist/cjs/table/types.d.cts +2 -1
- package/dist/cjs/table/utilities.d.cts +2 -1
- package/dist/esm/column/constants.d.ts +58 -5
- package/dist/esm/column/constants.js +78 -23
- package/dist/esm/column/index.d.ts +1 -0
- package/dist/esm/column/index.js +30 -10
- package/dist/esm/column/utils.d.ts +133 -0
- package/dist/esm/column/utils.js +32 -0
- package/dist/esm/database/alter.d.ts +3 -2
- package/dist/esm/database/alter.js +15 -15
- package/dist/esm/database/column.d.ts +3 -2
- package/dist/esm/database/column.js +9 -7
- package/dist/esm/database/contract.d.ts +3 -2
- package/dist/esm/database/index.d.ts +3 -2
- package/dist/esm/database/index.js +15 -2
- package/dist/esm/database/table.d.ts +3 -2
- package/dist/esm/database/table.js +12 -4
- package/dist/esm/database/types.d.ts +2 -1
- package/dist/esm/database/wrapper.d.ts +17 -21
- package/dist/esm/database/wrapper.js +43 -53
- package/dist/esm/{index-DFrpzXEn.d.ts → index-BXOAxB_h.d.ts} +4 -2
- package/dist/esm/{index-FMT0YEO7.d.ts → index-BdpoD4zk.d.ts} +80 -46
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/migration/index.d.ts +3 -2
- package/dist/esm/migration/runner.js +1 -1
- package/dist/esm/migration/type.d.ts +3 -2
- package/dist/esm/query/builder.d.ts +2 -1
- package/dist/esm/query/condition.d.ts +2 -1
- package/dist/esm/query/condition.js +5 -2
- package/dist/esm/query/contract.d.ts +3 -2
- package/dist/esm/query/helper.d.ts +2 -1
- package/dist/esm/query/index.d.ts +2 -1
- package/dist/esm/query/index.js +16 -7
- package/dist/esm/query/join.d.ts +2 -1
- package/dist/esm/query/sql.d.ts +5 -4
- package/dist/esm/query/sql.js +36 -8
- package/dist/esm/query/types.d.ts +2 -1
- package/dist/esm/query/utilities.d.ts +4 -1
- package/dist/esm/query/utilities.js +15 -5
- package/dist/esm/table/constants.d.ts +1 -0
- package/dist/esm/table/constants.js +1 -0
- package/dist/esm/table/index.d.ts +2 -1
- package/dist/esm/table/index.js +29 -9
- package/dist/esm/table/types.d.ts +2 -1
- package/dist/esm/table/utilities.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
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
2
|
import '../column/index.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
4
|
import '../column/constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../table/constants.cjs';
|
|
7
8
|
import '../column/types.cjs';
|
|
@@ -49,6 +49,9 @@ function rawHaving(column, params) {
|
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
function addCondition(query, clause, column, operator, value, logical) {
|
|
52
|
+
if (!query.table.dialect) {
|
|
53
|
+
throw new Error("No DB Dialect defined");
|
|
54
|
+
}
|
|
52
55
|
const validClause = clause.toLowerCase();
|
|
53
56
|
const condition = utilities.getCondition(query.table.dialect, column, operator, value);
|
|
54
57
|
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
@@ -71,7 +74,7 @@ function where(column, operator, value) {
|
|
|
71
74
|
constants.ConditionClause.WHERE,
|
|
72
75
|
column,
|
|
73
76
|
operator,
|
|
74
|
-
value,
|
|
77
|
+
value || null,
|
|
75
78
|
constants.LogicalOperator.AND
|
|
76
79
|
);
|
|
77
80
|
}
|
|
@@ -81,7 +84,7 @@ function or(column, operator, value) {
|
|
|
81
84
|
constants.ConditionClause.WHERE,
|
|
82
85
|
column,
|
|
83
86
|
operator,
|
|
84
|
-
value,
|
|
87
|
+
value || null,
|
|
85
88
|
constants.LogicalOperator.OR
|
|
86
89
|
);
|
|
87
90
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import 'bun';
|
|
2
|
+
export { Y as QueryConditionContract, X as QueryTransformerContract } from '../index-CnQVnCEI.cjs';
|
|
2
3
|
import '../column/index.cjs';
|
|
4
|
+
import '../table/constants.cjs';
|
|
3
5
|
import './constants.cjs';
|
|
4
6
|
import '../column/constants.cjs';
|
|
5
7
|
import '../types.cjs';
|
|
6
|
-
import '../table/constants.cjs';
|
|
7
8
|
import '../column/types.cjs';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { H as aggregateCol, z as alias, B as clone, G as col, F as rawCol } from '../index-CnQVnCEI.cjs';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
4
|
import '../column/constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../table/constants.cjs';
|
|
7
8
|
import '../column/types.cjs';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import '../column/index.cjs';
|
|
2
|
-
export {
|
|
2
|
+
export { f as QueryBuilder } from '../index-CnQVnCEI.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
4
|
import '../table/constants.cjs';
|
|
5
5
|
import '../column/constants.cjs';
|
|
6
6
|
import '../column/types.cjs';
|
|
7
7
|
import '../types.cjs';
|
|
8
|
+
import 'bun';
|
package/dist/cjs/query/index.js
CHANGED
|
@@ -154,22 +154,31 @@ class QueryBuilder {
|
|
|
154
154
|
insert(...values) {
|
|
155
155
|
this.definition.queryType = constants.QueryType.INSERT;
|
|
156
156
|
if (!this.definition.insertValues) this.definition.insertValues = [];
|
|
157
|
-
const {
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const {
|
|
158
|
+
isWithTimestamp,
|
|
159
|
+
isHasCreatedAt,
|
|
160
|
+
isHasUpdatedAt,
|
|
161
|
+
createdAt,
|
|
162
|
+
updatedAt,
|
|
163
|
+
timestamp
|
|
164
|
+
} = utilities$1.getTimestamp(this.table);
|
|
160
165
|
if (isWithTimestamp) {
|
|
161
166
|
values = values.map((row) => ({
|
|
162
167
|
...row,
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
...isHasCreatedAt && {
|
|
169
|
+
[createdAt]: row[createdAt] ?? timestamp
|
|
170
|
+
},
|
|
171
|
+
...isHasUpdatedAt && {
|
|
172
|
+
[updatedAt]: row[updatedAt] ?? timestamp
|
|
173
|
+
}
|
|
165
174
|
}));
|
|
166
175
|
}
|
|
167
176
|
this.definition.insertValues = values;
|
|
168
177
|
return this;
|
|
169
178
|
}
|
|
170
179
|
update(values) {
|
|
171
|
-
const { isWithTimestamp, updatedAt, timestamp } = utilities$1.getTimestamp(this.table);
|
|
172
|
-
if (isWithTimestamp) {
|
|
180
|
+
const { isWithTimestamp, isHasUpdatedAt, updatedAt, timestamp } = utilities$1.getTimestamp(this.table);
|
|
181
|
+
if (isWithTimestamp && isHasUpdatedAt) {
|
|
173
182
|
values = {
|
|
174
183
|
...values,
|
|
175
184
|
[updatedAt]: values[updatedAt] ?? timestamp
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-CnQVnCEI.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import { AcceptedJoin } from './constants.cjs';
|
|
4
4
|
import '../column/constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../table/constants.cjs';
|
|
7
8
|
import '../column/types.cjs';
|
|
8
9
|
|
package/dist/cjs/query/sql.d.cts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransactionSQL } from 'bun';
|
|
2
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-CnQVnCEI.cjs';
|
|
2
3
|
import { Column } from '../column/index.cjs';
|
|
4
|
+
import { Dialect } from '../table/constants.cjs';
|
|
3
5
|
import '../column/constants.cjs';
|
|
4
6
|
import '../types.cjs';
|
|
5
7
|
import './constants.cjs';
|
|
6
|
-
import '../table/constants.cjs';
|
|
7
8
|
import '../column/types.cjs';
|
|
8
9
|
|
|
9
10
|
declare function buildQuery(query: string): string;
|
|
10
|
-
declare function toQuery<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>(this: Query): {
|
|
11
|
+
declare function toQuery<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>(this: Query, dialect?: Dialect | null): {
|
|
11
12
|
query: string;
|
|
12
13
|
params: unknown[] | null | undefined;
|
|
13
14
|
};
|
|
14
15
|
declare function toString<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>(this: Query): string;
|
|
15
|
-
declare function exec<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, Output extends Query['_output'] = Query['_output']>(this: Query): Promise<Output>;
|
|
16
|
+
declare function exec<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, Output extends Query['_output'] = Query['_output']>(this: Query, tx?: TransactionSQL | null): Promise<Output>;
|
|
16
17
|
|
|
17
18
|
export { buildQuery, exec, toQuery, toString };
|
package/dist/cjs/query/sql.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var constants$1 = require('../table/constants');
|
|
3
4
|
var builder = require('./builder');
|
|
4
5
|
var constants = require('./constants');
|
|
5
6
|
var utilities = require('./utilities');
|
|
@@ -11,7 +12,7 @@ function buildQuery(query) {
|
|
|
11
12
|
return `$${index}`;
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
|
-
function toQuery() {
|
|
15
|
+
function toQuery(dialect) {
|
|
15
16
|
let sql = "";
|
|
16
17
|
switch (this.definition.queryType) {
|
|
17
18
|
case constants.QueryType.SELECT:
|
|
@@ -57,7 +58,9 @@ function toQuery() {
|
|
|
57
58
|
this.definition.params.push(this.definition.offset);
|
|
58
59
|
}
|
|
59
60
|
if (this.definition.queryType === constants.QueryType.UPDATE || this.definition.queryType === constants.QueryType.DELETE) {
|
|
60
|
-
|
|
61
|
+
if (dialect !== constants$1.Dialect.MYSQL) {
|
|
62
|
+
sql += ` RETURNING *`;
|
|
63
|
+
}
|
|
61
64
|
}
|
|
62
65
|
sql = buildQuery(sql);
|
|
63
66
|
return { query: sql + ";", params: this.definition.params };
|
|
@@ -65,26 +68,51 @@ function toQuery() {
|
|
|
65
68
|
function toString() {
|
|
66
69
|
return this.toQuery().query;
|
|
67
70
|
}
|
|
68
|
-
async function exec() {
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
+
async function exec(tx) {
|
|
72
|
+
const client = this.table.client;
|
|
73
|
+
const dialect = this.table.dialect;
|
|
74
|
+
const queryType = this.definition.queryType;
|
|
75
|
+
const isUpdate = queryType === constants.QueryType.UPDATE;
|
|
76
|
+
const isDelete = queryType === constants.QueryType.DELETE;
|
|
77
|
+
const isReturning = isUpdate || isDelete;
|
|
78
|
+
const isMySQL = dialect === constants$1.Dialect.MYSQL;
|
|
79
|
+
if (!client) {
|
|
80
|
+
throw new Error("Database client not defined");
|
|
81
|
+
}
|
|
82
|
+
if (!queryType) {
|
|
83
|
+
throw new Error("No query type defined");
|
|
84
|
+
}
|
|
85
|
+
const { query, params } = this.toQuery(dialect);
|
|
71
86
|
if (this.hooks?.before?.size) {
|
|
72
87
|
for (const hook of this.hooks.before.values()) {
|
|
73
88
|
hook({
|
|
74
89
|
query,
|
|
75
90
|
params,
|
|
76
|
-
type:
|
|
91
|
+
type: queryType,
|
|
77
92
|
hook: constants.QueryHooksType.BEFORE
|
|
78
93
|
});
|
|
79
94
|
}
|
|
80
95
|
}
|
|
81
|
-
|
|
96
|
+
let result = await client.exec({
|
|
97
|
+
sql: query,
|
|
98
|
+
params,
|
|
99
|
+
tx
|
|
100
|
+
});
|
|
101
|
+
if (isMySQL && isReturning) {
|
|
102
|
+
const query2 = this.clone();
|
|
103
|
+
query2.definition.queryType = constants.QueryType.SELECT;
|
|
104
|
+
result = await client.exec({
|
|
105
|
+
sql: query2.toQuery().query,
|
|
106
|
+
params,
|
|
107
|
+
tx
|
|
108
|
+
});
|
|
109
|
+
}
|
|
82
110
|
if (this.hooks?.after?.size) {
|
|
83
111
|
for (const hook of this.hooks.after.values()) {
|
|
84
112
|
hook({
|
|
85
113
|
query,
|
|
86
114
|
params,
|
|
87
|
-
type:
|
|
115
|
+
type: queryType,
|
|
88
116
|
hook: constants.QueryHooksType.AFTER
|
|
89
117
|
});
|
|
90
118
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import '../column/index.cjs';
|
|
2
2
|
import '../column/constants.cjs';
|
|
3
|
-
export {
|
|
3
|
+
export { l as AcceptedInsertValues, k as AcceptedOrderBy, m as AcceptedUpdateValues, n as AggregateColumn, A as AliasedColumn, C as ColumnSelector, h as QuerHooks, Q as QueryDefinition, p as QueryOutput, j as QueryRunHooks, q as QueryRunHooksOptions, R as RawColumn, o as SelectQueryOutput, g as SelectableColumn, e as StrictColumnSelector, W as WhereValue } from '../index-CnQVnCEI.cjs';
|
|
4
4
|
import '../types.cjs';
|
|
5
5
|
import './constants.cjs';
|
|
6
6
|
import '../table/constants.cjs';
|
|
7
7
|
import '../column/types.cjs';
|
|
8
|
+
import 'bun';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { T as Table, W as WhereValue, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, W as WhereValue, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder, A as AliasedColumn, g as SelectableColumn } from '../index-CnQVnCEI.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import { Dialect } from '../table/constants.cjs';
|
|
4
4
|
import { AcceptedOperator } from './constants.cjs';
|
|
5
5
|
import '../column/constants.cjs';
|
|
6
6
|
import '../types.cjs';
|
|
7
|
+
import 'bun';
|
|
7
8
|
import '../column/types.cjs';
|
|
8
9
|
|
|
9
10
|
declare function getTableColumnNames<ColName extends string, BaseAlias extends string, BaseTable extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>>(column: ColName, baseAlias: BaseAlias, baseTable: BaseTable, joinedTables: JoinedTables): {
|
|
@@ -16,6 +17,8 @@ declare function getTimestamp<TableRef extends Table<string, Record<string, Colu
|
|
|
16
17
|
timestamp: Date;
|
|
17
18
|
createdAt: string;
|
|
18
19
|
updatedAt: string;
|
|
20
|
+
isHasUpdatedAt: boolean;
|
|
21
|
+
isHasCreatedAt: boolean;
|
|
19
22
|
};
|
|
20
23
|
declare function getParanoid<TableRef extends Table<string, Record<string, Column>>>(table: TableRef): {
|
|
21
24
|
isWithParanoid: boolean;
|
|
@@ -62,22 +62,32 @@ function getCondition(dialect, column, operator, value) {
|
|
|
62
62
|
function getTimestamp(table) {
|
|
63
63
|
const isWithTimestamp = !!table.timestamp;
|
|
64
64
|
const timestamp = /* @__PURE__ */ new Date();
|
|
65
|
+
let isHasCreatedAt = true;
|
|
66
|
+
let isHasUpdatedAt = true;
|
|
65
67
|
let createdAt = "createdAt";
|
|
66
68
|
let updatedAt = "updatedAt";
|
|
67
69
|
if (isWithTimestamp) {
|
|
68
70
|
const isCustomTimestamp = typeof table.timestamp === "object";
|
|
69
|
-
if (isCustomTimestamp
|
|
70
|
-
|
|
71
|
+
if (isCustomTimestamp) {
|
|
72
|
+
if (typeof table.timestamp.createdAt === "string") {
|
|
73
|
+
createdAt = table.timestamp.createdAt;
|
|
74
|
+
}
|
|
75
|
+
isHasCreatedAt = table.timestamp.createdAt === false;
|
|
71
76
|
}
|
|
72
|
-
if (isCustomTimestamp
|
|
73
|
-
|
|
77
|
+
if (isCustomTimestamp) {
|
|
78
|
+
if (typeof table.timestamp.updatedAt === "string") {
|
|
79
|
+
updatedAt = table.timestamp.updatedAt;
|
|
80
|
+
}
|
|
81
|
+
isHasUpdatedAt = table.timestamp.updatedAt === false;
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
return {
|
|
77
85
|
isWithTimestamp,
|
|
78
86
|
timestamp,
|
|
79
87
|
createdAt,
|
|
80
|
-
updatedAt
|
|
88
|
+
updatedAt,
|
|
89
|
+
isHasUpdatedAt,
|
|
90
|
+
isHasCreatedAt
|
|
81
91
|
};
|
|
82
92
|
}
|
|
83
93
|
function getParanoid(table) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { T as Table } from '../index-
|
|
1
|
+
export { T as Table } from '../index-CnQVnCEI.cjs';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
4
|
import '../column/constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
6
6
|
import '../query/constants.cjs';
|
|
7
|
+
import 'bun';
|
|
7
8
|
import '../column/types.cjs';
|
package/dist/cjs/table/index.js
CHANGED
|
@@ -5,22 +5,21 @@ var utilities = require('./utilities');
|
|
|
5
5
|
|
|
6
6
|
class Table {
|
|
7
7
|
client;
|
|
8
|
-
|
|
8
|
+
_dialect;
|
|
9
9
|
name;
|
|
10
10
|
columns;
|
|
11
11
|
timestamp;
|
|
12
12
|
paranoid;
|
|
13
13
|
_output;
|
|
14
14
|
constructor(options) {
|
|
15
|
-
this.
|
|
15
|
+
this._dialect = options.dialect || null;
|
|
16
16
|
this.name = options.name;
|
|
17
17
|
this.columns = options.columns;
|
|
18
18
|
this.paranoid = options.paranoid || null;
|
|
19
19
|
this.timestamp = options.timestamp || null;
|
|
20
20
|
this.client = null;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
21
|
+
if (!this._dialect) return;
|
|
22
|
+
this.setColumnDialect(this._dialect);
|
|
24
23
|
}
|
|
25
24
|
infer() {
|
|
26
25
|
return null;
|
|
@@ -32,18 +31,39 @@ class Table {
|
|
|
32
31
|
columns
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
|
-
|
|
34
|
+
setColumnDialect(dialect) {
|
|
35
|
+
for (const column of Object.values(this.columns)) {
|
|
36
|
+
column.dialect(dialect);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
get dialect() {
|
|
40
|
+
return this._dialect;
|
|
41
|
+
}
|
|
42
|
+
setDialect(dialect) {
|
|
43
|
+
this._dialect = dialect;
|
|
44
|
+
this.setColumnDialect(dialect);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
async create(options = {}) {
|
|
48
|
+
const db = options.db || this.client;
|
|
36
49
|
if (!db) throw new Error("Database client not defined");
|
|
37
50
|
const sql = `CREATE TABLE IF NOT EXISTS ${this.name} (${Object.entries(
|
|
38
51
|
this.columns
|
|
39
52
|
).map(([name, column]) => `${name} ${column.toQuery().query}`).join(", ")});`;
|
|
40
|
-
await db.exec(
|
|
53
|
+
await db.exec({
|
|
54
|
+
sql,
|
|
55
|
+
tx: options.tx
|
|
56
|
+
});
|
|
41
57
|
return this;
|
|
42
58
|
}
|
|
43
|
-
async drop(
|
|
59
|
+
async drop(options = {}) {
|
|
60
|
+
const db = options.db || this.client;
|
|
44
61
|
if (!db) throw new Error("Database client not defined");
|
|
45
62
|
const sql = `DROP TABLE IF EXISTS ${this.name};`;
|
|
46
|
-
await db.exec(
|
|
63
|
+
await db.exec({
|
|
64
|
+
sql,
|
|
65
|
+
tx: options.tx
|
|
66
|
+
});
|
|
47
67
|
return this;
|
|
48
68
|
}
|
|
49
69
|
query() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import 'bun';
|
|
2
|
+
export { E as ExecOptions, M as MergeTimestampParanoid, x as TableOptions, y as TableOutput, a as TimestampOptions } from '../index-CnQVnCEI.cjs';
|
|
2
3
|
import '../column/index.cjs';
|
|
3
4
|
import './constants.cjs';
|
|
4
5
|
import '../column/constants.cjs';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import '../column/constants.cjs';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
|
-
export {
|
|
4
|
+
export { t as createdAt, w as defineColumns, v as deletedAt, u as updatedAt } from '../index-CnQVnCEI.cjs';
|
|
5
5
|
import '../column/types.cjs';
|
|
6
6
|
import '../types.cjs';
|
|
7
7
|
import '../query/constants.cjs';
|
|
8
|
+
import 'bun';
|
|
@@ -23,75 +23,128 @@ declare const ColumnTypeMapping: {
|
|
|
23
23
|
readonly INTEGER: {
|
|
24
24
|
readonly sqlite: "INTEGER";
|
|
25
25
|
readonly postgres: "INTEGER";
|
|
26
|
+
readonly mysql: "INT";
|
|
26
27
|
};
|
|
27
28
|
readonly STRING: {
|
|
28
29
|
readonly sqlite: "TEXT";
|
|
29
30
|
readonly postgres: "VARCHAR";
|
|
31
|
+
readonly mysql: "VARCHAR";
|
|
30
32
|
};
|
|
31
33
|
readonly BOOLEAN: {
|
|
32
34
|
readonly sqlite: "INTEGER";
|
|
33
35
|
readonly postgres: "BOOLEAN";
|
|
36
|
+
readonly mysql: "TINYINT";
|
|
34
37
|
};
|
|
35
38
|
readonly DATE: {
|
|
36
39
|
readonly sqlite: "TEXT";
|
|
37
40
|
readonly postgres: "DATE";
|
|
41
|
+
readonly mysql: "DATE";
|
|
38
42
|
};
|
|
39
43
|
readonly FLOAT: {
|
|
40
44
|
readonly sqlite: "REAL";
|
|
41
45
|
readonly postgres: "FLOAT";
|
|
46
|
+
readonly mysql: "FLOAT PRECISION";
|
|
42
47
|
};
|
|
43
48
|
readonly DECIMAL: {
|
|
44
|
-
readonly sqlite: "
|
|
49
|
+
readonly sqlite: "NUMERIC";
|
|
45
50
|
readonly postgres: "DECIMAL";
|
|
51
|
+
readonly mysql: "DECIMAL";
|
|
46
52
|
};
|
|
47
53
|
readonly BIGINT: {
|
|
48
|
-
readonly sqlite: "
|
|
54
|
+
readonly sqlite: "INTEGER";
|
|
49
55
|
readonly postgres: "BIGINT";
|
|
56
|
+
readonly mysql: "BIGINT";
|
|
50
57
|
};
|
|
51
58
|
readonly TEXT: {
|
|
52
59
|
readonly sqlite: "TEXT";
|
|
53
60
|
readonly postgres: "TEXT";
|
|
61
|
+
readonly mysql: "TEXT";
|
|
54
62
|
};
|
|
55
63
|
readonly BLOB: {
|
|
56
64
|
readonly sqlite: "BLOB";
|
|
57
65
|
readonly postgres: "BYTEA";
|
|
66
|
+
readonly mysql: "BLOB";
|
|
58
67
|
};
|
|
59
68
|
readonly JSON: {
|
|
60
69
|
readonly sqlite: "TEXT";
|
|
61
70
|
readonly postgres: "JSONB";
|
|
71
|
+
readonly mysql: "JSON";
|
|
62
72
|
};
|
|
63
73
|
readonly VARCHAR: {
|
|
64
|
-
readonly sqlite: "
|
|
74
|
+
readonly sqlite: "VARCHAR";
|
|
65
75
|
readonly postgres: "VARCHAR";
|
|
76
|
+
readonly mysql: "VARCHAR";
|
|
66
77
|
};
|
|
67
78
|
readonly TIME: {
|
|
68
79
|
readonly sqlite: "TEXT";
|
|
69
80
|
readonly postgres: "TIME";
|
|
81
|
+
readonly mysql: "TIME";
|
|
70
82
|
};
|
|
71
83
|
readonly TIMESTAMP: {
|
|
72
84
|
readonly sqlite: "TEXT";
|
|
73
85
|
readonly postgres: "TIMESTAMP";
|
|
86
|
+
readonly mysql: "DATETIME";
|
|
74
87
|
};
|
|
75
88
|
readonly DOUBLE: {
|
|
76
89
|
readonly sqlite: "REAL";
|
|
77
90
|
readonly postgres: "DOUBLE PRECISION";
|
|
91
|
+
readonly mysql: "DOUBLE PRECISION";
|
|
78
92
|
};
|
|
79
93
|
readonly DATETIME: {
|
|
80
94
|
readonly sqlite: "TEXT";
|
|
81
95
|
readonly postgres: "TIMESTAMP";
|
|
96
|
+
readonly mysql: "DATETIME";
|
|
82
97
|
};
|
|
83
98
|
readonly DATEONLY: {
|
|
84
99
|
readonly sqlite: "TEXT";
|
|
85
100
|
readonly postgres: "DATE";
|
|
101
|
+
readonly mysql: "DATE";
|
|
86
102
|
};
|
|
87
103
|
readonly ENUM: {
|
|
88
104
|
readonly sqlite: "TEXT";
|
|
89
105
|
readonly postgres: "TEXT";
|
|
106
|
+
readonly mysql: "TEXT";
|
|
90
107
|
};
|
|
91
108
|
readonly SERIAL: {
|
|
92
|
-
readonly sqlite: "INTEGER
|
|
109
|
+
readonly sqlite: "INTEGER";
|
|
93
110
|
readonly postgres: "SERIAL";
|
|
111
|
+
readonly mysql: "INT";
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
declare const ColumnProperties: {
|
|
115
|
+
readonly NOT_NULL: "NOT_NULL";
|
|
116
|
+
readonly UNIQUE: "UNIQUE";
|
|
117
|
+
readonly DEFAULT: "DEFAULT";
|
|
118
|
+
readonly AUTO_INCREMENT: "AUTO_INCREMENT";
|
|
119
|
+
readonly PRIMARY_KEY: "PRIMARY_KEY";
|
|
120
|
+
};
|
|
121
|
+
type ColumnProperties = (typeof ColumnProperties)[keyof typeof ColumnProperties];
|
|
122
|
+
declare const ColumnPropertyMapping: {
|
|
123
|
+
NOT_NULL: {
|
|
124
|
+
sqlite: string;
|
|
125
|
+
postgres: string;
|
|
126
|
+
mysql: string;
|
|
127
|
+
};
|
|
128
|
+
UNIQUE: {
|
|
129
|
+
sqlite: string;
|
|
130
|
+
postgres: string;
|
|
131
|
+
mysql: string;
|
|
132
|
+
};
|
|
133
|
+
DEFAULT: {
|
|
134
|
+
sqlite: string;
|
|
135
|
+
postgres: string;
|
|
136
|
+
mysql: string;
|
|
137
|
+
};
|
|
138
|
+
AUTO_INCREMENT: {
|
|
139
|
+
sqlite: string;
|
|
140
|
+
postgres: string;
|
|
141
|
+
mysql: string;
|
|
142
|
+
};
|
|
143
|
+
PRIMARY_KEY: {
|
|
144
|
+
sqlite: string;
|
|
145
|
+
postgres: string;
|
|
146
|
+
mysql: string;
|
|
94
147
|
};
|
|
95
148
|
};
|
|
96
149
|
|
|
97
|
-
export { AcceptedColumnTypes, ColumnTypeMapping };
|
|
150
|
+
export { AcceptedColumnTypes, ColumnProperties, ColumnPropertyMapping, ColumnTypeMapping };
|