relq 1.0.101 → 1.0.102
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.
|
@@ -65,7 +65,7 @@ class ConnectedInsertBuilder {
|
|
|
65
65
|
}
|
|
66
66
|
doNothing(...args) {
|
|
67
67
|
const columns = [...new Set(args.flat())];
|
|
68
|
-
this.builder._onConflict(columns, q => q.doNothing());
|
|
68
|
+
this.builder._onConflict(columns.length > 0 ? columns : null, q => q.doNothing());
|
|
69
69
|
return this;
|
|
70
70
|
}
|
|
71
71
|
doUpdate(columns, values, where) {
|
|
@@ -97,7 +97,7 @@ class InsertBuilder {
|
|
|
97
97
|
return this.insertData.length;
|
|
98
98
|
}
|
|
99
99
|
_onConflict(columns, callback) {
|
|
100
|
-
this.conflictColumns = Array.isArray(columns) ? columns : [columns];
|
|
100
|
+
this.conflictColumns = columns === null ? [] : Array.isArray(columns) ? columns : [columns];
|
|
101
101
|
this.conflictBuilder = new conflict_builder_1.ConflictBuilder(this.tableName);
|
|
102
102
|
if (callback) {
|
|
103
103
|
callback(this.conflictBuilder);
|
|
@@ -215,12 +215,11 @@ class InsertBuilder {
|
|
|
215
215
|
return { values: processedValues, placeholders: placeholderTypes.join(', ') };
|
|
216
216
|
}
|
|
217
217
|
buildConflictClause() {
|
|
218
|
-
if (!this.
|
|
218
|
+
if (!this.conflictBuilder)
|
|
219
219
|
return '';
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
let clause = (0, pg_format_1.default)(' ON CONFLICT (%I)', this.conflictColumns);
|
|
220
|
+
let clause = this.conflictColumns && this.conflictColumns.length > 0
|
|
221
|
+
? (0, pg_format_1.default)(' ON CONFLICT (%I)', this.conflictColumns)
|
|
222
|
+
: ' ON CONFLICT';
|
|
224
223
|
if (this.conflictBuilder.action === 'update') {
|
|
225
224
|
const updateSql = (0, conflict_builder_1.buildConflictUpdateSql)(this.conflictBuilder.updateData, this.tableName);
|
|
226
225
|
clause += ` DO UPDATE SET ${updateSql}`;
|
|
@@ -62,7 +62,7 @@ export class ConnectedInsertBuilder {
|
|
|
62
62
|
}
|
|
63
63
|
doNothing(...args) {
|
|
64
64
|
const columns = [...new Set(args.flat())];
|
|
65
|
-
this.builder._onConflict(columns, q => q.doNothing());
|
|
65
|
+
this.builder._onConflict(columns.length > 0 ? columns : null, q => q.doNothing());
|
|
66
66
|
return this;
|
|
67
67
|
}
|
|
68
68
|
doUpdate(columns, values, where) {
|
|
@@ -91,7 +91,7 @@ export class InsertBuilder {
|
|
|
91
91
|
return this.insertData.length;
|
|
92
92
|
}
|
|
93
93
|
_onConflict(columns, callback) {
|
|
94
|
-
this.conflictColumns = Array.isArray(columns) ? columns : [columns];
|
|
94
|
+
this.conflictColumns = columns === null ? [] : Array.isArray(columns) ? columns : [columns];
|
|
95
95
|
this.conflictBuilder = new ConflictBuilder(this.tableName);
|
|
96
96
|
if (callback) {
|
|
97
97
|
callback(this.conflictBuilder);
|
|
@@ -209,12 +209,11 @@ export class InsertBuilder {
|
|
|
209
209
|
return { values: processedValues, placeholders: placeholderTypes.join(', ') };
|
|
210
210
|
}
|
|
211
211
|
buildConflictClause() {
|
|
212
|
-
if (!this.
|
|
212
|
+
if (!this.conflictBuilder)
|
|
213
213
|
return '';
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let clause = format(' ON CONFLICT (%I)', this.conflictColumns);
|
|
214
|
+
let clause = this.conflictColumns && this.conflictColumns.length > 0
|
|
215
|
+
? format(' ON CONFLICT (%I)', this.conflictColumns)
|
|
216
|
+
: ' ON CONFLICT';
|
|
218
217
|
if (this.conflictBuilder.action === 'update') {
|
|
219
218
|
const updateSql = buildConflictUpdateSql(this.conflictBuilder.updateData, this.tableName);
|
|
220
219
|
clause += ` DO UPDATE SET ${updateSql}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -2997,7 +2997,7 @@ export declare class InsertBuilder {
|
|
|
2997
2997
|
* @internal Handle ON CONFLICT - used by ConnectedInsertBuilder
|
|
2998
2998
|
* Use .doNothing() or .doUpdate() for type-safe conflict handling
|
|
2999
2999
|
*/
|
|
3000
|
-
_onConflict(columns: string | string[], callback?: (builder: ConflictBuilder) => void): InsertBuilder;
|
|
3000
|
+
_onConflict(columns: string | string[] | null, callback?: (builder: ConflictBuilder) => void): InsertBuilder;
|
|
3001
3001
|
/**
|
|
3002
3002
|
* RETURNING clause with simple column list
|
|
3003
3003
|
*
|
|
@@ -8162,21 +8162,28 @@ declare class ConnectedInsertBuilder<TTable = any> {
|
|
|
8162
8162
|
* | MySQL | ⚠️ | Uses INSERT IGNORE (different semantics) |
|
|
8163
8163
|
* | SQLite | ✅ | Native ON CONFLICT support |
|
|
8164
8164
|
*
|
|
8165
|
-
* @param columns -
|
|
8165
|
+
* @param columns - Optional column(s) for conflict detection.
|
|
8166
|
+
* Omit to match any constraint (`ON CONFLICT DO NOTHING`).
|
|
8166
8167
|
*
|
|
8167
8168
|
* @example
|
|
8168
8169
|
* ```typescript
|
|
8170
|
+
* // Any constraint conflict
|
|
8171
|
+
* await db.table.users.insert({ email: 'test@example.com' })
|
|
8172
|
+
* .doNothing()
|
|
8173
|
+
* .run()
|
|
8174
|
+
*
|
|
8169
8175
|
* // Single column conflict
|
|
8170
8176
|
* await db.table.users.insert({ email: 'test@example.com' })
|
|
8171
8177
|
* .doNothing('email')
|
|
8172
|
-
* .
|
|
8178
|
+
* .run()
|
|
8173
8179
|
*
|
|
8174
8180
|
* // Multiple columns (composite unique constraint)
|
|
8175
8181
|
* await db.table.userRoles.insert({ userId, roleId })
|
|
8176
8182
|
* .doNothing('userId', 'roleId')
|
|
8177
|
-
* .
|
|
8183
|
+
* .run()
|
|
8178
8184
|
* ```
|
|
8179
8185
|
*/
|
|
8186
|
+
doNothing(): this;
|
|
8180
8187
|
doNothing(columns: ColumnName<TTable>[]): this;
|
|
8181
8188
|
doNothing(...columns: ColumnName<TTable>[]): this;
|
|
8182
8189
|
/**
|
|
@@ -8489,7 +8496,7 @@ declare class ConnectedQueryBuilder<TSchema = any, TTable = any> {
|
|
|
8489
8496
|
*/
|
|
8490
8497
|
insertMany(rows: Array<TTable extends {
|
|
8491
8498
|
$inferInsert: infer I;
|
|
8492
|
-
} ? I : Record<string, any>>): ConnectedInsertBuilder<TTable>;
|
|
8499
|
+
} ? I : Record<string, any>>): Omit<ConnectedInsertBuilder<TTable>, "addRow" | "addRows" | "clear" | "total">;
|
|
8493
8500
|
/**
|
|
8494
8501
|
* INSERT INTO ... SELECT — insert rows from a SELECT query.
|
|
8495
8502
|
* The callback receives all schema tables so you can build
|