arkormx 2.0.0-next.20 → 2.0.0-next.22
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/index.cjs +346 -9
- package/dist/index.d.cts +136 -12
- package/dist/index.d.mts +136 -12
- package/dist/index.mjs +346 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2384,7 +2384,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
2384
2384
|
relationLoads: false,
|
|
2385
2385
|
relationAggregates: true,
|
|
2386
2386
|
relationFilters: true,
|
|
2387
|
-
rawWhere:
|
|
2387
|
+
rawWhere: true
|
|
2388
2388
|
};
|
|
2389
2389
|
constructor(db, mapping = {}) {
|
|
2390
2390
|
this.db = db;
|
|
@@ -2669,6 +2669,18 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
2669
2669
|
if (condition.operator === "ends-with") return kysely.sql`${column} like ${`%${String(condition.value ?? "")}`}`;
|
|
2670
2670
|
return kysely.sql`${column} ${condition.operator === "!=" ? kysely.sql.raw("!=") : kysely.sql.raw(condition.operator)} ${condition.value}`;
|
|
2671
2671
|
}
|
|
2672
|
+
buildRawWhereCondition(condition) {
|
|
2673
|
+
const segments = condition.sql.split("?");
|
|
2674
|
+
const bindings = condition.bindings ?? [];
|
|
2675
|
+
if (segments.length !== bindings.length + 1) throw new ArkormException("Raw where bindings do not match the number of placeholders.");
|
|
2676
|
+
const parts = [];
|
|
2677
|
+
segments.forEach((segment, index) => {
|
|
2678
|
+
if (segment.length > 0) parts.push(kysely.sql.raw(segment));
|
|
2679
|
+
if (index < bindings.length) parts.push(kysely.sql`${bindings[index]}`);
|
|
2680
|
+
});
|
|
2681
|
+
if (parts.length === 0) return kysely.sql`1 = 1`;
|
|
2682
|
+
return kysely.sql`${kysely.sql.join(parts, kysely.sql``)}`;
|
|
2683
|
+
}
|
|
2672
2684
|
buildWhereCondition(target, condition) {
|
|
2673
2685
|
if (!condition) return kysely.sql`1 = 1`;
|
|
2674
2686
|
if (condition.type === "comparison") return this.buildComparisonCondition(target, condition);
|
|
@@ -2685,13 +2697,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
2685
2697
|
const notCondition = condition;
|
|
2686
2698
|
return kysely.sql`not (${this.buildWhereCondition(target, notCondition.condition)})`;
|
|
2687
2699
|
}
|
|
2688
|
-
|
|
2689
|
-
operation: "adapter.where",
|
|
2690
|
-
meta: {
|
|
2691
|
-
feature: "rawWhere",
|
|
2692
|
-
sql: condition.sql
|
|
2693
|
-
}
|
|
2694
|
-
});
|
|
2700
|
+
return this.buildRawWhereCondition(condition);
|
|
2695
2701
|
}
|
|
2696
2702
|
buildWhereClause(target, condition) {
|
|
2697
2703
|
if (!condition) return kysely.sql``;
|
|
@@ -6701,6 +6707,36 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6701
6707
|
return this.where({ [key]: { notIn: values } });
|
|
6702
6708
|
}
|
|
6703
6709
|
/**
|
|
6710
|
+
* Adds a string contains clause for a single attribute key.
|
|
6711
|
+
*
|
|
6712
|
+
* @param key
|
|
6713
|
+
* @param value
|
|
6714
|
+
* @returns
|
|
6715
|
+
*/
|
|
6716
|
+
whereLike(key, value) {
|
|
6717
|
+
return this.where({ [key]: { contains: value } });
|
|
6718
|
+
}
|
|
6719
|
+
/**
|
|
6720
|
+
* Adds a string starts-with clause for a single attribute key.
|
|
6721
|
+
*
|
|
6722
|
+
* @param key
|
|
6723
|
+
* @param value
|
|
6724
|
+
* @returns
|
|
6725
|
+
*/
|
|
6726
|
+
whereStartsWith(key, value) {
|
|
6727
|
+
return this.where({ [key]: { startsWith: value } });
|
|
6728
|
+
}
|
|
6729
|
+
/**
|
|
6730
|
+
* Adds a string ends-with clause for a single attribute key.
|
|
6731
|
+
*
|
|
6732
|
+
* @param key
|
|
6733
|
+
* @param value
|
|
6734
|
+
* @returns
|
|
6735
|
+
*/
|
|
6736
|
+
whereEndsWith(key, value) {
|
|
6737
|
+
return this.where({ [key]: { endsWith: value } });
|
|
6738
|
+
}
|
|
6739
|
+
/**
|
|
6704
6740
|
* Adds a strongly-typed OR NOT IN where clause for a single attribute key.
|
|
6705
6741
|
*
|
|
6706
6742
|
* @param key
|
|
@@ -8825,6 +8861,36 @@ var Relation = class {
|
|
|
8825
8861
|
return this.constrain((query) => query.whereIn(key, values));
|
|
8826
8862
|
}
|
|
8827
8863
|
/**
|
|
8864
|
+
* Add a string contains clause to the relationship query.
|
|
8865
|
+
*
|
|
8866
|
+
* @param key
|
|
8867
|
+
* @param value
|
|
8868
|
+
* @returns
|
|
8869
|
+
*/
|
|
8870
|
+
whereLike(key, value) {
|
|
8871
|
+
return this.constrain((query) => query.whereLike(key, value));
|
|
8872
|
+
}
|
|
8873
|
+
/**
|
|
8874
|
+
* Add a string starts-with clause to the relationship query.
|
|
8875
|
+
*
|
|
8876
|
+
* @param key
|
|
8877
|
+
* @param value
|
|
8878
|
+
* @returns
|
|
8879
|
+
*/
|
|
8880
|
+
whereStartsWith(key, value) {
|
|
8881
|
+
return this.constrain((query) => query.whereStartsWith(key, value));
|
|
8882
|
+
}
|
|
8883
|
+
/**
|
|
8884
|
+
* Add a string ends-with clause to the relationship query.
|
|
8885
|
+
*
|
|
8886
|
+
* @param key
|
|
8887
|
+
* @param value
|
|
8888
|
+
* @returns
|
|
8889
|
+
*/
|
|
8890
|
+
whereEndsWith(key, value) {
|
|
8891
|
+
return this.constrain((query) => query.whereEndsWith(key, value));
|
|
8892
|
+
}
|
|
8893
|
+
/**
|
|
8828
8894
|
* Add an order by clause to the relationship query.
|
|
8829
8895
|
*
|
|
8830
8896
|
* @param orderBy
|
|
@@ -9154,6 +9220,277 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9154
9220
|
conditions: [baseCondition, this.pivotWhere]
|
|
9155
9221
|
};
|
|
9156
9222
|
}
|
|
9223
|
+
buildPivotTarget() {
|
|
9224
|
+
return {
|
|
9225
|
+
table: this.throughDelegate,
|
|
9226
|
+
primaryKey: this.relatedPivotKey
|
|
9227
|
+
};
|
|
9228
|
+
}
|
|
9229
|
+
buildRelatedPivotCondition(relatedValues) {
|
|
9230
|
+
const normalizedValues = relatedValues.filter((value) => value != null);
|
|
9231
|
+
if (normalizedValues.length === 0) return null;
|
|
9232
|
+
if (normalizedValues.length === 1) return {
|
|
9233
|
+
type: "comparison",
|
|
9234
|
+
column: this.relatedPivotKey,
|
|
9235
|
+
operator: "=",
|
|
9236
|
+
value: normalizedValues[0]
|
|
9237
|
+
};
|
|
9238
|
+
return {
|
|
9239
|
+
type: "comparison",
|
|
9240
|
+
column: this.relatedPivotKey,
|
|
9241
|
+
operator: "in",
|
|
9242
|
+
value: normalizedValues
|
|
9243
|
+
};
|
|
9244
|
+
}
|
|
9245
|
+
buildPivotMutationWhere(relatedValues = []) {
|
|
9246
|
+
const baseCondition = this.buildPivotWhere(this.resolveParentPivotValue());
|
|
9247
|
+
const relatedCondition = this.buildRelatedPivotCondition(relatedValues);
|
|
9248
|
+
if (!relatedCondition) return baseCondition;
|
|
9249
|
+
return {
|
|
9250
|
+
type: "group",
|
|
9251
|
+
operator: "and",
|
|
9252
|
+
conditions: [baseCondition, relatedCondition]
|
|
9253
|
+
};
|
|
9254
|
+
}
|
|
9255
|
+
normalizeIdentifierValue(value) {
|
|
9256
|
+
if (typeof value === "string" && /^-?\d+$/.test(value)) return Number(value);
|
|
9257
|
+
return value;
|
|
9258
|
+
}
|
|
9259
|
+
isPlainObject(value) {
|
|
9260
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
9261
|
+
}
|
|
9262
|
+
isModelLike(value) {
|
|
9263
|
+
return this.isPlainObject(value) && typeof value.getAttribute === "function";
|
|
9264
|
+
}
|
|
9265
|
+
normalizeRelatedItems(related) {
|
|
9266
|
+
return Array.isArray(related) ? related : [related];
|
|
9267
|
+
}
|
|
9268
|
+
normalizeSyncEntries(related, pivotAttributes = {}) {
|
|
9269
|
+
if (Array.isArray(related)) return related.map((item) => ({
|
|
9270
|
+
related: item,
|
|
9271
|
+
attributes: { ...pivotAttributes }
|
|
9272
|
+
}));
|
|
9273
|
+
if (this.isPlainObject(related) && !this.isModelLike(related)) return Object.entries(related).map(([key, attributes]) => ({
|
|
9274
|
+
related: this.normalizeIdentifierValue(key),
|
|
9275
|
+
attributes: this.isPlainObject(attributes) ? attributes : {}
|
|
9276
|
+
}));
|
|
9277
|
+
return [{
|
|
9278
|
+
related,
|
|
9279
|
+
attributes: { ...pivotAttributes }
|
|
9280
|
+
}];
|
|
9281
|
+
}
|
|
9282
|
+
resolveParentPivotValue() {
|
|
9283
|
+
return this.parent.getAttribute(this.parentKey);
|
|
9284
|
+
}
|
|
9285
|
+
resolveRelatedPivotValue(related) {
|
|
9286
|
+
if (related && typeof related === "object" && "getAttribute" in related) return related.getAttribute(this.relatedKey);
|
|
9287
|
+
return related;
|
|
9288
|
+
}
|
|
9289
|
+
buildPivotInsertValues(related, attributes = {}) {
|
|
9290
|
+
const values = {
|
|
9291
|
+
...attributes,
|
|
9292
|
+
[this.foreignPivotKey]: this.resolveParentPivotValue(),
|
|
9293
|
+
[this.relatedPivotKey]: this.resolveRelatedPivotValue(related)
|
|
9294
|
+
};
|
|
9295
|
+
if (this.pivotCreatedAtColumn && !(this.pivotCreatedAtColumn in values)) values[this.pivotCreatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9296
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9297
|
+
return values;
|
|
9298
|
+
}
|
|
9299
|
+
attachPivotToSingleResult(related, pivotRow) {
|
|
9300
|
+
if (!this.shouldAttachPivotAttributes()) return related;
|
|
9301
|
+
related.setAttribute(this.pivotAccessor, this.createPivotRecord(pivotRow));
|
|
9302
|
+
return related;
|
|
9303
|
+
}
|
|
9304
|
+
async insertPivotRow(values, adapter = this.getRelationAdapter()) {
|
|
9305
|
+
await adapter.insert({
|
|
9306
|
+
target: this.buildPivotTarget(),
|
|
9307
|
+
values
|
|
9308
|
+
});
|
|
9309
|
+
}
|
|
9310
|
+
async selectPivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9311
|
+
return await adapter.select({
|
|
9312
|
+
target: this.buildPivotTarget(),
|
|
9313
|
+
where
|
|
9314
|
+
});
|
|
9315
|
+
}
|
|
9316
|
+
async deletePivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9317
|
+
if (typeof adapter.deleteMany === "function") return await adapter.deleteMany({
|
|
9318
|
+
target: this.buildPivotTarget(),
|
|
9319
|
+
where
|
|
9320
|
+
});
|
|
9321
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9322
|
+
await Promise.all(rows.map(async (row) => {
|
|
9323
|
+
await adapter.delete({
|
|
9324
|
+
target: this.buildPivotTarget(),
|
|
9325
|
+
where: {
|
|
9326
|
+
type: "group",
|
|
9327
|
+
operator: "and",
|
|
9328
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9329
|
+
type: "comparison",
|
|
9330
|
+
column,
|
|
9331
|
+
operator: "=",
|
|
9332
|
+
value
|
|
9333
|
+
}))
|
|
9334
|
+
}
|
|
9335
|
+
});
|
|
9336
|
+
}));
|
|
9337
|
+
return rows.length;
|
|
9338
|
+
}
|
|
9339
|
+
buildPivotUpdateValues(attributes = {}) {
|
|
9340
|
+
const values = { ...attributes };
|
|
9341
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9342
|
+
return values;
|
|
9343
|
+
}
|
|
9344
|
+
async updatePivotRows(related, attributes, adapter = this.getRelationAdapter()) {
|
|
9345
|
+
const values = this.buildPivotUpdateValues(attributes);
|
|
9346
|
+
if (Object.keys(values).length === 0) return 0;
|
|
9347
|
+
const where = this.buildPivotMutationWhere([this.resolveRelatedPivotValue(related)]);
|
|
9348
|
+
if (typeof adapter.updateMany === "function") return await adapter.updateMany({
|
|
9349
|
+
target: this.buildPivotTarget(),
|
|
9350
|
+
where,
|
|
9351
|
+
values
|
|
9352
|
+
});
|
|
9353
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9354
|
+
await Promise.all(rows.map(async (row) => {
|
|
9355
|
+
await adapter.update({
|
|
9356
|
+
target: this.buildPivotTarget(),
|
|
9357
|
+
where: {
|
|
9358
|
+
type: "group",
|
|
9359
|
+
operator: "and",
|
|
9360
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9361
|
+
type: "comparison",
|
|
9362
|
+
column,
|
|
9363
|
+
operator: "=",
|
|
9364
|
+
value
|
|
9365
|
+
}))
|
|
9366
|
+
},
|
|
9367
|
+
values
|
|
9368
|
+
});
|
|
9369
|
+
}));
|
|
9370
|
+
return rows.length;
|
|
9371
|
+
}
|
|
9372
|
+
/**
|
|
9373
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
9374
|
+
* pivot attributes if pivot attributes should be included.
|
|
9375
|
+
*
|
|
9376
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9377
|
+
* @returns A new instance of the related model.
|
|
9378
|
+
*/
|
|
9379
|
+
make(attributes = {}) {
|
|
9380
|
+
return this.related.hydrate(attributes);
|
|
9381
|
+
}
|
|
9382
|
+
/**
|
|
9383
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
9384
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
9385
|
+
* should be included.
|
|
9386
|
+
*
|
|
9387
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9388
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9389
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9390
|
+
*/
|
|
9391
|
+
async create(attributes = {}, pivotAttributes = {}) {
|
|
9392
|
+
const related = await this.related.query().create(attributes);
|
|
9393
|
+
const pivotRow = this.buildPivotInsertValues(related, pivotAttributes);
|
|
9394
|
+
await this.insertPivotRow(pivotRow);
|
|
9395
|
+
return this.attachPivotToSingleResult(related, pivotRow);
|
|
9396
|
+
}
|
|
9397
|
+
/**
|
|
9398
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
9399
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
9400
|
+
* pivot attributes should be included.
|
|
9401
|
+
*
|
|
9402
|
+
* @param related The related model instance to save.
|
|
9403
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9404
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9405
|
+
*/
|
|
9406
|
+
async save(related, pivotAttributes = {}) {
|
|
9407
|
+
const saveable = related;
|
|
9408
|
+
let persisted = related;
|
|
9409
|
+
if (typeof saveable.save === "function") try {
|
|
9410
|
+
persisted = await saveable.save();
|
|
9411
|
+
} catch (error) {
|
|
9412
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "MODEL_NOT_FOUND")) throw error;
|
|
9413
|
+
const attributes = typeof saveable.getRawAttributes === "function" ? saveable.getRawAttributes() : {};
|
|
9414
|
+
persisted = await this.related.query().create(attributes);
|
|
9415
|
+
}
|
|
9416
|
+
const pivotRow = this.buildPivotInsertValues(persisted, pivotAttributes);
|
|
9417
|
+
await this.insertPivotRow(pivotRow);
|
|
9418
|
+
return this.attachPivotToSingleResult(persisted, pivotRow);
|
|
9419
|
+
}
|
|
9420
|
+
/**
|
|
9421
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
9422
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
9423
|
+
*
|
|
9424
|
+
* @param related The related model instance(s) to attach.
|
|
9425
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9426
|
+
* @returns The number of related model records attached.
|
|
9427
|
+
*/
|
|
9428
|
+
async attach(related, pivotAttributes = {}) {
|
|
9429
|
+
const items = Array.isArray(related) ? related : [related];
|
|
9430
|
+
await Promise.all(items.map(async (item) => {
|
|
9431
|
+
await this.insertPivotRow(this.buildPivotInsertValues(item, pivotAttributes));
|
|
9432
|
+
}));
|
|
9433
|
+
return items.length;
|
|
9434
|
+
}
|
|
9435
|
+
/**
|
|
9436
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
9437
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
9438
|
+
* for the parent are removed.
|
|
9439
|
+
*
|
|
9440
|
+
* @param related
|
|
9441
|
+
* @returns
|
|
9442
|
+
*/
|
|
9443
|
+
async detach(related) {
|
|
9444
|
+
const where = related === void 0 ? this.buildPivotWhere(this.resolveParentPivotValue()) : this.buildPivotMutationWhere(this.normalizeRelatedItems(related).map((item) => this.resolveRelatedPivotValue(item)));
|
|
9445
|
+
return await this.deletePivotRows(where);
|
|
9446
|
+
}
|
|
9447
|
+
/**
|
|
9448
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
9449
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
9450
|
+
*
|
|
9451
|
+
* @param related
|
|
9452
|
+
* @param pivotAttributes
|
|
9453
|
+
* @returns
|
|
9454
|
+
*/
|
|
9455
|
+
async sync(related, pivotAttributes = {}) {
|
|
9456
|
+
return await this.getRelationAdapter().transaction(async (transaction) => {
|
|
9457
|
+
const existingRows = await this.selectPivotRows(this.buildPivotWhere(this.resolveParentPivotValue()), transaction);
|
|
9458
|
+
const desiredEntries = /* @__PURE__ */ new Map();
|
|
9459
|
+
this.normalizeSyncEntries(related, pivotAttributes).forEach((entry) => {
|
|
9460
|
+
const relatedValue = this.resolveRelatedPivotValue(entry.related);
|
|
9461
|
+
if (relatedValue == null) return;
|
|
9462
|
+
desiredEntries.set(String(relatedValue), {
|
|
9463
|
+
related: relatedValue,
|
|
9464
|
+
attributes: entry.attributes
|
|
9465
|
+
});
|
|
9466
|
+
});
|
|
9467
|
+
let detached = 0;
|
|
9468
|
+
let attached = 0;
|
|
9469
|
+
let updated = 0;
|
|
9470
|
+
const existingKeys = /* @__PURE__ */ new Set();
|
|
9471
|
+
for (const row of existingRows) {
|
|
9472
|
+
const relatedValue = row[this.relatedPivotKey];
|
|
9473
|
+
if (relatedValue == null) continue;
|
|
9474
|
+
const relatedKey = String(relatedValue);
|
|
9475
|
+
existingKeys.add(relatedKey);
|
|
9476
|
+
if (!desiredEntries.has(relatedKey)) detached += await this.deletePivotRows(this.buildPivotMutationWhere([relatedValue]), transaction);
|
|
9477
|
+
}
|
|
9478
|
+
for (const [relatedKey, entry] of desiredEntries) {
|
|
9479
|
+
if (!existingKeys.has(relatedKey)) {
|
|
9480
|
+
await this.insertPivotRow(this.buildPivotInsertValues(entry.related, entry.attributes), transaction);
|
|
9481
|
+
attached += 1;
|
|
9482
|
+
continue;
|
|
9483
|
+
}
|
|
9484
|
+
if (Object.keys(entry.attributes).length === 0) continue;
|
|
9485
|
+
updated += await this.updatePivotRows(entry.related, entry.attributes, transaction);
|
|
9486
|
+
}
|
|
9487
|
+
return {
|
|
9488
|
+
attached,
|
|
9489
|
+
detached,
|
|
9490
|
+
updated
|
|
9491
|
+
};
|
|
9492
|
+
});
|
|
9493
|
+
}
|
|
9157
9494
|
shouldAttachPivotAttributes() {
|
|
9158
9495
|
return this.shouldAttachPivot || this.pivotColumns.size > 0 || Boolean(this.pivotCreatedAtColumn) || Boolean(this.pivotUpdatedAtColumn) || Boolean(this.pivotModel);
|
|
9159
9496
|
}
|
|
@@ -9239,7 +9576,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9239
9576
|
return query;
|
|
9240
9577
|
}
|
|
9241
9578
|
async loadPivotRowsForParent() {
|
|
9242
|
-
const parentValue = this.
|
|
9579
|
+
const parentValue = this.resolveParentPivotValue();
|
|
9243
9580
|
return await this.createRelationTableLoader().selectRows({
|
|
9244
9581
|
table: this.throughDelegate,
|
|
9245
9582
|
where: this.buildPivotWhere(parentValue),
|
package/dist/index.d.cts
CHANGED
|
@@ -554,6 +554,30 @@ declare abstract class Relation<TModel> {
|
|
|
554
554
|
* @returns
|
|
555
555
|
*/
|
|
556
556
|
whereIn<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, values: ModelAttributes<TModel>[TKey][]): this;
|
|
557
|
+
/**
|
|
558
|
+
* Add a string contains clause to the relationship query.
|
|
559
|
+
*
|
|
560
|
+
* @param key
|
|
561
|
+
* @param value
|
|
562
|
+
* @returns
|
|
563
|
+
*/
|
|
564
|
+
whereLike<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
565
|
+
/**
|
|
566
|
+
* Add a string starts-with clause to the relationship query.
|
|
567
|
+
*
|
|
568
|
+
* @param key
|
|
569
|
+
* @param value
|
|
570
|
+
* @returns
|
|
571
|
+
*/
|
|
572
|
+
whereStartsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
573
|
+
/**
|
|
574
|
+
* Add a string ends-with clause to the relationship query.
|
|
575
|
+
*
|
|
576
|
+
* @param key
|
|
577
|
+
* @param value
|
|
578
|
+
* @returns
|
|
579
|
+
*/
|
|
580
|
+
whereEndsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
557
581
|
/**
|
|
558
582
|
* Add an order by clause to the relationship query.
|
|
559
583
|
*
|
|
@@ -791,6 +815,82 @@ declare class BelongsToManyRelation<TParent, TRelated> extends Relation<TRelated
|
|
|
791
815
|
private addPivotWhere;
|
|
792
816
|
private makePivotComparison;
|
|
793
817
|
private buildPivotWhere;
|
|
818
|
+
private buildPivotTarget;
|
|
819
|
+
private buildRelatedPivotCondition;
|
|
820
|
+
private buildPivotMutationWhere;
|
|
821
|
+
private normalizeIdentifierValue;
|
|
822
|
+
private isPlainObject;
|
|
823
|
+
private isModelLike;
|
|
824
|
+
private normalizeRelatedItems;
|
|
825
|
+
private normalizeSyncEntries;
|
|
826
|
+
private resolveParentPivotValue;
|
|
827
|
+
private resolveRelatedPivotValue;
|
|
828
|
+
private buildPivotInsertValues;
|
|
829
|
+
private attachPivotToSingleResult;
|
|
830
|
+
private insertPivotRow;
|
|
831
|
+
private selectPivotRows;
|
|
832
|
+
private deletePivotRows;
|
|
833
|
+
private buildPivotUpdateValues;
|
|
834
|
+
private updatePivotRows;
|
|
835
|
+
/**
|
|
836
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
837
|
+
* pivot attributes if pivot attributes should be included.
|
|
838
|
+
*
|
|
839
|
+
* @param attributes The attributes to initialize the related model with.
|
|
840
|
+
* @returns A new instance of the related model.
|
|
841
|
+
*/
|
|
842
|
+
make(attributes?: Record<string, unknown>): TRelated;
|
|
843
|
+
/**
|
|
844
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
845
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
846
|
+
* should be included.
|
|
847
|
+
*
|
|
848
|
+
* @param attributes The attributes to initialize the related model with.
|
|
849
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
850
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
851
|
+
*/
|
|
852
|
+
create(attributes?: Record<string, unknown>, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
853
|
+
/**
|
|
854
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
855
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
856
|
+
* pivot attributes should be included.
|
|
857
|
+
*
|
|
858
|
+
* @param related The related model instance to save.
|
|
859
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
860
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
861
|
+
*/
|
|
862
|
+
save(related: TRelated, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
863
|
+
/**
|
|
864
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
865
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
866
|
+
*
|
|
867
|
+
* @param related The related model instance(s) to attach.
|
|
868
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
869
|
+
* @returns The number of related model records attached.
|
|
870
|
+
*/
|
|
871
|
+
attach(related: TRelated | unknown | Array<TRelated | unknown>, pivotAttributes?: Record<string, unknown>): Promise<number>;
|
|
872
|
+
/**
|
|
873
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
874
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
875
|
+
* for the parent are removed.
|
|
876
|
+
*
|
|
877
|
+
* @param related
|
|
878
|
+
* @returns
|
|
879
|
+
*/
|
|
880
|
+
detach(related?: TRelated | unknown | Array<TRelated | unknown>): Promise<number>;
|
|
881
|
+
/**
|
|
882
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
883
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
884
|
+
*
|
|
885
|
+
* @param related
|
|
886
|
+
* @param pivotAttributes
|
|
887
|
+
* @returns
|
|
888
|
+
*/
|
|
889
|
+
sync(related: TRelated | unknown | Array<TRelated | unknown> | Record<string, Record<string, unknown>>, pivotAttributes?: Record<string, unknown>): Promise<{
|
|
890
|
+
attached: number;
|
|
891
|
+
detached: number;
|
|
892
|
+
updated: number;
|
|
893
|
+
}>;
|
|
794
894
|
private shouldAttachPivotAttributes;
|
|
795
895
|
private getPivotColumnSelection;
|
|
796
896
|
/**
|
|
@@ -1343,7 +1443,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1343
1443
|
* @param this
|
|
1344
1444
|
* @returns
|
|
1345
1445
|
*/
|
|
1346
|
-
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1446
|
+
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1347
1447
|
/**
|
|
1348
1448
|
* Boot hook for subclasses to register scopes or perform one-time setup.
|
|
1349
1449
|
*/
|
|
@@ -1358,14 +1458,14 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1358
1458
|
* @param this
|
|
1359
1459
|
* @returns
|
|
1360
1460
|
*/
|
|
1361
|
-
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1461
|
+
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1362
1462
|
/**
|
|
1363
1463
|
* Get a query builder instance that only includes soft-deleted records.
|
|
1364
1464
|
*
|
|
1365
1465
|
* @param this
|
|
1366
1466
|
* @returns
|
|
1367
1467
|
*/
|
|
1368
|
-
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1468
|
+
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1369
1469
|
/**
|
|
1370
1470
|
* Get a query builder instance that excludes soft-deleted records.
|
|
1371
1471
|
* This is the default behavior of the query builder, but this method can be used
|
|
@@ -1376,7 +1476,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1376
1476
|
* @param args
|
|
1377
1477
|
* @returns
|
|
1378
1478
|
*/
|
|
1379
|
-
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1479
|
+
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, name: string, ...args: unknown[]): QueryBuilder<TModel, TDelegate>;
|
|
1380
1480
|
/**
|
|
1381
1481
|
* Get the soft delete configuration for the model, including whether
|
|
1382
1482
|
* soft deletes are enabled and the name of the deleted at column.
|
|
@@ -1431,9 +1531,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1431
1531
|
* @param key
|
|
1432
1532
|
* @returns
|
|
1433
1533
|
*/
|
|
1434
|
-
getAttribute<TKey extends
|
|
1435
|
-
getAttribute<TKey extends keyof this & string>(key: TKey): this[TKey] extends ((...args: any[]) => any) ? unknown : this[TKey];
|
|
1436
|
-
getAttribute<TKey extends keyof TAttributes & string>(key: TKey): TAttributes[TKey];
|
|
1534
|
+
getAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey): ModelAttributeValue<TSelf, TAttributes, TKey>;
|
|
1437
1535
|
getAttribute(key: string): unknown;
|
|
1438
1536
|
/**
|
|
1439
1537
|
* Set the value of an attribute, applying any set mutators or casts if defined.
|
|
@@ -1442,9 +1540,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1442
1540
|
* @param value
|
|
1443
1541
|
* @returns
|
|
1444
1542
|
*/
|
|
1445
|
-
setAttribute<TKey extends
|
|
1446
|
-
setAttribute<TKey extends keyof this & string>(key: TKey, value: this[TKey] extends ((...args: any[]) => any) ? never : this[TKey]): this;
|
|
1447
|
-
setAttribute<TKey extends keyof TAttributes & string>(key: TKey, value: TAttributes[TKey]): this;
|
|
1543
|
+
setAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey, value: ModelAttributeValue<TSelf, TAttributes, TKey>): this;
|
|
1448
1544
|
setAttribute(key: string, value: unknown): this;
|
|
1449
1545
|
/**
|
|
1450
1546
|
* Save the model to the database.
|
|
@@ -1869,11 +1965,14 @@ interface AttributeSchemaDelegate<TAttributes extends Record<string, unknown>> e
|
|
|
1869
1965
|
type DelegateForModelSchema<TSchema extends PrismaDelegateLike | Record<string, unknown> | string, TAttributes extends Record<string, unknown> = ModelAttributesOf<TSchema>> = TSchema extends PrismaDelegateLike ? TSchema : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateFromPrismaClient<TSchema> : PrismaDelegateLike : AttributeSchemaDelegate<TAttributes>;
|
|
1870
1966
|
type ModelAttributesOf<TSchema extends PrismaDelegateLike | Record<string, unknown> | string> = TSchema extends PrismaDelegateLike ? DelegateRow<TSchema> extends Record<string, unknown> ? DelegateRow<TSchema> : Record<string, any> : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateRow<DelegateFromPrismaClient<TSchema>> extends Record<string, unknown> ? DelegateRow<DelegateFromPrismaClient<TSchema>> : Record<string, any> : Record<string, any> : TSchema extends Record<string, unknown> ? TSchema : Record<string, any>;
|
|
1871
1967
|
type ModelAttributes<TModel> = TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>;
|
|
1968
|
+
type BaseModelInstance = Model<any, any>;
|
|
1969
|
+
type ModelDeclaredAttributeKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => any) ? never : TKey }[keyof TModel & string];
|
|
1872
1970
|
type RelationshipResultProvider<TResult = unknown> = {
|
|
1873
1971
|
getResults: (...args: any[]) => Promise<TResult>;
|
|
1874
1972
|
};
|
|
1875
|
-
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never }[keyof TModel & string];
|
|
1973
|
+
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => infer TReturn) ? Parameters<TModel[TKey]> extends [] ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never : never }[keyof TModel & string];
|
|
1876
1974
|
type ModelRelationshipResult<TModel, TKey extends ModelRelationshipKey<TModel>> = TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<infer TResult> ? TResult : never : never;
|
|
1975
|
+
type ModelAttributeValue<TModel, TAttributes extends Record<string, unknown>, TKey extends string> = TKey extends ModelRelationshipKey<TModel> ? ModelRelationshipResult<TModel, TKey> : TKey extends ModelDeclaredAttributeKey<TModel> ? TModel[TKey] : TKey extends keyof TAttributes & string ? TAttributes[TKey] : unknown;
|
|
1877
1976
|
type ModelCreateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeCreateInput<TAttributes> : DelegateCreateData<TDelegate> : DelegateCreateData<TDelegate>;
|
|
1878
1977
|
type ModelUpdateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeUpdateInput<TAttributes> : DelegateUpdateData<TDelegate> : DelegateUpdateData<TDelegate>;
|
|
1879
1978
|
type RelatedModelClass<TInstance = unknown> = (abstract new (attributes?: Record<string, unknown>) => TInstance) & RelationshipModelStatic;
|
|
@@ -2101,6 +2200,30 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
|
|
|
2101
2200
|
* @returns
|
|
2102
2201
|
*/
|
|
2103
2202
|
whereNotIn<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, values: ModelAttributes<TModel>[TKey][]): this;
|
|
2203
|
+
/**
|
|
2204
|
+
* Adds a string contains clause for a single attribute key.
|
|
2205
|
+
*
|
|
2206
|
+
* @param key
|
|
2207
|
+
* @param value
|
|
2208
|
+
* @returns
|
|
2209
|
+
*/
|
|
2210
|
+
whereLike<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
2211
|
+
/**
|
|
2212
|
+
* Adds a string starts-with clause for a single attribute key.
|
|
2213
|
+
*
|
|
2214
|
+
* @param key
|
|
2215
|
+
* @param value
|
|
2216
|
+
* @returns
|
|
2217
|
+
*/
|
|
2218
|
+
whereStartsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
2219
|
+
/**
|
|
2220
|
+
* Adds a string ends-with clause for a single attribute key.
|
|
2221
|
+
*
|
|
2222
|
+
* @param key
|
|
2223
|
+
* @param value
|
|
2224
|
+
* @returns
|
|
2225
|
+
*/
|
|
2226
|
+
whereEndsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
2104
2227
|
/**
|
|
2105
2228
|
* Adds a strongly-typed OR NOT IN where clause for a single attribute key.
|
|
2106
2229
|
*
|
|
@@ -3087,6 +3210,7 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
|
|
|
3087
3210
|
private buildOrderBy;
|
|
3088
3211
|
private buildConditionValueList;
|
|
3089
3212
|
private buildComparisonCondition;
|
|
3213
|
+
private buildRawWhereCondition;
|
|
3090
3214
|
private buildWhereCondition;
|
|
3091
3215
|
private buildWhereClause;
|
|
3092
3216
|
private buildPaginationClause;
|
|
@@ -4983,4 +5107,4 @@ declare class URLDriver {
|
|
|
4983
5107
|
url(page: number): string;
|
|
4984
5108
|
}
|
|
4985
5109
|
//#endregion
|
|
4986
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
5110
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributeValue, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelDeclaredAttributeKey, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.d.mts
CHANGED
|
@@ -554,6 +554,30 @@ declare abstract class Relation<TModel> {
|
|
|
554
554
|
* @returns
|
|
555
555
|
*/
|
|
556
556
|
whereIn<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, values: ModelAttributes<TModel>[TKey][]): this;
|
|
557
|
+
/**
|
|
558
|
+
* Add a string contains clause to the relationship query.
|
|
559
|
+
*
|
|
560
|
+
* @param key
|
|
561
|
+
* @param value
|
|
562
|
+
* @returns
|
|
563
|
+
*/
|
|
564
|
+
whereLike<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
565
|
+
/**
|
|
566
|
+
* Add a string starts-with clause to the relationship query.
|
|
567
|
+
*
|
|
568
|
+
* @param key
|
|
569
|
+
* @param value
|
|
570
|
+
* @returns
|
|
571
|
+
*/
|
|
572
|
+
whereStartsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
573
|
+
/**
|
|
574
|
+
* Add a string ends-with clause to the relationship query.
|
|
575
|
+
*
|
|
576
|
+
* @param key
|
|
577
|
+
* @param value
|
|
578
|
+
* @returns
|
|
579
|
+
*/
|
|
580
|
+
whereEndsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
557
581
|
/**
|
|
558
582
|
* Add an order by clause to the relationship query.
|
|
559
583
|
*
|
|
@@ -791,6 +815,82 @@ declare class BelongsToManyRelation<TParent, TRelated> extends Relation<TRelated
|
|
|
791
815
|
private addPivotWhere;
|
|
792
816
|
private makePivotComparison;
|
|
793
817
|
private buildPivotWhere;
|
|
818
|
+
private buildPivotTarget;
|
|
819
|
+
private buildRelatedPivotCondition;
|
|
820
|
+
private buildPivotMutationWhere;
|
|
821
|
+
private normalizeIdentifierValue;
|
|
822
|
+
private isPlainObject;
|
|
823
|
+
private isModelLike;
|
|
824
|
+
private normalizeRelatedItems;
|
|
825
|
+
private normalizeSyncEntries;
|
|
826
|
+
private resolveParentPivotValue;
|
|
827
|
+
private resolveRelatedPivotValue;
|
|
828
|
+
private buildPivotInsertValues;
|
|
829
|
+
private attachPivotToSingleResult;
|
|
830
|
+
private insertPivotRow;
|
|
831
|
+
private selectPivotRows;
|
|
832
|
+
private deletePivotRows;
|
|
833
|
+
private buildPivotUpdateValues;
|
|
834
|
+
private updatePivotRows;
|
|
835
|
+
/**
|
|
836
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
837
|
+
* pivot attributes if pivot attributes should be included.
|
|
838
|
+
*
|
|
839
|
+
* @param attributes The attributes to initialize the related model with.
|
|
840
|
+
* @returns A new instance of the related model.
|
|
841
|
+
*/
|
|
842
|
+
make(attributes?: Record<string, unknown>): TRelated;
|
|
843
|
+
/**
|
|
844
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
845
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
846
|
+
* should be included.
|
|
847
|
+
*
|
|
848
|
+
* @param attributes The attributes to initialize the related model with.
|
|
849
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
850
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
851
|
+
*/
|
|
852
|
+
create(attributes?: Record<string, unknown>, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
853
|
+
/**
|
|
854
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
855
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
856
|
+
* pivot attributes should be included.
|
|
857
|
+
*
|
|
858
|
+
* @param related The related model instance to save.
|
|
859
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
860
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
861
|
+
*/
|
|
862
|
+
save(related: TRelated, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
863
|
+
/**
|
|
864
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
865
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
866
|
+
*
|
|
867
|
+
* @param related The related model instance(s) to attach.
|
|
868
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
869
|
+
* @returns The number of related model records attached.
|
|
870
|
+
*/
|
|
871
|
+
attach(related: TRelated | unknown | Array<TRelated | unknown>, pivotAttributes?: Record<string, unknown>): Promise<number>;
|
|
872
|
+
/**
|
|
873
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
874
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
875
|
+
* for the parent are removed.
|
|
876
|
+
*
|
|
877
|
+
* @param related
|
|
878
|
+
* @returns
|
|
879
|
+
*/
|
|
880
|
+
detach(related?: TRelated | unknown | Array<TRelated | unknown>): Promise<number>;
|
|
881
|
+
/**
|
|
882
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
883
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
884
|
+
*
|
|
885
|
+
* @param related
|
|
886
|
+
* @param pivotAttributes
|
|
887
|
+
* @returns
|
|
888
|
+
*/
|
|
889
|
+
sync(related: TRelated | unknown | Array<TRelated | unknown> | Record<string, Record<string, unknown>>, pivotAttributes?: Record<string, unknown>): Promise<{
|
|
890
|
+
attached: number;
|
|
891
|
+
detached: number;
|
|
892
|
+
updated: number;
|
|
893
|
+
}>;
|
|
794
894
|
private shouldAttachPivotAttributes;
|
|
795
895
|
private getPivotColumnSelection;
|
|
796
896
|
/**
|
|
@@ -1343,7 +1443,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1343
1443
|
* @param this
|
|
1344
1444
|
* @returns
|
|
1345
1445
|
*/
|
|
1346
|
-
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1446
|
+
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1347
1447
|
/**
|
|
1348
1448
|
* Boot hook for subclasses to register scopes or perform one-time setup.
|
|
1349
1449
|
*/
|
|
@@ -1358,14 +1458,14 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1358
1458
|
* @param this
|
|
1359
1459
|
* @returns
|
|
1360
1460
|
*/
|
|
1361
|
-
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1461
|
+
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1362
1462
|
/**
|
|
1363
1463
|
* Get a query builder instance that only includes soft-deleted records.
|
|
1364
1464
|
*
|
|
1365
1465
|
* @param this
|
|
1366
1466
|
* @returns
|
|
1367
1467
|
*/
|
|
1368
|
-
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1468
|
+
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1369
1469
|
/**
|
|
1370
1470
|
* Get a query builder instance that excludes soft-deleted records.
|
|
1371
1471
|
* This is the default behavior of the query builder, but this method can be used
|
|
@@ -1376,7 +1476,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1376
1476
|
* @param args
|
|
1377
1477
|
* @returns
|
|
1378
1478
|
*/
|
|
1379
|
-
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1479
|
+
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, name: string, ...args: unknown[]): QueryBuilder<TModel, TDelegate>;
|
|
1380
1480
|
/**
|
|
1381
1481
|
* Get the soft delete configuration for the model, including whether
|
|
1382
1482
|
* soft deletes are enabled and the name of the deleted at column.
|
|
@@ -1431,9 +1531,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1431
1531
|
* @param key
|
|
1432
1532
|
* @returns
|
|
1433
1533
|
*/
|
|
1434
|
-
getAttribute<TKey extends
|
|
1435
|
-
getAttribute<TKey extends keyof this & string>(key: TKey): this[TKey] extends ((...args: any[]) => any) ? unknown : this[TKey];
|
|
1436
|
-
getAttribute<TKey extends keyof TAttributes & string>(key: TKey): TAttributes[TKey];
|
|
1534
|
+
getAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey): ModelAttributeValue<TSelf, TAttributes, TKey>;
|
|
1437
1535
|
getAttribute(key: string): unknown;
|
|
1438
1536
|
/**
|
|
1439
1537
|
* Set the value of an attribute, applying any set mutators or casts if defined.
|
|
@@ -1442,9 +1540,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1442
1540
|
* @param value
|
|
1443
1541
|
* @returns
|
|
1444
1542
|
*/
|
|
1445
|
-
setAttribute<TKey extends
|
|
1446
|
-
setAttribute<TKey extends keyof this & string>(key: TKey, value: this[TKey] extends ((...args: any[]) => any) ? never : this[TKey]): this;
|
|
1447
|
-
setAttribute<TKey extends keyof TAttributes & string>(key: TKey, value: TAttributes[TKey]): this;
|
|
1543
|
+
setAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey, value: ModelAttributeValue<TSelf, TAttributes, TKey>): this;
|
|
1448
1544
|
setAttribute(key: string, value: unknown): this;
|
|
1449
1545
|
/**
|
|
1450
1546
|
* Save the model to the database.
|
|
@@ -1869,11 +1965,14 @@ interface AttributeSchemaDelegate<TAttributes extends Record<string, unknown>> e
|
|
|
1869
1965
|
type DelegateForModelSchema<TSchema extends PrismaDelegateLike | Record<string, unknown> | string, TAttributes extends Record<string, unknown> = ModelAttributesOf<TSchema>> = TSchema extends PrismaDelegateLike ? TSchema : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateFromPrismaClient<TSchema> : PrismaDelegateLike : AttributeSchemaDelegate<TAttributes>;
|
|
1870
1966
|
type ModelAttributesOf<TSchema extends PrismaDelegateLike | Record<string, unknown> | string> = TSchema extends PrismaDelegateLike ? DelegateRow<TSchema> extends Record<string, unknown> ? DelegateRow<TSchema> : Record<string, any> : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateRow<DelegateFromPrismaClient<TSchema>> extends Record<string, unknown> ? DelegateRow<DelegateFromPrismaClient<TSchema>> : Record<string, any> : Record<string, any> : TSchema extends Record<string, unknown> ? TSchema : Record<string, any>;
|
|
1871
1967
|
type ModelAttributes<TModel> = TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>;
|
|
1968
|
+
type BaseModelInstance = Model<any, any>;
|
|
1969
|
+
type ModelDeclaredAttributeKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => any) ? never : TKey }[keyof TModel & string];
|
|
1872
1970
|
type RelationshipResultProvider<TResult = unknown> = {
|
|
1873
1971
|
getResults: (...args: any[]) => Promise<TResult>;
|
|
1874
1972
|
};
|
|
1875
|
-
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never }[keyof TModel & string];
|
|
1973
|
+
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => infer TReturn) ? Parameters<TModel[TKey]> extends [] ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never : never }[keyof TModel & string];
|
|
1876
1974
|
type ModelRelationshipResult<TModel, TKey extends ModelRelationshipKey<TModel>> = TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<infer TResult> ? TResult : never : never;
|
|
1975
|
+
type ModelAttributeValue<TModel, TAttributes extends Record<string, unknown>, TKey extends string> = TKey extends ModelRelationshipKey<TModel> ? ModelRelationshipResult<TModel, TKey> : TKey extends ModelDeclaredAttributeKey<TModel> ? TModel[TKey] : TKey extends keyof TAttributes & string ? TAttributes[TKey] : unknown;
|
|
1877
1976
|
type ModelCreateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeCreateInput<TAttributes> : DelegateCreateData<TDelegate> : DelegateCreateData<TDelegate>;
|
|
1878
1977
|
type ModelUpdateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeUpdateInput<TAttributes> : DelegateUpdateData<TDelegate> : DelegateUpdateData<TDelegate>;
|
|
1879
1978
|
type RelatedModelClass<TInstance = unknown> = (abstract new (attributes?: Record<string, unknown>) => TInstance) & RelationshipModelStatic;
|
|
@@ -2101,6 +2200,30 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
|
|
|
2101
2200
|
* @returns
|
|
2102
2201
|
*/
|
|
2103
2202
|
whereNotIn<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, values: ModelAttributes<TModel>[TKey][]): this;
|
|
2203
|
+
/**
|
|
2204
|
+
* Adds a string contains clause for a single attribute key.
|
|
2205
|
+
*
|
|
2206
|
+
* @param key
|
|
2207
|
+
* @param value
|
|
2208
|
+
* @returns
|
|
2209
|
+
*/
|
|
2210
|
+
whereLike<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
2211
|
+
/**
|
|
2212
|
+
* Adds a string starts-with clause for a single attribute key.
|
|
2213
|
+
*
|
|
2214
|
+
* @param key
|
|
2215
|
+
* @param value
|
|
2216
|
+
* @returns
|
|
2217
|
+
*/
|
|
2218
|
+
whereStartsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
2219
|
+
/**
|
|
2220
|
+
* Adds a string ends-with clause for a single attribute key.
|
|
2221
|
+
*
|
|
2222
|
+
* @param key
|
|
2223
|
+
* @param value
|
|
2224
|
+
* @returns
|
|
2225
|
+
*/
|
|
2226
|
+
whereEndsWith<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey, value: Extract<ModelAttributes<TModel>[TKey], string>): this;
|
|
2104
2227
|
/**
|
|
2105
2228
|
* Adds a strongly-typed OR NOT IN where clause for a single attribute key.
|
|
2106
2229
|
*
|
|
@@ -3087,6 +3210,7 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
|
|
|
3087
3210
|
private buildOrderBy;
|
|
3088
3211
|
private buildConditionValueList;
|
|
3089
3212
|
private buildComparisonCondition;
|
|
3213
|
+
private buildRawWhereCondition;
|
|
3090
3214
|
private buildWhereCondition;
|
|
3091
3215
|
private buildWhereClause;
|
|
3092
3216
|
private buildPaginationClause;
|
|
@@ -4983,4 +5107,4 @@ declare class URLDriver {
|
|
|
4983
5107
|
url(page: number): string;
|
|
4984
5108
|
}
|
|
4985
5109
|
//#endregion
|
|
4986
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
5110
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributeValue, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelDeclaredAttributeKey, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.mjs
CHANGED
|
@@ -2355,7 +2355,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
2355
2355
|
relationLoads: false,
|
|
2356
2356
|
relationAggregates: true,
|
|
2357
2357
|
relationFilters: true,
|
|
2358
|
-
rawWhere:
|
|
2358
|
+
rawWhere: true
|
|
2359
2359
|
};
|
|
2360
2360
|
constructor(db, mapping = {}) {
|
|
2361
2361
|
this.db = db;
|
|
@@ -2640,6 +2640,18 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
2640
2640
|
if (condition.operator === "ends-with") return sql`${column} like ${`%${String(condition.value ?? "")}`}`;
|
|
2641
2641
|
return sql`${column} ${condition.operator === "!=" ? sql.raw("!=") : sql.raw(condition.operator)} ${condition.value}`;
|
|
2642
2642
|
}
|
|
2643
|
+
buildRawWhereCondition(condition) {
|
|
2644
|
+
const segments = condition.sql.split("?");
|
|
2645
|
+
const bindings = condition.bindings ?? [];
|
|
2646
|
+
if (segments.length !== bindings.length + 1) throw new ArkormException("Raw where bindings do not match the number of placeholders.");
|
|
2647
|
+
const parts = [];
|
|
2648
|
+
segments.forEach((segment, index) => {
|
|
2649
|
+
if (segment.length > 0) parts.push(sql.raw(segment));
|
|
2650
|
+
if (index < bindings.length) parts.push(sql`${bindings[index]}`);
|
|
2651
|
+
});
|
|
2652
|
+
if (parts.length === 0) return sql`1 = 1`;
|
|
2653
|
+
return sql`${sql.join(parts, sql``)}`;
|
|
2654
|
+
}
|
|
2643
2655
|
buildWhereCondition(target, condition) {
|
|
2644
2656
|
if (!condition) return sql`1 = 1`;
|
|
2645
2657
|
if (condition.type === "comparison") return this.buildComparisonCondition(target, condition);
|
|
@@ -2656,13 +2668,7 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
|
|
|
2656
2668
|
const notCondition = condition;
|
|
2657
2669
|
return sql`not (${this.buildWhereCondition(target, notCondition.condition)})`;
|
|
2658
2670
|
}
|
|
2659
|
-
|
|
2660
|
-
operation: "adapter.where",
|
|
2661
|
-
meta: {
|
|
2662
|
-
feature: "rawWhere",
|
|
2663
|
-
sql: condition.sql
|
|
2664
|
-
}
|
|
2665
|
-
});
|
|
2671
|
+
return this.buildRawWhereCondition(condition);
|
|
2666
2672
|
}
|
|
2667
2673
|
buildWhereClause(target, condition) {
|
|
2668
2674
|
if (!condition) return sql``;
|
|
@@ -6672,6 +6678,36 @@ var QueryBuilder = class QueryBuilder {
|
|
|
6672
6678
|
return this.where({ [key]: { notIn: values } });
|
|
6673
6679
|
}
|
|
6674
6680
|
/**
|
|
6681
|
+
* Adds a string contains clause for a single attribute key.
|
|
6682
|
+
*
|
|
6683
|
+
* @param key
|
|
6684
|
+
* @param value
|
|
6685
|
+
* @returns
|
|
6686
|
+
*/
|
|
6687
|
+
whereLike(key, value) {
|
|
6688
|
+
return this.where({ [key]: { contains: value } });
|
|
6689
|
+
}
|
|
6690
|
+
/**
|
|
6691
|
+
* Adds a string starts-with clause for a single attribute key.
|
|
6692
|
+
*
|
|
6693
|
+
* @param key
|
|
6694
|
+
* @param value
|
|
6695
|
+
* @returns
|
|
6696
|
+
*/
|
|
6697
|
+
whereStartsWith(key, value) {
|
|
6698
|
+
return this.where({ [key]: { startsWith: value } });
|
|
6699
|
+
}
|
|
6700
|
+
/**
|
|
6701
|
+
* Adds a string ends-with clause for a single attribute key.
|
|
6702
|
+
*
|
|
6703
|
+
* @param key
|
|
6704
|
+
* @param value
|
|
6705
|
+
* @returns
|
|
6706
|
+
*/
|
|
6707
|
+
whereEndsWith(key, value) {
|
|
6708
|
+
return this.where({ [key]: { endsWith: value } });
|
|
6709
|
+
}
|
|
6710
|
+
/**
|
|
6675
6711
|
* Adds a strongly-typed OR NOT IN where clause for a single attribute key.
|
|
6676
6712
|
*
|
|
6677
6713
|
* @param key
|
|
@@ -8796,6 +8832,36 @@ var Relation = class {
|
|
|
8796
8832
|
return this.constrain((query) => query.whereIn(key, values));
|
|
8797
8833
|
}
|
|
8798
8834
|
/**
|
|
8835
|
+
* Add a string contains clause to the relationship query.
|
|
8836
|
+
*
|
|
8837
|
+
* @param key
|
|
8838
|
+
* @param value
|
|
8839
|
+
* @returns
|
|
8840
|
+
*/
|
|
8841
|
+
whereLike(key, value) {
|
|
8842
|
+
return this.constrain((query) => query.whereLike(key, value));
|
|
8843
|
+
}
|
|
8844
|
+
/**
|
|
8845
|
+
* Add a string starts-with clause to the relationship query.
|
|
8846
|
+
*
|
|
8847
|
+
* @param key
|
|
8848
|
+
* @param value
|
|
8849
|
+
* @returns
|
|
8850
|
+
*/
|
|
8851
|
+
whereStartsWith(key, value) {
|
|
8852
|
+
return this.constrain((query) => query.whereStartsWith(key, value));
|
|
8853
|
+
}
|
|
8854
|
+
/**
|
|
8855
|
+
* Add a string ends-with clause to the relationship query.
|
|
8856
|
+
*
|
|
8857
|
+
* @param key
|
|
8858
|
+
* @param value
|
|
8859
|
+
* @returns
|
|
8860
|
+
*/
|
|
8861
|
+
whereEndsWith(key, value) {
|
|
8862
|
+
return this.constrain((query) => query.whereEndsWith(key, value));
|
|
8863
|
+
}
|
|
8864
|
+
/**
|
|
8799
8865
|
* Add an order by clause to the relationship query.
|
|
8800
8866
|
*
|
|
8801
8867
|
* @param orderBy
|
|
@@ -9125,6 +9191,277 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9125
9191
|
conditions: [baseCondition, this.pivotWhere]
|
|
9126
9192
|
};
|
|
9127
9193
|
}
|
|
9194
|
+
buildPivotTarget() {
|
|
9195
|
+
return {
|
|
9196
|
+
table: this.throughDelegate,
|
|
9197
|
+
primaryKey: this.relatedPivotKey
|
|
9198
|
+
};
|
|
9199
|
+
}
|
|
9200
|
+
buildRelatedPivotCondition(relatedValues) {
|
|
9201
|
+
const normalizedValues = relatedValues.filter((value) => value != null);
|
|
9202
|
+
if (normalizedValues.length === 0) return null;
|
|
9203
|
+
if (normalizedValues.length === 1) return {
|
|
9204
|
+
type: "comparison",
|
|
9205
|
+
column: this.relatedPivotKey,
|
|
9206
|
+
operator: "=",
|
|
9207
|
+
value: normalizedValues[0]
|
|
9208
|
+
};
|
|
9209
|
+
return {
|
|
9210
|
+
type: "comparison",
|
|
9211
|
+
column: this.relatedPivotKey,
|
|
9212
|
+
operator: "in",
|
|
9213
|
+
value: normalizedValues
|
|
9214
|
+
};
|
|
9215
|
+
}
|
|
9216
|
+
buildPivotMutationWhere(relatedValues = []) {
|
|
9217
|
+
const baseCondition = this.buildPivotWhere(this.resolveParentPivotValue());
|
|
9218
|
+
const relatedCondition = this.buildRelatedPivotCondition(relatedValues);
|
|
9219
|
+
if (!relatedCondition) return baseCondition;
|
|
9220
|
+
return {
|
|
9221
|
+
type: "group",
|
|
9222
|
+
operator: "and",
|
|
9223
|
+
conditions: [baseCondition, relatedCondition]
|
|
9224
|
+
};
|
|
9225
|
+
}
|
|
9226
|
+
normalizeIdentifierValue(value) {
|
|
9227
|
+
if (typeof value === "string" && /^-?\d+$/.test(value)) return Number(value);
|
|
9228
|
+
return value;
|
|
9229
|
+
}
|
|
9230
|
+
isPlainObject(value) {
|
|
9231
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
9232
|
+
}
|
|
9233
|
+
isModelLike(value) {
|
|
9234
|
+
return this.isPlainObject(value) && typeof value.getAttribute === "function";
|
|
9235
|
+
}
|
|
9236
|
+
normalizeRelatedItems(related) {
|
|
9237
|
+
return Array.isArray(related) ? related : [related];
|
|
9238
|
+
}
|
|
9239
|
+
normalizeSyncEntries(related, pivotAttributes = {}) {
|
|
9240
|
+
if (Array.isArray(related)) return related.map((item) => ({
|
|
9241
|
+
related: item,
|
|
9242
|
+
attributes: { ...pivotAttributes }
|
|
9243
|
+
}));
|
|
9244
|
+
if (this.isPlainObject(related) && !this.isModelLike(related)) return Object.entries(related).map(([key, attributes]) => ({
|
|
9245
|
+
related: this.normalizeIdentifierValue(key),
|
|
9246
|
+
attributes: this.isPlainObject(attributes) ? attributes : {}
|
|
9247
|
+
}));
|
|
9248
|
+
return [{
|
|
9249
|
+
related,
|
|
9250
|
+
attributes: { ...pivotAttributes }
|
|
9251
|
+
}];
|
|
9252
|
+
}
|
|
9253
|
+
resolveParentPivotValue() {
|
|
9254
|
+
return this.parent.getAttribute(this.parentKey);
|
|
9255
|
+
}
|
|
9256
|
+
resolveRelatedPivotValue(related) {
|
|
9257
|
+
if (related && typeof related === "object" && "getAttribute" in related) return related.getAttribute(this.relatedKey);
|
|
9258
|
+
return related;
|
|
9259
|
+
}
|
|
9260
|
+
buildPivotInsertValues(related, attributes = {}) {
|
|
9261
|
+
const values = {
|
|
9262
|
+
...attributes,
|
|
9263
|
+
[this.foreignPivotKey]: this.resolveParentPivotValue(),
|
|
9264
|
+
[this.relatedPivotKey]: this.resolveRelatedPivotValue(related)
|
|
9265
|
+
};
|
|
9266
|
+
if (this.pivotCreatedAtColumn && !(this.pivotCreatedAtColumn in values)) values[this.pivotCreatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9267
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9268
|
+
return values;
|
|
9269
|
+
}
|
|
9270
|
+
attachPivotToSingleResult(related, pivotRow) {
|
|
9271
|
+
if (!this.shouldAttachPivotAttributes()) return related;
|
|
9272
|
+
related.setAttribute(this.pivotAccessor, this.createPivotRecord(pivotRow));
|
|
9273
|
+
return related;
|
|
9274
|
+
}
|
|
9275
|
+
async insertPivotRow(values, adapter = this.getRelationAdapter()) {
|
|
9276
|
+
await adapter.insert({
|
|
9277
|
+
target: this.buildPivotTarget(),
|
|
9278
|
+
values
|
|
9279
|
+
});
|
|
9280
|
+
}
|
|
9281
|
+
async selectPivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9282
|
+
return await adapter.select({
|
|
9283
|
+
target: this.buildPivotTarget(),
|
|
9284
|
+
where
|
|
9285
|
+
});
|
|
9286
|
+
}
|
|
9287
|
+
async deletePivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9288
|
+
if (typeof adapter.deleteMany === "function") return await adapter.deleteMany({
|
|
9289
|
+
target: this.buildPivotTarget(),
|
|
9290
|
+
where
|
|
9291
|
+
});
|
|
9292
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9293
|
+
await Promise.all(rows.map(async (row) => {
|
|
9294
|
+
await adapter.delete({
|
|
9295
|
+
target: this.buildPivotTarget(),
|
|
9296
|
+
where: {
|
|
9297
|
+
type: "group",
|
|
9298
|
+
operator: "and",
|
|
9299
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9300
|
+
type: "comparison",
|
|
9301
|
+
column,
|
|
9302
|
+
operator: "=",
|
|
9303
|
+
value
|
|
9304
|
+
}))
|
|
9305
|
+
}
|
|
9306
|
+
});
|
|
9307
|
+
}));
|
|
9308
|
+
return rows.length;
|
|
9309
|
+
}
|
|
9310
|
+
buildPivotUpdateValues(attributes = {}) {
|
|
9311
|
+
const values = { ...attributes };
|
|
9312
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9313
|
+
return values;
|
|
9314
|
+
}
|
|
9315
|
+
async updatePivotRows(related, attributes, adapter = this.getRelationAdapter()) {
|
|
9316
|
+
const values = this.buildPivotUpdateValues(attributes);
|
|
9317
|
+
if (Object.keys(values).length === 0) return 0;
|
|
9318
|
+
const where = this.buildPivotMutationWhere([this.resolveRelatedPivotValue(related)]);
|
|
9319
|
+
if (typeof adapter.updateMany === "function") return await adapter.updateMany({
|
|
9320
|
+
target: this.buildPivotTarget(),
|
|
9321
|
+
where,
|
|
9322
|
+
values
|
|
9323
|
+
});
|
|
9324
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9325
|
+
await Promise.all(rows.map(async (row) => {
|
|
9326
|
+
await adapter.update({
|
|
9327
|
+
target: this.buildPivotTarget(),
|
|
9328
|
+
where: {
|
|
9329
|
+
type: "group",
|
|
9330
|
+
operator: "and",
|
|
9331
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9332
|
+
type: "comparison",
|
|
9333
|
+
column,
|
|
9334
|
+
operator: "=",
|
|
9335
|
+
value
|
|
9336
|
+
}))
|
|
9337
|
+
},
|
|
9338
|
+
values
|
|
9339
|
+
});
|
|
9340
|
+
}));
|
|
9341
|
+
return rows.length;
|
|
9342
|
+
}
|
|
9343
|
+
/**
|
|
9344
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
9345
|
+
* pivot attributes if pivot attributes should be included.
|
|
9346
|
+
*
|
|
9347
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9348
|
+
* @returns A new instance of the related model.
|
|
9349
|
+
*/
|
|
9350
|
+
make(attributes = {}) {
|
|
9351
|
+
return this.related.hydrate(attributes);
|
|
9352
|
+
}
|
|
9353
|
+
/**
|
|
9354
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
9355
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
9356
|
+
* should be included.
|
|
9357
|
+
*
|
|
9358
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9359
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9360
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9361
|
+
*/
|
|
9362
|
+
async create(attributes = {}, pivotAttributes = {}) {
|
|
9363
|
+
const related = await this.related.query().create(attributes);
|
|
9364
|
+
const pivotRow = this.buildPivotInsertValues(related, pivotAttributes);
|
|
9365
|
+
await this.insertPivotRow(pivotRow);
|
|
9366
|
+
return this.attachPivotToSingleResult(related, pivotRow);
|
|
9367
|
+
}
|
|
9368
|
+
/**
|
|
9369
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
9370
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
9371
|
+
* pivot attributes should be included.
|
|
9372
|
+
*
|
|
9373
|
+
* @param related The related model instance to save.
|
|
9374
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9375
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9376
|
+
*/
|
|
9377
|
+
async save(related, pivotAttributes = {}) {
|
|
9378
|
+
const saveable = related;
|
|
9379
|
+
let persisted = related;
|
|
9380
|
+
if (typeof saveable.save === "function") try {
|
|
9381
|
+
persisted = await saveable.save();
|
|
9382
|
+
} catch (error) {
|
|
9383
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "MODEL_NOT_FOUND")) throw error;
|
|
9384
|
+
const attributes = typeof saveable.getRawAttributes === "function" ? saveable.getRawAttributes() : {};
|
|
9385
|
+
persisted = await this.related.query().create(attributes);
|
|
9386
|
+
}
|
|
9387
|
+
const pivotRow = this.buildPivotInsertValues(persisted, pivotAttributes);
|
|
9388
|
+
await this.insertPivotRow(pivotRow);
|
|
9389
|
+
return this.attachPivotToSingleResult(persisted, pivotRow);
|
|
9390
|
+
}
|
|
9391
|
+
/**
|
|
9392
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
9393
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
9394
|
+
*
|
|
9395
|
+
* @param related The related model instance(s) to attach.
|
|
9396
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9397
|
+
* @returns The number of related model records attached.
|
|
9398
|
+
*/
|
|
9399
|
+
async attach(related, pivotAttributes = {}) {
|
|
9400
|
+
const items = Array.isArray(related) ? related : [related];
|
|
9401
|
+
await Promise.all(items.map(async (item) => {
|
|
9402
|
+
await this.insertPivotRow(this.buildPivotInsertValues(item, pivotAttributes));
|
|
9403
|
+
}));
|
|
9404
|
+
return items.length;
|
|
9405
|
+
}
|
|
9406
|
+
/**
|
|
9407
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
9408
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
9409
|
+
* for the parent are removed.
|
|
9410
|
+
*
|
|
9411
|
+
* @param related
|
|
9412
|
+
* @returns
|
|
9413
|
+
*/
|
|
9414
|
+
async detach(related) {
|
|
9415
|
+
const where = related === void 0 ? this.buildPivotWhere(this.resolveParentPivotValue()) : this.buildPivotMutationWhere(this.normalizeRelatedItems(related).map((item) => this.resolveRelatedPivotValue(item)));
|
|
9416
|
+
return await this.deletePivotRows(where);
|
|
9417
|
+
}
|
|
9418
|
+
/**
|
|
9419
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
9420
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
9421
|
+
*
|
|
9422
|
+
* @param related
|
|
9423
|
+
* @param pivotAttributes
|
|
9424
|
+
* @returns
|
|
9425
|
+
*/
|
|
9426
|
+
async sync(related, pivotAttributes = {}) {
|
|
9427
|
+
return await this.getRelationAdapter().transaction(async (transaction) => {
|
|
9428
|
+
const existingRows = await this.selectPivotRows(this.buildPivotWhere(this.resolveParentPivotValue()), transaction);
|
|
9429
|
+
const desiredEntries = /* @__PURE__ */ new Map();
|
|
9430
|
+
this.normalizeSyncEntries(related, pivotAttributes).forEach((entry) => {
|
|
9431
|
+
const relatedValue = this.resolveRelatedPivotValue(entry.related);
|
|
9432
|
+
if (relatedValue == null) return;
|
|
9433
|
+
desiredEntries.set(String(relatedValue), {
|
|
9434
|
+
related: relatedValue,
|
|
9435
|
+
attributes: entry.attributes
|
|
9436
|
+
});
|
|
9437
|
+
});
|
|
9438
|
+
let detached = 0;
|
|
9439
|
+
let attached = 0;
|
|
9440
|
+
let updated = 0;
|
|
9441
|
+
const existingKeys = /* @__PURE__ */ new Set();
|
|
9442
|
+
for (const row of existingRows) {
|
|
9443
|
+
const relatedValue = row[this.relatedPivotKey];
|
|
9444
|
+
if (relatedValue == null) continue;
|
|
9445
|
+
const relatedKey = String(relatedValue);
|
|
9446
|
+
existingKeys.add(relatedKey);
|
|
9447
|
+
if (!desiredEntries.has(relatedKey)) detached += await this.deletePivotRows(this.buildPivotMutationWhere([relatedValue]), transaction);
|
|
9448
|
+
}
|
|
9449
|
+
for (const [relatedKey, entry] of desiredEntries) {
|
|
9450
|
+
if (!existingKeys.has(relatedKey)) {
|
|
9451
|
+
await this.insertPivotRow(this.buildPivotInsertValues(entry.related, entry.attributes), transaction);
|
|
9452
|
+
attached += 1;
|
|
9453
|
+
continue;
|
|
9454
|
+
}
|
|
9455
|
+
if (Object.keys(entry.attributes).length === 0) continue;
|
|
9456
|
+
updated += await this.updatePivotRows(entry.related, entry.attributes, transaction);
|
|
9457
|
+
}
|
|
9458
|
+
return {
|
|
9459
|
+
attached,
|
|
9460
|
+
detached,
|
|
9461
|
+
updated
|
|
9462
|
+
};
|
|
9463
|
+
});
|
|
9464
|
+
}
|
|
9128
9465
|
shouldAttachPivotAttributes() {
|
|
9129
9466
|
return this.shouldAttachPivot || this.pivotColumns.size > 0 || Boolean(this.pivotCreatedAtColumn) || Boolean(this.pivotUpdatedAtColumn) || Boolean(this.pivotModel);
|
|
9130
9467
|
}
|
|
@@ -9210,7 +9547,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9210
9547
|
return query;
|
|
9211
9548
|
}
|
|
9212
9549
|
async loadPivotRowsForParent() {
|
|
9213
|
-
const parentValue = this.
|
|
9550
|
+
const parentValue = this.resolveParentPivotValue();
|
|
9214
9551
|
return await this.createRelationTableLoader().selectRows({
|
|
9215
9552
|
table: this.throughDelegate,
|
|
9216
9553
|
where: this.buildPivotWhere(parentValue),
|