@prisma/orm-family-sql 8.0.0-rc.14-dev.30 → 8.0.0-rc.14-dev.32
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/contract-prisma7__provider.mjs +2 -2
- package/dist/contract-psl.mjs +1 -1
- package/dist/contract-psl__attribute-specs.mjs +1 -1
- package/dist/contract-psl__provider.mjs +1 -1
- package/dist/contract-psl__provider.mjs.map +1 -1
- package/dist/{control-BYT1Lgtm.mjs → control-AYMohAq_.mjs} +2 -2
- package/dist/{control-BYT1Lgtm.mjs.map → control-AYMohAq_.mjs.map} +1 -1
- package/dist/family.mjs +1 -1
- package/dist/family__control.mjs +1 -1
- package/dist/family__pack.mjs +1 -1
- package/dist/{interpreter-CDflex9x-Bx84tcl5.mjs → interpreter-Cn_CHpKv-V5WRLkBQ.mjs} +3 -3
- package/dist/{interpreter-CDflex9x-Bx84tcl5.mjs.map → interpreter-Cn_CHpKv-V5WRLkBQ.mjs.map} +1 -1
- package/dist/orm-client.d.mts +90 -47
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +26 -362
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{psl-field-resolution-CKMm6Gx0-CdzpWIV5.mjs → psl-field-resolution-Bf8vUaoK-CanSt2s1.mjs} +6 -3
- package/dist/psl-field-resolution-Bf8vUaoK-CanSt2s1.mjs.map +1 -0
- package/package.json +18 -18
- package/dist/psl-field-resolution-CKMm6Gx0-CdzpWIV5.mjs.map +0 -1
package/dist/orm-client.mjs
CHANGED
|
@@ -3896,7 +3896,7 @@ function splitCreateArguments(optionsOrConfigure, configure) {
|
|
|
3896
3896
|
function isMtiVariantInfo(variant) {
|
|
3897
3897
|
return variant?.strategy === "mti";
|
|
3898
3898
|
}
|
|
3899
|
-
var
|
|
3899
|
+
var CollectionBase = class CollectionBase {
|
|
3900
3900
|
/** @internal */
|
|
3901
3901
|
ctx;
|
|
3902
3902
|
/** @internal */
|
|
@@ -3932,7 +3932,7 @@ var CollectionImpl = class CollectionImpl {
|
|
|
3932
3932
|
* because their names are the registry's, not the class declaration's.
|
|
3933
3933
|
*
|
|
3934
3934
|
* A name the collection already carries is skipped, and which member holds
|
|
3935
|
-
* it decides what the skip means. A `
|
|
3935
|
+
* it decides what the skip means. A `CollectionBase` member is rejected at
|
|
3936
3936
|
* ORM composition with `ORM.AGGREGATE_OPERATION_RESERVED`, since
|
|
3937
3937
|
* {@link reservedCollectionMemberNames} scans this class. A member declared
|
|
3938
3938
|
* by a custom collection class registered through `orm({ collections })`
|
|
@@ -3972,27 +3972,14 @@ var CollectionImpl = class CollectionImpl {
|
|
|
3972
3972
|
namespaceId: this.namespaceId
|
|
3973
3973
|
});
|
|
3974
3974
|
if (!filter) return blindCast(this);
|
|
3975
|
-
return this.#
|
|
3975
|
+
return this.#cloneSelf({ filters: [...this.state.filters, filter] });
|
|
3976
3976
|
}
|
|
3977
3977
|
/**
|
|
3978
|
-
*
|
|
3979
|
-
* collection has the variant's row shape and a discriminator filter
|
|
3980
|
-
* is automatically applied. Chaining `.variant(...)` again replaces
|
|
3981
|
-
* the previous variant filter.
|
|
3982
|
-
*
|
|
3983
|
-
* ```typescript
|
|
3984
|
-
* // Read only admin users (STI):
|
|
3985
|
-
* const admins = await db.orm.User.variant('Admin').all();
|
|
3986
|
-
*
|
|
3987
|
-
* // Iterate the rows:
|
|
3988
|
-
* for await (const admin of db.orm.User.variant('Admin').all()) {
|
|
3989
|
-
* console.log(admin.role);
|
|
3990
|
-
* }
|
|
3991
|
-
*
|
|
3992
|
-
* // Insert under a variant — discriminator is injected automatically:
|
|
3993
|
-
* await db.orm.User.variant('Admin').create({ name: 'Ada', role: 'super' });
|
|
3994
|
-
* ```
|
|
3978
|
+
* Call `fn` with this collection and return its result.
|
|
3995
3979
|
*/
|
|
3980
|
+
apply(fn) {
|
|
3981
|
+
return fn(this);
|
|
3982
|
+
}
|
|
3996
3983
|
variant(variantName) {
|
|
3997
3984
|
const model = modelOf(this.contract, this.namespaceId, this.modelName);
|
|
3998
3985
|
const discriminator = model?.discriminator;
|
|
@@ -4052,46 +4039,15 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4052
4039
|
};
|
|
4053
4040
|
return this.#cloneWithRow({ includes: [...this.state.includes, includeExpr] });
|
|
4054
4041
|
}
|
|
4055
|
-
/**
|
|
4056
|
-
* Project the row down to a subset of scalar fields. Previously
|
|
4057
|
-
* included relations are preserved on the resulting row shape; only
|
|
4058
|
-
* scalar columns are narrowed.
|
|
4059
|
-
*
|
|
4060
|
-
* ```typescript
|
|
4061
|
-
* const summaries = await db.orm.User.select('id', 'email').all();
|
|
4062
|
-
* // typeof summaries[number] === { id: ...; email: ... }
|
|
4063
|
-
*
|
|
4064
|
-
* for await (const row of db.orm.User.select('id', 'email').all()) {
|
|
4065
|
-
* console.log(row.id, row.email);
|
|
4066
|
-
* }
|
|
4067
|
-
* ```
|
|
4068
|
-
*/
|
|
4069
4042
|
select(...fields) {
|
|
4070
4043
|
const selectedFields = mapFieldsToColumns(this.contract, this.namespaceId, this.modelName, fields);
|
|
4071
4044
|
return this.#cloneWithRow({ selectedFields });
|
|
4072
4045
|
}
|
|
4073
|
-
/**
|
|
4074
|
-
* Append an `ORDER BY` clause. Pass a single selector callback or an
|
|
4075
|
-
* array of callbacks; each receives a typed model accessor whose
|
|
4076
|
-
* columns expose `.asc()` and `.desc()`. Multiple calls append to the
|
|
4077
|
-
* existing list (left-to-right ordering preserved).
|
|
4078
|
-
*
|
|
4079
|
-
* Calling `orderBy(...)` unlocks `cursor(...)` and `distinctOn(...)`,
|
|
4080
|
-
* which both require a defined sort order.
|
|
4081
|
-
*
|
|
4082
|
-
* ```typescript
|
|
4083
|
-
* const newest = await db.orm.User.orderBy((u) => u.createdAt.desc()).all();
|
|
4084
|
-
*
|
|
4085
|
-
* const byName = await db.orm.User
|
|
4086
|
-
* .orderBy([(u) => u.lastName.asc(), (u) => u.firstName.asc()])
|
|
4087
|
-
* .all();
|
|
4088
|
-
* ```
|
|
4089
|
-
*/
|
|
4090
4046
|
orderBy(selection) {
|
|
4091
4047
|
const accessor = createModelAccessor(this.ctx.context, this.namespaceId, this.modelName, this.state.variantName);
|
|
4092
4048
|
const nextOrders = (Array.isArray(selection) ? selection : [selection]).map((selector) => selector(accessor));
|
|
4093
4049
|
const existing = this.state.orderBy ?? [];
|
|
4094
|
-
return this.#
|
|
4050
|
+
return this.#cloneSelf({ orderBy: [...existing, ...nextOrders] });
|
|
4095
4051
|
}
|
|
4096
4052
|
/**
|
|
4097
4053
|
* Switch to grouped-aggregate mode. Returns a `GroupedCollection`
|
|
@@ -4161,136 +4117,39 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4161
4117
|
}
|
|
4162
4118
|
return createIncludeCombine(branches);
|
|
4163
4119
|
}
|
|
4164
|
-
/**
|
|
4165
|
-
* Resume pagination from a known cursor position. Requires a prior
|
|
4166
|
-
* `orderBy(...)` so the cursor has a stable basis; provide a value
|
|
4167
|
-
* for every column referenced by the active `orderBy(...)` so each
|
|
4168
|
-
* ordered axis has a defined boundary.
|
|
4169
|
-
*
|
|
4170
|
-
* ```typescript
|
|
4171
|
-
* const page1 = await db.orm.Post
|
|
4172
|
-
* .orderBy((p) => p.createdAt.desc())
|
|
4173
|
-
* .limit(20)
|
|
4174
|
-
* .all();
|
|
4175
|
-
*
|
|
4176
|
-
* const last = page1[page1.length - 1]!;
|
|
4177
|
-
* const page2 = await db.orm.Post
|
|
4178
|
-
* .orderBy((p) => p.createdAt.desc())
|
|
4179
|
-
* .cursor({ createdAt: last.createdAt })
|
|
4180
|
-
* .limit(20)
|
|
4181
|
-
* .all();
|
|
4182
|
-
* ```
|
|
4183
|
-
*/
|
|
4184
4120
|
cursor(cursorValues) {
|
|
4185
4121
|
assertCursorCompatibleOrder(this.state.orderBy);
|
|
4186
4122
|
const mappedCursor = mapCursorValuesToColumns(this.contract, this.namespaceId, this.modelName, cursorValues);
|
|
4187
|
-
if (Object.keys(mappedCursor).length === 0) return
|
|
4188
|
-
return this.#
|
|
4123
|
+
if (Object.keys(mappedCursor).length === 0) return this;
|
|
4124
|
+
return this.#cloneSelf({ cursor: mappedCursor });
|
|
4189
4125
|
}
|
|
4190
|
-
/**
|
|
4191
|
-
* Emit `SELECT DISTINCT` keyed on the given fields. Replaces any
|
|
4192
|
-
* previous `distinct(...)` / `distinctOn(...)` selection.
|
|
4193
|
-
*
|
|
4194
|
-
* ```typescript
|
|
4195
|
-
* const groups = await db.orm.User.distinct('country', 'role').all();
|
|
4196
|
-
* ```
|
|
4197
|
-
*/
|
|
4198
4126
|
distinct(...fields) {
|
|
4199
4127
|
const distinctFields = mapFieldsToColumns(this.contract, this.namespaceId, this.modelName, fields);
|
|
4200
|
-
return this.#
|
|
4128
|
+
return this.#cloneSelf({
|
|
4201
4129
|
distinct: distinctFields,
|
|
4202
4130
|
distinctOn: void 0
|
|
4203
4131
|
});
|
|
4204
4132
|
}
|
|
4205
|
-
/**
|
|
4206
|
-
* Emit `SELECT DISTINCT ON (fields)` — keep the first row per
|
|
4207
|
-
* distinct key according to the current `orderBy(...)`. Requires a
|
|
4208
|
-
* prior `orderBy(...)`; replaces any previous `distinct(...)` /
|
|
4209
|
-
* `distinctOn(...)` selection.
|
|
4210
|
-
*
|
|
4211
|
-
* Requires the `postgres.distinctOn` capability.
|
|
4212
|
-
*
|
|
4213
|
-
* ```typescript
|
|
4214
|
-
* // Latest post per user:
|
|
4215
|
-
* const latestPerUser = await db.orm.Post
|
|
4216
|
-
* .orderBy([(p) => p.userId.asc(), (p) => p.createdAt.desc()])
|
|
4217
|
-
* .distinctOn('userId')
|
|
4218
|
-
* .all();
|
|
4219
|
-
* ```
|
|
4220
|
-
*/
|
|
4221
4133
|
distinctOn(...fields) {
|
|
4222
4134
|
assertDistinctOnCapability(this.contract, "distinctOn");
|
|
4223
4135
|
assertDistinctOnCompatibleOrder(this.state.orderBy, fields.length);
|
|
4224
4136
|
const distinctOnFields = mapFieldsToColumns(this.contract, this.namespaceId, this.modelName, fields);
|
|
4225
|
-
return this.#
|
|
4137
|
+
return this.#cloneSelf({
|
|
4226
4138
|
distinct: void 0,
|
|
4227
4139
|
distinctOn: distinctOnFields
|
|
4228
4140
|
});
|
|
4229
4141
|
}
|
|
4230
|
-
/**
|
|
4231
|
-
* Apply `LIMIT n`. Replaces any previous limit set on this collection.
|
|
4232
|
-
*
|
|
4233
|
-
* ```typescript
|
|
4234
|
-
* const firstTen = await db.orm.User.orderBy((u) => u.id.asc()).limit(10).all();
|
|
4235
|
-
* ```
|
|
4236
|
-
*/
|
|
4237
4142
|
limit(n) {
|
|
4238
|
-
return this.#
|
|
4143
|
+
return this.#cloneSelf({ limit: typeof n === "number" ? n : toExpr(n) });
|
|
4239
4144
|
}
|
|
4240
|
-
/**
|
|
4241
|
-
* Apply `OFFSET n`. Replaces any previous offset set on this collection.
|
|
4242
|
-
*
|
|
4243
|
-
* ```typescript
|
|
4244
|
-
* const page2 = await db.orm.User
|
|
4245
|
-
* .orderBy((u) => u.id.asc())
|
|
4246
|
-
* .offset(10)
|
|
4247
|
-
* .limit(10)
|
|
4248
|
-
* .all();
|
|
4249
|
-
* ```
|
|
4250
|
-
*/
|
|
4251
4145
|
offset(n) {
|
|
4252
|
-
return this.#
|
|
4146
|
+
return this.#cloneSelf({ offset: typeof n === "number" ? n : toExpr(n) });
|
|
4253
4147
|
}
|
|
4254
|
-
/**
|
|
4255
|
-
* Read terminal: execute the query and stream every matching row.
|
|
4256
|
-
*
|
|
4257
|
-
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
4258
|
-
* resolves to `Row[]` (so `await` collects all rows into an array)
|
|
4259
|
-
* AND an async iterable (so `for await` streams rows as they
|
|
4260
|
-
* arrive, without buffering the whole result set in memory). Pick
|
|
4261
|
-
* whichever fits the caller. A single result can only be consumed
|
|
4262
|
-
* once.
|
|
4263
|
-
*
|
|
4264
|
-
* Queries without `include(...)` stream rows as the driver yields them (drivers that cannot
|
|
4265
|
-
* expose a cursor buffer internally first). Queries with `include(...)` read the whole parent
|
|
4266
|
-
* result set into memory before yielding the first row.
|
|
4267
|
-
*
|
|
4268
|
-
* ```typescript
|
|
4269
|
-
* // Thenable — collect to an array:
|
|
4270
|
-
* const users = await db.orm.User.all();
|
|
4271
|
-
* for (const user of users) console.log(user.id);
|
|
4272
|
-
*
|
|
4273
|
-
* // Async iterable — stream rows as they arrive:
|
|
4274
|
-
* for await (const user of db.orm.User.all()) {
|
|
4275
|
-
* console.log(user.id);
|
|
4276
|
-
* }
|
|
4277
|
-
* ```
|
|
4278
|
-
*
|
|
4279
|
-
* Accepts an optional `configure` callback that receives a
|
|
4280
|
-
* `MetaBuilder<'read'>` so the caller can attach typed user
|
|
4281
|
-
* annotations to the executed plan. `meta.annotate(...)` enforces
|
|
4282
|
-
* applicability at the type level and at runtime; annotations are
|
|
4283
|
-
* merged into `plan.meta.annotations` at compile time.
|
|
4284
|
-
*
|
|
4285
|
-
* ```typescript
|
|
4286
|
-
* await db.orm.User.all((meta) => meta.annotate(cacheAnnotation({ key: 'users' })));
|
|
4287
|
-
* ```
|
|
4288
|
-
*/
|
|
4289
4148
|
all(configure) {
|
|
4290
4149
|
return this.#withAnnotationsFromMeta(configure, "all").#dispatch();
|
|
4291
4150
|
}
|
|
4292
4151
|
get prepared() {
|
|
4293
|
-
return {
|
|
4152
|
+
return blindCast({
|
|
4294
4153
|
aggregate: (fn, configure) => this.#describeAggregate(fn, configure),
|
|
4295
4154
|
all: (configure) => {
|
|
4296
4155
|
return describeCollectionRows(this.#withAnnotationsFromMeta(configure, "all").#descriptionOptions());
|
|
@@ -4298,7 +4157,7 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4298
4157
|
first: (filter, configure) => {
|
|
4299
4158
|
return describeCollectionFirst(this.#forFirst(filter, configure).#descriptionOptions());
|
|
4300
4159
|
}
|
|
4301
|
-
};
|
|
4160
|
+
});
|
|
4302
4161
|
}
|
|
4303
4162
|
#descriptionOptions() {
|
|
4304
4163
|
return {
|
|
@@ -4405,41 +4264,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4405
4264
|
model: this.modelName
|
|
4406
4265
|
} });
|
|
4407
4266
|
}
|
|
4408
|
-
/**
|
|
4409
|
-
* Write terminal: insert many rows and stream the inserted rows.
|
|
4410
|
-
*
|
|
4411
|
-
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
4412
|
-
* resolves to `Row[]` AND an async iterable that streams inserted
|
|
4413
|
-
* rows as they arrive. Use whichever shape fits the caller — but
|
|
4414
|
-
* only consume it once. Streaming is the default; some
|
|
4415
|
-
* driver/plan combinations may still buffer internally before
|
|
4416
|
-
* yielding.
|
|
4417
|
-
*
|
|
4418
|
-
* ```typescript
|
|
4419
|
-
* // Thenable — collect all inserted rows into an array:
|
|
4420
|
-
* const created = await db.orm.User.createAll([
|
|
4421
|
-
* { email: 'a@example.com' },
|
|
4422
|
-
* { email: 'b@example.com' },
|
|
4423
|
-
* ]);
|
|
4424
|
-
*
|
|
4425
|
-
* // Async iterable — stream inserted rows as they arrive:
|
|
4426
|
-
* for await (const row of db.orm.User.createAll(seedUsers)) {
|
|
4427
|
-
* console.log('inserted', row.id);
|
|
4428
|
-
* }
|
|
4429
|
-
*
|
|
4430
|
-
* // Let the database skip rows that collide with a unique
|
|
4431
|
-
* // constraint; only the rows it inserted come back:
|
|
4432
|
-
* const inserted = await db.orm.User.createAll(seedUsers, {
|
|
4433
|
-
* onConflict: 'skip',
|
|
4434
|
-
* conflictOn: ['email'],
|
|
4435
|
-
* });
|
|
4436
|
-
* ```
|
|
4437
|
-
*
|
|
4438
|
-
* Accepts an optional `configure` callback that receives a
|
|
4439
|
-
* `MetaBuilder<'write'>` for attaching typed annotations to the
|
|
4440
|
-
* compiled insert plan. It may be passed in second position when
|
|
4441
|
-
* there are no options.
|
|
4442
|
-
*/
|
|
4443
4267
|
createAll(data, optionsOrConfigure, configure) {
|
|
4444
4268
|
const { options, configureCallback } = splitCreateArguments(optionsOrConfigure, configure);
|
|
4445
4269
|
const conflictSkip = this.#resolveConflictSkip(options, "createAll()");
|
|
@@ -4662,38 +4486,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4662
4486
|
const compiled = mergeAnnotations(compileInsertCount(this.contract, this.namespaceId, this.tableName, mappedRows, conflictSkip), annotationsMap);
|
|
4663
4487
|
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
4664
4488
|
}
|
|
4665
|
-
/**
|
|
4666
|
-
* Write terminal: insert a row, or update the existing row on
|
|
4667
|
-
* conflict. Returns the resulting row (the inserted one or the
|
|
4668
|
-
* updated/existing one).
|
|
4669
|
-
*
|
|
4670
|
-
* `conflictOn` selects which unique constraint drives the conflict
|
|
4671
|
-
* resolution — omit to use the model's primary key.
|
|
4672
|
-
*
|
|
4673
|
-
* ```typescript
|
|
4674
|
-
* // Insert-or-update on email uniqueness:
|
|
4675
|
-
* await db.orm.User.upsert({
|
|
4676
|
-
* create: { email: 'alice@example.com', name: 'Alice' },
|
|
4677
|
-
* update: { name: 'Alice (updated)' },
|
|
4678
|
-
* conflictOn: { email: 'alice@example.com' },
|
|
4679
|
-
* });
|
|
4680
|
-
*
|
|
4681
|
-
* // Conditional create — `update: {}` keeps the existing row
|
|
4682
|
-
* // unchanged. `conflictOn` must reference the constraint that
|
|
4683
|
-
* // makes the row "already exist"; omit only when the conflict is
|
|
4684
|
-
* // on the primary key. On conflict,
|
|
4685
|
-
* // `ON CONFLICT DO NOTHING RETURNING ...` may return zero rows,
|
|
4686
|
-
* // so a follow-up reload is issued to fetch and return the
|
|
4687
|
-
* // existing row.
|
|
4688
|
-
* await db.orm.User.upsert({
|
|
4689
|
-
* create: { email: 'alice@example.com', name: 'Alice' },
|
|
4690
|
-
* update: {},
|
|
4691
|
-
* conflictOn: { email: 'alice@example.com' },
|
|
4692
|
-
* });
|
|
4693
|
-
* ```
|
|
4694
|
-
*
|
|
4695
|
-
* Not supported on MTI variants.
|
|
4696
|
-
*/
|
|
4697
4489
|
async upsert(input, configure) {
|
|
4698
4490
|
assertReturningCapability(this.contract, "upsert()");
|
|
4699
4491
|
this.#assertNotMtiVariant("upsert()");
|
|
@@ -4736,44 +4528,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4736
4528
|
model: this.modelName
|
|
4737
4529
|
} });
|
|
4738
4530
|
}
|
|
4739
|
-
/**
|
|
4740
|
-
* Write terminal: update a single matching row — the first one the
|
|
4741
|
-
* filter matches — and return it (or `null` when no row matched).
|
|
4742
|
-
* Requires a prior `.where(...)` — calling `update(...)` on an
|
|
4743
|
-
* unfiltered collection is a type error.
|
|
4744
|
-
*
|
|
4745
|
-
* Related rows can be created, linked, or unlinked through relation callbacks on any relation:
|
|
4746
|
-
* to-one (1:1, N:1), to-many (1:N), and many-to-many (N:M, written through the junction table).
|
|
4747
|
-
* The callback receives a mutator exposing `create(...)`, `connect(...)`, and `disconnect(...)`.
|
|
4748
|
-
* A to-one `disconnect()` clears the foreign key; a to-many `disconnect()` with no criteria
|
|
4749
|
-
* unlinks every related row; an N:M `disconnect()` requires criteria. N:M `create`/`connect` are
|
|
4750
|
-
* unavailable when the junction has required columns the relation API cannot populate. Nested
|
|
4751
|
-
* updates against existing related rows are not supported through this API.
|
|
4752
|
-
*
|
|
4753
|
-
* ```typescript
|
|
4754
|
-
* // Update one row by id:
|
|
4755
|
-
* const updated = await db.orm.User
|
|
4756
|
-
* .where({ id: 1 })
|
|
4757
|
-
* .update({ name: 'Alice Renamed' });
|
|
4758
|
-
*
|
|
4759
|
-
* // Update + relink — runs as a graph of internal mutations:
|
|
4760
|
-
* await db.orm.User
|
|
4761
|
-
* .where({ id: 1 })
|
|
4762
|
-
* .update({
|
|
4763
|
-
* name: 'Alice',
|
|
4764
|
-
* posts: (posts) => posts.connect([{ id: 5 }]),
|
|
4765
|
-
* });
|
|
4766
|
-
* ```
|
|
4767
|
-
*
|
|
4768
|
-
* Accepts an optional `configure` callback that receives a
|
|
4769
|
-
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
4770
|
-
*
|
|
4771
|
-
* Note: when the input contains nested-mutation callbacks, the
|
|
4772
|
-
* operation is executed as a graph of internal queries via
|
|
4773
|
-
* `withMutationScope`. In that path the `configure` callback still runs, so `meta.annotate`
|
|
4774
|
-
* validation applies, but the recorded annotations are discarded: neither the nested
|
|
4775
|
-
* statements nor the read-back query carry them.
|
|
4776
|
-
*/
|
|
4777
4531
|
async update(data, configure) {
|
|
4778
4532
|
assertReturningCapability(this.contract, "update()");
|
|
4779
4533
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "update");
|
|
@@ -4797,31 +4551,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4797
4551
|
return (await scoped.#clone({ filters: [identityWhere] }).#updateAllWithAnnotations(blindCast(data), annotationsMap))[0] ?? null;
|
|
4798
4552
|
});
|
|
4799
4553
|
}
|
|
4800
|
-
/**
|
|
4801
|
-
* Write terminal: update every matching row and stream the updated
|
|
4802
|
-
* rows. Requires a prior `.where(...)` filter.
|
|
4803
|
-
*
|
|
4804
|
-
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
4805
|
-
* resolves to `Row[]` AND an async iterable that streams updated
|
|
4806
|
-
* rows as they arrive. Use whichever fits; a result can only be
|
|
4807
|
-
* consumed once. Streaming is the default; some driver/plan
|
|
4808
|
-
* combinations may still buffer internally before yielding.
|
|
4809
|
-
*
|
|
4810
|
-
* ```typescript
|
|
4811
|
-
* // Thenable — collect updated rows into an array:
|
|
4812
|
-
* const updated = await db.orm.Post
|
|
4813
|
-
* .where({ published: false })
|
|
4814
|
-
* .updateAll({ published: true });
|
|
4815
|
-
*
|
|
4816
|
-
* // Async iterable — stream updated rows as they arrive:
|
|
4817
|
-
* for await (const row of db.orm.Post.where({ draft: true }).updateAll({ draft: false })) {
|
|
4818
|
-
* console.log('published', row.id);
|
|
4819
|
-
* }
|
|
4820
|
-
* ```
|
|
4821
|
-
*
|
|
4822
|
-
* Accepts an optional `configure` callback that receives a
|
|
4823
|
-
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
4824
|
-
*/
|
|
4825
4554
|
updateAll(data, configure) {
|
|
4826
4555
|
return this.#updateAllWithAnnotations(data, this.#collectAnnotationsFromMeta(configure, "write", "updateAll"));
|
|
4827
4556
|
}
|
|
@@ -4849,20 +4578,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4849
4578
|
mapRow: (mapped) => blindCast(mapped)
|
|
4850
4579
|
});
|
|
4851
4580
|
}
|
|
4852
|
-
/**
|
|
4853
|
-
* Write terminal: update every matching row without returning them,
|
|
4854
|
-
* resolving to the count of rows that were updated. Requires a prior
|
|
4855
|
-
* `.where(...)` filter.
|
|
4856
|
-
*
|
|
4857
|
-
* Prefer `updateAll(...)` when you need the updated rows; prefer
|
|
4858
|
-
* this when you only need the affected-row count.
|
|
4859
|
-
*
|
|
4860
|
-
* ```typescript
|
|
4861
|
-
* const count = await db.orm.Post
|
|
4862
|
-
* .where({ published: false })
|
|
4863
|
-
* .updateAndCount({ published: true });
|
|
4864
|
-
* ```
|
|
4865
|
-
*/
|
|
4866
4581
|
async updateAndCount(data, configure) {
|
|
4867
4582
|
const mappedData = mapModelDataToStorageRow(this.contract, this.namespaceId, this.modelName, data);
|
|
4868
4583
|
if (Object.keys(mappedData).length === 0) return 0;
|
|
@@ -4871,20 +4586,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4871
4586
|
const compiled = mergeAnnotations(compileUpdateCount(this.contract, this.namespaceId, this.tableName, mappedData, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
|
|
4872
4587
|
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
4873
4588
|
}
|
|
4874
|
-
/**
|
|
4875
|
-
* Write terminal: delete a single matching row — the first one the
|
|
4876
|
-
* filter matches — and return it (or `null` when no row matched).
|
|
4877
|
-
* Requires a prior `.where(...)` — calling `delete()` on an
|
|
4878
|
-
* unfiltered collection is a type error.
|
|
4879
|
-
*
|
|
4880
|
-
* ```typescript
|
|
4881
|
-
* const deleted = await db.orm.User.where({ id: 1 }).delete();
|
|
4882
|
-
* if (deleted) console.log('deleted', deleted.email);
|
|
4883
|
-
* ```
|
|
4884
|
-
*
|
|
4885
|
-
* Accepts an optional `configure` callback that receives a
|
|
4886
|
-
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
4887
|
-
*/
|
|
4888
4589
|
async delete(configure) {
|
|
4889
4590
|
assertReturningCapability(this.contract, "delete()");
|
|
4890
4591
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "delete");
|
|
@@ -4895,31 +4596,8 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4895
4596
|
return (await scoped.#clone({ filters: [identityWhere] }).#executeDeleteReturning(annotationsMap).toArray())[0] ?? null;
|
|
4896
4597
|
});
|
|
4897
4598
|
}
|
|
4898
|
-
/**
|
|
4899
|
-
* Write terminal: delete every matching row and stream the deleted
|
|
4900
|
-
* rows. Requires a prior `.where(...)` filter.
|
|
4901
|
-
*
|
|
4902
|
-
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
4903
|
-
* resolves to `Row[]` AND an async iterable that streams deleted
|
|
4904
|
-
* rows as they arrive. Use whichever fits; a result can only be
|
|
4905
|
-
* consumed once. Streaming is the default; some driver/plan
|
|
4906
|
-
* combinations may still buffer internally before yielding.
|
|
4907
|
-
*
|
|
4908
|
-
* ```typescript
|
|
4909
|
-
* // Thenable — collect the deleted rows into an array:
|
|
4910
|
-
* const deleted = await db.orm.Post.where({ archived: true }).deleteAll();
|
|
4911
|
-
*
|
|
4912
|
-
* // Async iterable — stream deleted rows as they arrive:
|
|
4913
|
-
* for await (const row of db.orm.Post.where({ archived: true }).deleteAll()) {
|
|
4914
|
-
* console.log('removed', row.id);
|
|
4915
|
-
* }
|
|
4916
|
-
* ```
|
|
4917
|
-
*
|
|
4918
|
-
* Accepts an optional `configure` callback that receives a
|
|
4919
|
-
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
4920
|
-
*/
|
|
4921
4599
|
deleteAll(configure) {
|
|
4922
|
-
return
|
|
4600
|
+
return this.#deleteAllWithAnnotations(this.#collectAnnotationsFromMeta(configure, "write", "deleteAll"));
|
|
4923
4601
|
}
|
|
4924
4602
|
#deleteAllWithAnnotations(annotationsMap) {
|
|
4925
4603
|
assertReturningCapability(this.contract, "deleteAll()");
|
|
@@ -4976,18 +4654,6 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4976
4654
|
};
|
|
4977
4655
|
return new AsyncIterableResult(generator());
|
|
4978
4656
|
}
|
|
4979
|
-
/**
|
|
4980
|
-
* Write terminal: delete every matching row without returning them,
|
|
4981
|
-
* resolving to the count of rows that were deleted. Requires a prior
|
|
4982
|
-
* `.where(...)` filter.
|
|
4983
|
-
*
|
|
4984
|
-
* Prefer `deleteAll(...)` when you need the deleted rows; prefer
|
|
4985
|
-
* this when you only need the affected-row count.
|
|
4986
|
-
*
|
|
4987
|
-
* ```typescript
|
|
4988
|
-
* const removed = await db.orm.Post.where({ archived: true }).deleteAndCount();
|
|
4989
|
-
* ```
|
|
4990
|
-
*/
|
|
4991
4657
|
async deleteAndCount(configure) {
|
|
4992
4658
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "deleteAndCount");
|
|
4993
4659
|
const compiled = mergeAnnotations(compileDeleteCount(this.contract, this.namespaceId, this.tableName, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
|
|
@@ -5087,6 +4753,12 @@ var CollectionImpl = class CollectionImpl {
|
|
|
5087
4753
|
...overrides
|
|
5088
4754
|
});
|
|
5089
4755
|
}
|
|
4756
|
+
#cloneSelf(overrides) {
|
|
4757
|
+
return blindCast(this.#createSelf({
|
|
4758
|
+
...this.state,
|
|
4759
|
+
...overrides
|
|
4760
|
+
}));
|
|
4761
|
+
}
|
|
5090
4762
|
#withRuntime(runtime) {
|
|
5091
4763
|
return blindCast(new (blindCast(this.constructor))({
|
|
5092
4764
|
...this.ctx,
|
|
@@ -5115,7 +4787,7 @@ var CollectionImpl = class CollectionImpl {
|
|
|
5115
4787
|
}));
|
|
5116
4788
|
}
|
|
5117
4789
|
#createCollection(modelName, options) {
|
|
5118
|
-
return blindCast(new ((this.registry.get(modelName)) ?? (blindCast(
|
|
4790
|
+
return blindCast(new ((this.registry.get(modelName)) ?? (blindCast(CollectionBase)))(this.ctx, modelName, {
|
|
5119
4791
|
tableName: options.tableName,
|
|
5120
4792
|
namespaceId: options.namespaceId,
|
|
5121
4793
|
state: options.state,
|
|
@@ -5190,17 +4862,9 @@ const collectionInstanceMemberNames = [
|
|
|
5190
4862
|
* so ORM composition rejects any operation this set contains.
|
|
5191
4863
|
*/
|
|
5192
4864
|
function reservedCollectionMemberNames() {
|
|
5193
|
-
return /* @__PURE__ */ new Set([...Object.getOwnPropertyNames(
|
|
4865
|
+
return /* @__PURE__ */ new Set([...Object.getOwnPropertyNames(CollectionBase.prototype), ...collectionInstanceMemberNames]);
|
|
5194
4866
|
}
|
|
5195
|
-
const Collection = blindCast(
|
|
5196
|
-
/**
|
|
5197
|
-
* The class behind {@link Collection}, for package-internal prototype-chain
|
|
5198
|
-
* checks (`instanceof`) and default construction. The public constructor
|
|
5199
|
-
* surface carries a single construct signature returning the intersection,
|
|
5200
|
-
* which heritage clauses require; the raw class keeps the `Function` shape
|
|
5201
|
-
* those checks need.
|
|
5202
|
-
*/
|
|
5203
|
-
const CollectionBase = CollectionImpl;
|
|
4867
|
+
const Collection = blindCast(CollectionBase);
|
|
5204
4868
|
/**
|
|
5205
4869
|
* Reject a contributed aggregate operation whose name a collection member
|
|
5206
4870
|
* already owns. Aggregate operations surface as reducer methods on the
|