@ignisia/sql 0.4.1 → 0.4.3
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/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/table.d.cts +2 -2
- package/dist/cjs/database/types.d.cts +1 -1
- package/dist/cjs/database/wrapper.d.cts +1 -1
- package/dist/cjs/{index-K07efKgt.d.cts → index-CY-nPZED.d.cts} +1 -1
- package/dist/cjs/{index-BjgeY76W.d.cts → index-DQRamRz3.d.cts} +1 -1
- 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 +1 -1
- package/dist/cjs/query/builder.d.cts +1 -1
- package/dist/cjs/query/builder.js +1 -1
- package/dist/cjs/query/compiler.d.cts +1 -1
- package/dist/cjs/query/condition/common.d.cts +1 -1
- package/dist/cjs/query/condition/core.d.cts +1 -1
- package/dist/cjs/query/condition/index.d.cts +1 -1
- package/dist/cjs/query/condition/not.d.cts +1 -1
- package/dist/cjs/query/contract.d.cts +1 -1
- package/dist/cjs/query/explain.d.cts +1 -1
- package/dist/cjs/query/helper.d.cts +1 -1
- package/dist/cjs/query/index.d.cts +1 -1
- package/dist/cjs/query/join.d.cts +1 -1
- package/dist/cjs/query/sql.d.cts +1 -1
- package/dist/cjs/query/sql.js +37 -8
- package/dist/cjs/query/types.d.cts +1 -1
- package/dist/cjs/query/utilities.d.cts +1 -1
- package/dist/cjs/table/index.d.cts +1 -1
- package/dist/cjs/table/types.d.cts +1 -1
- package/dist/cjs/table/utilities.d.cts +1 -1
- package/dist/esm/query/builder.js +1 -1
- package/dist/esm/query/sql.js +37 -8
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-DQRamRz3.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import { AcceptedColumnTypes } from '../column/constants.cjs';
|
|
4
|
-
import { T as Table, D as DatabaseDefinition } from '../index-
|
|
4
|
+
import { T as Table, D as DatabaseDefinition } from '../index-CY-nPZED.cjs';
|
|
5
5
|
import { Dialect } from '../table/constants.cjs';
|
|
6
6
|
import 'bun';
|
|
7
7
|
import '../query/constants.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-DQRamRz3.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition } from '../index-
|
|
3
|
+
import { T as Table, D as DatabaseDefinition } from '../index-CY-nPZED.cjs';
|
|
4
4
|
import { Dialect } from '../table/constants.cjs';
|
|
5
5
|
import 'bun';
|
|
6
6
|
import '../query/constants.cjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { C as ColumnAlterationContract, T as TableAlterationContract } from '../index-
|
|
1
|
+
export { C as ColumnAlterationContract, T as TableAlterationContract } from '../index-DQRamRz3.cjs';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import '../column/constants.cjs';
|
|
4
|
-
import '../index-
|
|
4
|
+
import '../index-CY-nPZED.cjs';
|
|
5
5
|
import '../table/constants.cjs';
|
|
6
6
|
import 'bun';
|
|
7
7
|
import '../query/constants.cjs';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import 'bun';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-CY-nPZED.cjs';
|
|
4
4
|
import '../query/constants.cjs';
|
|
5
5
|
import '../table/constants.cjs';
|
|
6
|
-
export { D as Database } from '../index-
|
|
6
|
+
export { D as Database } from '../index-DQRamRz3.cjs';
|
|
7
7
|
import '../column/constants.cjs';
|
|
8
8
|
import '../column/types.cjs';
|
|
9
9
|
import '../types.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-DQRamRz3.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition,
|
|
3
|
+
import { T as Table, D as DatabaseDefinition, c as TimestampOptions, M as MergeTimestampParanoid } from '../index-CY-nPZED.cjs';
|
|
4
4
|
import { Dialect } from '../table/constants.cjs';
|
|
5
5
|
import 'bun';
|
|
6
6
|
import '../query/constants.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'bun';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
|
-
export { D as DatabaseDefinition,
|
|
3
|
+
export { D as DatabaseDefinition, d as DatabaseDialect, e as DatabaseExecOptions, o as DatabaseOptions, f as MysqlConfig, P as PostgresConfig, x as SqlConfig, S as SqlConfigMapping, g as SqliteConfig } from '../index-CY-nPZED.cjs';
|
|
4
4
|
import '../table/constants.cjs';
|
|
5
5
|
import '../column/constants.cjs';
|
|
6
6
|
import '../column/types.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SQL, TransactionSQL } from 'bun';
|
|
2
2
|
import { Dialect } from '../table/constants.cjs';
|
|
3
|
-
import {
|
|
3
|
+
import { S as SqlConfigMapping, d as DatabaseDialect, e as DatabaseExecOptions, P as PostgresConfig, f as MysqlConfig, g as SqliteConfig } from '../index-CY-nPZED.cjs';
|
|
4
4
|
import '../column/index.cjs';
|
|
5
5
|
import '../column/constants.cjs';
|
|
6
6
|
import '../column/types.cjs';
|
|
@@ -497,4 +497,4 @@ declare class QueryBuilder<Alias extends TableRef['name'], TableRef extends Tabl
|
|
|
497
497
|
infer(): this['_output'];
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
-
export { clone as $, type AliasedColumn as A, deletedAt as B, type ColumnSelector as C, type DatabaseDefinition as D, type ExplainOptions as E, defineColumns as F, type GroupNode as G, type TableOptions as H, type TableOutput as I, type JoinNode as J, type ExecOptions as K, type SingleValueComparisonNode as L, type MergeTimestampParanoid as M, type MultiValueComparisonNode as N, type NullValueComparisonNode as O, type PostgresConfig as P, type QueryDefinition as Q, type RawColumn as R, type
|
|
500
|
+
export { clone as $, type AliasedColumn as A, deletedAt as B, type ColumnSelector as C, type DatabaseDefinition as D, type ExplainOptions as E, defineColumns as F, type GroupNode as G, type TableOptions as H, type TableOutput as I, type JoinNode as J, type ExecOptions as K, type SingleValueComparisonNode as L, type MergeTimestampParanoid as M, type MultiValueComparisonNode as N, type NullValueComparisonNode as O, type PostgresConfig as P, type QueryDefinition as Q, type RawColumn as R, type SqlConfigMapping as S, Table as T, type ComparisonNode as U, type NotNode as V, type WhereValue as W, type BaseJoinNode as X, type NonCrossNaturalJoinNode as Y, type CrossNaturalJoinNode as Z, alias as _, addCondition as a, col as a0, aggregateCol as a1, addGroupCondition as b, type TimestampOptions as c, type DatabaseDialect as d, type DatabaseExecOptions as e, type MysqlConfig as f, type SqliteConfig as g, type StrictColumnSelector as h, QueryBuilder as i, type SelectableColumn as j, type QueryTransformerContract as k, type QueryConditionContract as l, type AstNode as m, type QueryHooks as n, type DatabaseOptions as o, type QueryRunHooks as p, type AcceptedOrderBy as q, type AcceptedInsertValues as r, type AcceptedUpdateValues as s, type AggregateColumn as t, type SelectQueryOutput as u, type QueryOutput as v, type QueryRunHooksOptions as w, type SqlConfig as x, createdAt as y, updatedAt as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransactionSQL } from 'bun';
|
|
2
2
|
import { Column } from './column/index.cjs';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition,
|
|
3
|
+
import { T as Table, D as DatabaseDefinition, c as TimestampOptions, M as MergeTimestampParanoid, n as QueryHooks, d as DatabaseDialect, o as DatabaseOptions, i as QueryBuilder, p as QueryRunHooks } from './index-CY-nPZED.cjs';
|
|
4
4
|
import { QueryHooksType } from './query/constants.cjs';
|
|
5
5
|
import { Dialect } from './table/constants.cjs';
|
|
6
6
|
import { AcceptedColumnTypes } from './column/constants.cjs';
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Column } from './column/index.cjs';
|
|
2
|
-
export { D as Database } from './index-
|
|
2
|
+
export { D as Database } from './index-DQRamRz3.cjs';
|
|
3
3
|
export { Migration } from './migration/index.cjs';
|
|
4
|
-
export {
|
|
4
|
+
export { i as QueryBuilder, T as Table } from './index-CY-nPZED.cjs';
|
|
5
5
|
import './table/constants.cjs';
|
|
6
6
|
import './column/constants.cjs';
|
|
7
7
|
import './column/types.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Column } from '../column/index.cjs';
|
|
2
|
-
import { D as Database } from '../index-
|
|
3
|
-
import { T as Table } from '../index-
|
|
2
|
+
import { D as Database } from '../index-DQRamRz3.cjs';
|
|
3
|
+
import { T as Table } from '../index-CY-nPZED.cjs';
|
|
4
4
|
import { Dialect } from '../table/constants.cjs';
|
|
5
5
|
import { MigrationOptions, MigrationFn } from './type.cjs';
|
|
6
6
|
import '../column/constants.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Column } from '../column/index.cjs';
|
|
2
|
-
import { D as Database } from '../index-
|
|
3
|
-
import { T as Table } from '../index-
|
|
2
|
+
import { D as Database } from '../index-DQRamRz3.cjs';
|
|
3
|
+
import { T as Table } from '../index-CY-nPZED.cjs';
|
|
4
4
|
import { Dialect } from '../table/constants.cjs';
|
|
5
5
|
import '../column/constants.cjs';
|
|
6
6
|
import '../column/types.cjs';
|
package/dist/cjs/query/ast.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../column/index.cjs';
|
|
2
|
-
export {
|
|
2
|
+
export { m as AstNode, X as BaseJoinNode, U as ComparisonNode, Z as CrossNaturalJoinNode, G as GroupNode, J as JoinNode, N as MultiValueComparisonNode, Y as NonCrossNaturalJoinNode, V as NotNode, O as NullValueComparisonNode, L as SingleValueComparisonNode } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
4
|
import '../table/constants.cjs';
|
|
5
5
|
import '../column/constants.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder } from '../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import 'bun';
|
|
4
4
|
import '../types.cjs';
|
|
@@ -45,7 +45,7 @@ function buildInsertQuery(q, params) {
|
|
|
45
45
|
(row) => keys.map((key) => row[key])
|
|
46
46
|
)
|
|
47
47
|
);
|
|
48
|
-
return `INSERT INTO ${q.table.name} (${columns}) VALUES ${placeholders}
|
|
48
|
+
return `INSERT INTO ${q.table.name} (${columns}) VALUES ${placeholders}`;
|
|
49
49
|
}
|
|
50
50
|
function buildUpdateQuery(q, params) {
|
|
51
51
|
if (!q.definition?.updateValues) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dialect } from '../table/constants.cjs';
|
|
2
|
-
import {
|
|
2
|
+
import { m as AstNode, J as JoinNode } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import '../column/index.cjs';
|
|
4
4
|
import '../column/constants.cjs';
|
|
5
5
|
import '../column/types.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, W as WhereValue, i as QueryBuilder, k as QueryTransformerContract, l as QueryConditionContract, G as GroupNode } from '../../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../../column/index.cjs';
|
|
3
3
|
import { AcceptedOperator } from '../constants.cjs';
|
|
4
4
|
import 'bun';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { having, or, orGroup, where, whereGroup } from './common.cjs';
|
|
2
|
-
export { a as addCondition, b as addGroupCondition } from '../../index-
|
|
2
|
+
export { a as addCondition, b as addGroupCondition } from '../../index-CY-nPZED.cjs';
|
|
3
3
|
export { havingNot, orNot, orNotGroup, whereNot, whereNotGroup } from './not.cjs';
|
|
4
4
|
import '../../column/index.cjs';
|
|
5
5
|
import '../../table/constants.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, W as WhereValue, i as QueryBuilder, k as QueryTransformerContract, l as QueryConditionContract, G as GroupNode } from '../../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../../column/index.cjs';
|
|
3
3
|
import { AcceptedOperator } from '../constants.cjs';
|
|
4
4
|
import 'bun';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'bun';
|
|
2
|
-
export {
|
|
2
|
+
export { l as QueryConditionContract, k as QueryTransformerContract } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import '../column/index.cjs';
|
|
4
4
|
import '../table/constants.cjs';
|
|
5
5
|
import './constants.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder, E as ExplainOptions } from '../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import 'bun';
|
|
4
4
|
import '../types.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder, J as JoinNode, k as QueryTransformerContract, l as QueryConditionContract } from '../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import { AcceptedJoin } from './constants.cjs';
|
|
4
4
|
import 'bun';
|
package/dist/cjs/query/sql.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransactionSQL } from 'bun';
|
|
2
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
2
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder, E as ExplainOptions } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import { Column } from '../column/index.cjs';
|
|
4
4
|
import { Dialect } from '../table/constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
package/dist/cjs/query/sql.js
CHANGED
|
@@ -68,7 +68,7 @@ function toQuery(dialect = this.table.dialect) {
|
|
|
68
68
|
parts.push("OFFSET ?");
|
|
69
69
|
params.push(this.definition.offset);
|
|
70
70
|
}
|
|
71
|
-
if (this.definition.queryType === constants.QueryType.UPDATE || this.definition.queryType === constants.QueryType.DELETE) {
|
|
71
|
+
if (this.definition.queryType === constants.QueryType.INSERT || this.definition.queryType === constants.QueryType.UPDATE || this.definition.queryType === constants.QueryType.DELETE) {
|
|
72
72
|
if (dialect !== constants$1.Dialect.MYSQL) {
|
|
73
73
|
parts.push("RETURNING *");
|
|
74
74
|
}
|
|
@@ -109,9 +109,10 @@ async function exec(tx) {
|
|
|
109
109
|
const client = this.table.client;
|
|
110
110
|
const dialect = this.table.dialect;
|
|
111
111
|
const queryType = this.definition.queryType;
|
|
112
|
+
const isInsert = queryType === constants.QueryType.INSERT;
|
|
112
113
|
const isUpdate = queryType === constants.QueryType.UPDATE;
|
|
113
114
|
const isDelete = queryType === constants.QueryType.DELETE;
|
|
114
|
-
const isReturning = isUpdate || isDelete;
|
|
115
|
+
const isReturning = isInsert || isUpdate || isDelete;
|
|
115
116
|
const isMySQL = dialect === constants$1.Dialect.MYSQL;
|
|
116
117
|
if (!client) {
|
|
117
118
|
throw new Error("Database client not defined");
|
|
@@ -130,15 +131,43 @@ async function exec(tx) {
|
|
|
130
131
|
});
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
|
-
let result =
|
|
134
|
+
let result = [];
|
|
135
|
+
let mySqlResult = [];
|
|
136
|
+
const primaryKeyColumn = Object.entries(this.table.columns).find(
|
|
137
|
+
([, col]) => col.definition.primaryKey
|
|
138
|
+
)?.[0];
|
|
139
|
+
if (isMySQL && isDelete) {
|
|
140
|
+
const query2 = this.clone().select(`${this.table.name}.*`);
|
|
141
|
+
mySqlResult = await client.exec({
|
|
142
|
+
sql: query2.toQuery().query,
|
|
143
|
+
params,
|
|
144
|
+
tx
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
result = await client.exec({
|
|
134
148
|
sql: query,
|
|
135
149
|
params,
|
|
136
150
|
tx
|
|
137
151
|
});
|
|
138
|
-
if (isMySQL &&
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
if (isMySQL && isInsert && primaryKeyColumn) {
|
|
153
|
+
const insertResult = result;
|
|
154
|
+
const lastId = insertResult.lastInsertRowid;
|
|
155
|
+
if (lastId != null) {
|
|
156
|
+
const selectQuery = this.table.query().where(
|
|
157
|
+
`${this.table.name}."${primaryKeyColumn}"`,
|
|
158
|
+
"eq",
|
|
159
|
+
lastId
|
|
160
|
+
);
|
|
161
|
+
mySqlResult = await client.exec({
|
|
162
|
+
sql: selectQuery.toQuery().query,
|
|
163
|
+
params: selectQuery.toQuery().params,
|
|
164
|
+
tx
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (isMySQL && isUpdate) {
|
|
169
|
+
const query2 = this.clone().select(`${this.table.name}.*`);
|
|
170
|
+
mySqlResult = await client.exec({
|
|
142
171
|
sql: query2.toQuery().query,
|
|
143
172
|
params,
|
|
144
173
|
tx
|
|
@@ -154,7 +183,7 @@ async function exec(tx) {
|
|
|
154
183
|
});
|
|
155
184
|
}
|
|
156
185
|
}
|
|
157
|
-
return result.map(
|
|
186
|
+
return (isMySQL && isReturning ? mySqlResult : result).map(
|
|
158
187
|
(r) => utilities.parseAliasedRow({
|
|
159
188
|
row: r,
|
|
160
189
|
selects: this.definition.select ?? [],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'bun';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import '../column/constants.cjs';
|
|
4
|
-
export { r as AcceptedInsertValues, q as AcceptedOrderBy, s as AcceptedUpdateValues, t as AggregateColumn, A as AliasedColumn, C as ColumnSelector, E as ExplainOptions, Q as QueryDefinition, n as QueryHooks, v as QueryOutput, p as QueryRunHooks, w as QueryRunHooksOptions, R as RawColumn, u as SelectQueryOutput,
|
|
4
|
+
export { r as AcceptedInsertValues, q as AcceptedOrderBy, s as AcceptedUpdateValues, t as AggregateColumn, A as AliasedColumn, C as ColumnSelector, E as ExplainOptions, Q as QueryDefinition, n as QueryHooks, v as QueryOutput, p as QueryRunHooks, w as QueryRunHooksOptions, R as RawColumn, u as SelectQueryOutput, j as SelectableColumn, h as StrictColumnSelector, W as WhereValue } from '../index-CY-nPZED.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
6
6
|
import './constants.cjs';
|
|
7
7
|
import '../table/constants.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder, A as AliasedColumn, j as SelectableColumn } from '../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
3
|
import 'bun';
|
|
4
4
|
import '../types.cjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'bun';
|
|
2
|
-
export { K as ExecOptions, M as MergeTimestampParanoid, H as TableOptions, I as TableOutput,
|
|
2
|
+
export { K as ExecOptions, M as MergeTimestampParanoid, H as TableOptions, I as TableOutput, c as TimestampOptions } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import '../column/index.cjs';
|
|
4
4
|
import './constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../column/constants.cjs';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
|
-
export { y as createdAt, F as defineColumns, B as deletedAt, z as updatedAt } from '../index-
|
|
4
|
+
export { y as createdAt, F as defineColumns, B as deletedAt, z as updatedAt } from '../index-CY-nPZED.cjs';
|
|
5
5
|
import '../column/types.cjs';
|
|
6
6
|
import 'bun';
|
|
7
7
|
import '../types.cjs';
|
|
@@ -44,7 +44,7 @@ function buildInsertQuery(q, params) {
|
|
|
44
44
|
(row) => keys.map((key) => row[key])
|
|
45
45
|
)
|
|
46
46
|
);
|
|
47
|
-
return `INSERT INTO ${q.table.name} (${columns}) VALUES ${placeholders}
|
|
47
|
+
return `INSERT INTO ${q.table.name} (${columns}) VALUES ${placeholders}`;
|
|
48
48
|
}
|
|
49
49
|
function buildUpdateQuery(q, params) {
|
|
50
50
|
if (!q.definition?.updateValues) {
|
package/dist/esm/query/sql.js
CHANGED
|
@@ -67,7 +67,7 @@ function toQuery(dialect = this.table.dialect) {
|
|
|
67
67
|
parts.push("OFFSET ?");
|
|
68
68
|
params.push(this.definition.offset);
|
|
69
69
|
}
|
|
70
|
-
if (this.definition.queryType === QueryType.UPDATE || this.definition.queryType === QueryType.DELETE) {
|
|
70
|
+
if (this.definition.queryType === QueryType.INSERT || this.definition.queryType === QueryType.UPDATE || this.definition.queryType === QueryType.DELETE) {
|
|
71
71
|
if (dialect !== Dialect.MYSQL) {
|
|
72
72
|
parts.push("RETURNING *");
|
|
73
73
|
}
|
|
@@ -108,9 +108,10 @@ async function exec(tx) {
|
|
|
108
108
|
const client = this.table.client;
|
|
109
109
|
const dialect = this.table.dialect;
|
|
110
110
|
const queryType = this.definition.queryType;
|
|
111
|
+
const isInsert = queryType === QueryType.INSERT;
|
|
111
112
|
const isUpdate = queryType === QueryType.UPDATE;
|
|
112
113
|
const isDelete = queryType === QueryType.DELETE;
|
|
113
|
-
const isReturning = isUpdate || isDelete;
|
|
114
|
+
const isReturning = isInsert || isUpdate || isDelete;
|
|
114
115
|
const isMySQL = dialect === Dialect.MYSQL;
|
|
115
116
|
if (!client) {
|
|
116
117
|
throw new Error("Database client not defined");
|
|
@@ -129,15 +130,43 @@ async function exec(tx) {
|
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
|
-
let result =
|
|
133
|
+
let result = [];
|
|
134
|
+
let mySqlResult = [];
|
|
135
|
+
const primaryKeyColumn = Object.entries(this.table.columns).find(
|
|
136
|
+
([, col]) => col.definition.primaryKey
|
|
137
|
+
)?.[0];
|
|
138
|
+
if (isMySQL && isDelete) {
|
|
139
|
+
const query2 = this.clone().select(`${this.table.name}.*`);
|
|
140
|
+
mySqlResult = await client.exec({
|
|
141
|
+
sql: query2.toQuery().query,
|
|
142
|
+
params,
|
|
143
|
+
tx
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
result = await client.exec({
|
|
133
147
|
sql: query,
|
|
134
148
|
params,
|
|
135
149
|
tx
|
|
136
150
|
});
|
|
137
|
-
if (isMySQL &&
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
if (isMySQL && isInsert && primaryKeyColumn) {
|
|
152
|
+
const insertResult = result;
|
|
153
|
+
const lastId = insertResult.lastInsertRowid;
|
|
154
|
+
if (lastId != null) {
|
|
155
|
+
const selectQuery = this.table.query().where(
|
|
156
|
+
`${this.table.name}."${primaryKeyColumn}"`,
|
|
157
|
+
"eq",
|
|
158
|
+
lastId
|
|
159
|
+
);
|
|
160
|
+
mySqlResult = await client.exec({
|
|
161
|
+
sql: selectQuery.toQuery().query,
|
|
162
|
+
params: selectQuery.toQuery().params,
|
|
163
|
+
tx
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (isMySQL && isUpdate) {
|
|
168
|
+
const query2 = this.clone().select(`${this.table.name}.*`);
|
|
169
|
+
mySqlResult = await client.exec({
|
|
141
170
|
sql: query2.toQuery().query,
|
|
142
171
|
params,
|
|
143
172
|
tx
|
|
@@ -153,7 +182,7 @@ async function exec(tx) {
|
|
|
153
182
|
});
|
|
154
183
|
}
|
|
155
184
|
}
|
|
156
|
-
return result.map(
|
|
185
|
+
return (isMySQL && isReturning ? mySqlResult : result).map(
|
|
157
186
|
(r) => parseAliasedRow({
|
|
158
187
|
row: r,
|
|
159
188
|
selects: this.definition.select ?? [],
|