@zenstackhq/runtime 3.0.0-alpha.17 → 3.0.0-alpha.19

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.
@@ -96,7 +96,7 @@ type BatchResult = {
96
96
  count: number;
97
97
  };
98
98
  type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ScalarOnly extends boolean = false> = {
99
- [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: Key extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Key> : GetModelFieldType<Schema, Model, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>> : FieldIsArray<Schema, Model, Key> extends true ? ArrayFilter<GetModelFieldType<Schema, Model, Key>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>>;
99
+ [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: Key extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Key> : GetModelFieldType<Schema, Model, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>> : FieldIsArray<Schema, Model, Key> extends true ? ArrayFilter<GetModelFieldType<Schema, Model, Key>> : PrimitiveFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>>;
100
100
  } & {
101
101
  $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
102
102
  } & {
@@ -117,8 +117,8 @@ type ArrayFilter<T extends string> = {
117
117
  hasSome?: MapBaseType$1<T>[];
118
118
  isEmpty?: boolean;
119
119
  };
120
- type PrimitiveFilter<T extends string, Nullable extends boolean> = T extends 'String' ? StringFilter<Nullable> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable> : T extends 'Boolean' ? BooleanFilter<Nullable> : T extends 'DateTime' ? DateTimeFilter<Nullable> : T extends 'Bytes' ? BytesFilter<Nullable> : T extends 'Json' ? 'Not implemented yet' : never;
121
- type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean> = {
120
+ type PrimitiveFilter<Schema extends SchemaDef, T extends string, Nullable extends boolean> = T extends 'String' ? StringFilter<Schema, Nullable> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<Schema, T, Nullable> : T extends 'Boolean' ? BooleanFilter<Nullable> : T extends 'DateTime' ? DateTimeFilter<Schema, Nullable> : T extends 'Bytes' ? BytesFilter<Nullable> : T extends 'Json' ? 'Not implemented yet' : never;
121
+ type CommonPrimitiveFilter<Schema extends SchemaDef, DataType, T extends BuiltinType, Nullable extends boolean> = {
122
122
  equals?: NullableIf<DataType, Nullable>;
123
123
  in?: DataType[];
124
124
  notIn?: DataType[];
@@ -126,16 +126,17 @@ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boo
126
126
  lte?: DataType;
127
127
  gt?: DataType;
128
128
  gte?: DataType;
129
- not?: PrimitiveFilter<T, Nullable>;
129
+ not?: PrimitiveFilter<Schema, T, Nullable>;
130
130
  };
131
- type StringFilter<Nullable extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<string, 'String', Nullable> & {
131
+ type StringFilter<Schema extends SchemaDef, Nullable extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<Schema, string, 'String', Nullable> & {
132
132
  contains?: string;
133
133
  startsWith?: string;
134
134
  endsWith?: string;
135
+ } & (ProviderSupportsCaseSensitivity<Schema> extends true ? {
135
136
  mode?: 'default' | 'insensitive';
136
- });
137
- type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean> = NullableIf<number | bigint, Nullable> | CommonPrimitiveFilter<number, T, Nullable>;
138
- type DateTimeFilter<Nullable extends boolean> = NullableIf<Date | string, Nullable> | CommonPrimitiveFilter<Date | string, 'DateTime', Nullable>;
137
+ } : {}));
138
+ type NumberFilter<Schema extends SchemaDef, T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean> = NullableIf<number | bigint, Nullable> | CommonPrimitiveFilter<Schema, number, T, Nullable>;
139
+ type DateTimeFilter<Schema extends SchemaDef, Nullable extends boolean> = NullableIf<Date | string, Nullable> | CommonPrimitiveFilter<Schema, Date | string, 'DateTime', Nullable>;
139
140
  type BytesFilter<Nullable extends boolean> = NullableIf<Uint8Array | Buffer, Nullable> | {
140
141
  equals?: NullableIf<Uint8Array, Nullable>;
141
142
  in?: Uint8Array[];
@@ -187,9 +188,9 @@ type Cursor<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
187
188
  type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
188
189
  [Key in NonRelationFields<Schema, Model>]?: true;
189
190
  } & (AllowRelation extends true ? IncludeInput<Schema, Model> : {}) & // relation fields
190
- (AllowCount extends true ? {
191
+ (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
191
192
  _count?: SelectCount<Schema, Model>;
192
- } : {});
193
+ } : {} : {});
193
194
  type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = true | {
194
195
  select: {
195
196
  [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true | {
@@ -486,6 +487,10 @@ type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Sc
486
487
  references: unknown[];
487
488
  } ? never : Key]: true;
488
489
  };
490
+ type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
491
+ [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
492
+ } extends never ? false : true;
493
+ type ProviderSupportsCaseSensitivity<Schema extends SchemaDef> = Schema['provider'] extends 'postgresql' ? true : false;
489
494
 
490
495
  type AuthType<Schema extends SchemaDef> = string extends GetModels<Schema> ? Record<string, unknown> : Schema['authType'] extends GetModels<Schema> ? Partial<ModelResult<Schema, Schema['authType']>> : never;
491
496
 
@@ -520,6 +525,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
520
525
  buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit?: Record<string, boolean | undefined>): SelectQueryBuilder<any, any, any>;
521
526
  buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
522
527
  buildDelegateJoin(thisModel: string, otherModel: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
528
+ buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
523
529
  private negateSort;
524
530
  true(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
525
531
  false(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
@@ -561,6 +567,10 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
561
567
  * Whether the dialect supports DISTINCT ON.
562
568
  */
563
569
  abstract get supportsDistinctOn(): boolean;
570
+ /**
571
+ * Whether the dialect support inserting with `DEFAULT` as field value.
572
+ */
573
+ abstract get supportInsertWithDefault(): boolean;
564
574
  }
565
575
 
566
576
  type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
@@ -796,7 +806,7 @@ type ClientContract<Schema extends SchemaDef> = {
796
806
  * Executes a prepared raw query and returns the number of affected rows.
797
807
  * @example
798
808
  * ```
799
- * const result = await client.$executeRaw`UPDATE User SET cool = ${true} WHERE email = ${'user@email.com'};`
809
+ * const result = await db.$executeRaw`UPDATE User SET cool = ${true} WHERE email = ${'user@email.com'};`
800
810
  * ```
801
811
  */
802
812
  $executeRaw(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, number>;
@@ -805,7 +815,7 @@ type ClientContract<Schema extends SchemaDef> = {
805
815
  * This method is susceptible to SQL injections.
806
816
  * @example
807
817
  * ```
808
- * const result = await client.$executeRawUnsafe('UPDATE User SET cool = $1 WHERE email = $2 ;', true, 'user@email.com')
818
+ * const result = await db.$executeRawUnsafe('UPDATE User SET cool = $1 WHERE email = $2 ;', true, 'user@email.com')
809
819
  * ```
810
820
  */
811
821
  $executeRawUnsafe(query: string, ...values: any[]): ZenStackPromise<Schema, number>;
@@ -813,7 +823,7 @@ type ClientContract<Schema extends SchemaDef> = {
813
823
  * Performs a prepared raw query and returns the `SELECT` data.
814
824
  * @example
815
825
  * ```
816
- * const result = await client.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'user@email.com'};`
826
+ * const result = await db.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'user@email.com'};`
817
827
  * ```
818
828
  */
819
829
  $queryRaw<T = unknown>(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, T>;
@@ -822,7 +832,7 @@ type ClientContract<Schema extends SchemaDef> = {
822
832
  * This method is susceptible to SQL injections.
823
833
  * @example
824
834
  * ```
825
- * const result = await client.$queryRawUnsafe('SELECT * FROM User WHERE id = $1 OR email = $2;', 1, 'user@email.com')
835
+ * const result = await db.$queryRawUnsafe('SELECT * FROM User WHERE id = $1 OR email = $2;', 1, 'user@email.com')
826
836
  * ```
827
837
  */
828
838
  $queryRawUnsafe<T = unknown>(query: string, ...values: any[]): ZenStackPromise<Schema, T>;
@@ -920,17 +930,17 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
920
930
  * @example
921
931
  * ```ts
922
932
  * // find all users and return all scalar fields
923
- * await client.user.findMany();
933
+ * await db.user.findMany();
924
934
  *
925
935
  * // find all users with name 'Alex'
926
- * await client.user.findMany({
936
+ * await db.user.findMany({
927
937
  * where: {
928
938
  * name: 'Alex'
929
939
  * }
930
940
  * });
931
941
  *
932
942
  * // select fields
933
- * await client.user.findMany({
943
+ * await db.user.findMany({
934
944
  * select: {
935
945
  * name: true,
936
946
  * email: true,
@@ -938,21 +948,21 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
938
948
  * }); // result: `Array<{ name: string, email: string }>`
939
949
  *
940
950
  * // omit fields
941
- * await client.user.findMany({
951
+ * await db.user.findMany({
942
952
  * omit: {
943
953
  * name: true,
944
954
  * }
945
955
  * }); // result: `Array<{ id: number; email: string; ... }>`
946
956
  *
947
957
  * // include relations (and all scalar fields)
948
- * await client.user.findMany({
958
+ * await db.user.findMany({
949
959
  * include: {
950
960
  * posts: true,
951
961
  * }
952
962
  * }); // result: `Array<{ ...; posts: Post[] }>`
953
963
  *
954
964
  * // include relations with filter
955
- * await client.user.findMany({
965
+ * await db.user.findMany({
956
966
  * include: {
957
967
  * posts: {
958
968
  * where: {
@@ -963,14 +973,14 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
963
973
  * });
964
974
  *
965
975
  * // pagination and sorting
966
- * await client.user.findMany({
976
+ * await db.user.findMany({
967
977
  * skip: 10,
968
978
  * take: 10,
969
979
  * orderBy: [{ name: 'asc' }, { email: 'desc' }],
970
980
  * });
971
981
  *
972
982
  * // pagination with cursor (https://www.prisma.io/docs/orm/prisma-client/queries/pagination#cursor-based-pagination)
973
- * await client.user.findMany({
983
+ * await db.user.findMany({
974
984
  * cursor: { id: 10 },
975
985
  * skip: 1,
976
986
  * take: 10,
@@ -978,17 +988,17 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
978
988
  * });
979
989
  *
980
990
  * // distinct
981
- * await client.user.findMany({
991
+ * await db.user.findMany({
982
992
  * distinct: ['name']
983
993
  * });
984
994
  *
985
995
  * // count all relations
986
- * await client.user.findMany({
996
+ * await db.user.findMany({
987
997
  * _count: true,
988
998
  * }); // result: `{ _count: { posts: number; ... } }`
989
999
  *
990
1000
  * // count selected relations
991
- * await client.user.findMany({
1001
+ * await db.user.findMany({
992
1002
  * _count: { select: { posts: true } },
993
1003
  * }); // result: `{ _count: { posts: number } }`
994
1004
  * ```
@@ -1000,14 +1010,14 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1000
1010
  * @returns a single entity or null if not found
1001
1011
  * @see {@link findMany}
1002
1012
  */
1003
- findUnique<T extends FindUniqueArgs<Schema, Model>>(args?: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
1013
+ findUnique<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
1004
1014
  /**
1005
1015
  * Returns a uniquely identified entity or throws `NotFoundError` if not found.
1006
1016
  * @param args - query args
1007
1017
  * @returns a single entity
1008
1018
  * @see {@link findMany}
1009
1019
  */
1010
- findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args?: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1020
+ findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1011
1021
  /**
1012
1022
  * Returns the first entity.
1013
1023
  * @param args - query args
@@ -1030,12 +1040,12 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1030
1040
  * @example
1031
1041
  * ```ts
1032
1042
  * // simple create
1033
- * await client.user.create({
1043
+ * await db.user.create({
1034
1044
  * data: { name: 'Alex', email: 'alex@zenstack.dev' }
1035
1045
  * });
1036
1046
  *
1037
1047
  * // nested create with relation
1038
- * await client.user.create({
1048
+ * await db.user.create({
1039
1049
  * data: {
1040
1050
  * email: 'alex@zenstack.dev',
1041
1051
  * posts: { create: { title: 'Hello World' } }
@@ -1044,7 +1054,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1044
1054
  *
1045
1055
  * // you can use `select`, `omit`, and `include` to control
1046
1056
  * // the fields returned by the query, as with `findMany`
1047
- * await client.user.create({
1057
+ * await db.user.create({
1048
1058
  * data: {
1049
1059
  * email: 'alex@zenstack.dev',
1050
1060
  * posts: { create: { title: 'Hello World' } }
@@ -1053,7 +1063,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1053
1063
  * }); // result: `{ id: number; posts: Post[] }`
1054
1064
  *
1055
1065
  * // connect relations
1056
- * await client.user.create({
1066
+ * await db.user.create({
1057
1067
  * data: {
1058
1068
  * email: 'alex@zenstack.dev',
1059
1069
  * posts: { connect: { id: 1 } }
@@ -1061,7 +1071,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1061
1071
  * });
1062
1072
  *
1063
1073
  * // connect relations, and create if not found
1064
- * await client.user.create({
1074
+ * await db.user.create({
1065
1075
  * data: {
1066
1076
  * email: 'alex@zenstack.dev',
1067
1077
  * posts: {
@@ -1083,7 +1093,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1083
1093
  * @example
1084
1094
  * ```ts
1085
1095
  * // create multiple entities
1086
- * await client.user.createMany({
1096
+ * await db.user.createMany({
1087
1097
  * data: [
1088
1098
  * { name: 'Alex', email: 'alex@zenstack.dev' },
1089
1099
  * { name: 'John', email: 'john@zenstack.dev' }
@@ -1091,7 +1101,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1091
1101
  * });
1092
1102
  *
1093
1103
  * // skip items that cause unique constraint violation
1094
- * await client.user.createMany({
1104
+ * await db.user.createMany({
1095
1105
  * data: [
1096
1106
  * { name: 'Alex', email: 'alex@zenstack.dev' },
1097
1107
  * { name: 'John', email: 'john@zenstack.dev' }
@@ -1110,7 +1120,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1110
1120
  * @example
1111
1121
  * ```ts
1112
1122
  * // create multiple entities and return selected fields
1113
- * await client.user.createManyAndReturn({
1123
+ * await db.user.createManyAndReturn({
1114
1124
  * data: [
1115
1125
  * { name: 'Alex', email: 'alex@zenstack.dev' },
1116
1126
  * { name: 'John', email: 'john@zenstack.dev' }
@@ -1129,19 +1139,19 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1129
1139
  * @example
1130
1140
  * ```ts
1131
1141
  * // update fields
1132
- * await client.user.update({
1142
+ * await db.user.update({
1133
1143
  * where: { id: 1 },
1134
1144
  * data: { name: 'Alex' }
1135
1145
  * });
1136
1146
  *
1137
1147
  * // connect a relation
1138
- * await client.user.update({
1148
+ * await db.user.update({
1139
1149
  * where: { id: 1 },
1140
1150
  * data: { posts: { connect: { id: 1 } } }
1141
1151
  * });
1142
1152
  *
1143
1153
  * // connect relation, and create if not found
1144
- * await client.user.update({
1154
+ * await db.user.update({
1145
1155
  * where: { id: 1 },
1146
1156
  * data: {
1147
1157
  * posts: {
@@ -1154,7 +1164,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1154
1164
  * });
1155
1165
  *
1156
1166
  * // create many related entities (only available for one-to-many relations)
1157
- * await client.user.update({
1167
+ * await db.user.update({
1158
1168
  * where: { id: 1 },
1159
1169
  * data: {
1160
1170
  * posts: {
@@ -1166,19 +1176,19 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1166
1176
  * });
1167
1177
  *
1168
1178
  * // disconnect a one-to-many relation
1169
- * await client.user.update({
1179
+ * await db.user.update({
1170
1180
  * where: { id: 1 },
1171
1181
  * data: { posts: { disconnect: { id: 1 } } }
1172
1182
  * });
1173
1183
  *
1174
1184
  * // disconnect a one-to-one relation
1175
- * await client.user.update({
1185
+ * await db.user.update({
1176
1186
  * where: { id: 1 },
1177
1187
  * data: { profile: { disconnect: true } }
1178
1188
  * });
1179
1189
  *
1180
1190
  * // replace a relation (only available for one-to-many relations)
1181
- * await client.user.update({
1191
+ * await db.user.update({
1182
1192
  * where: { id: 1 },
1183
1193
  * data: {
1184
1194
  * posts: {
@@ -1188,7 +1198,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1188
1198
  * });
1189
1199
  *
1190
1200
  * // update a relation
1191
- * await client.user.update({
1201
+ * await db.user.update({
1192
1202
  * where: { id: 1 },
1193
1203
  * data: {
1194
1204
  * posts: {
@@ -1198,7 +1208,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1198
1208
  * });
1199
1209
  *
1200
1210
  * // upsert a relation
1201
- * await client.user.update({
1211
+ * await db.user.update({
1202
1212
  * where: { id: 1 },
1203
1213
  * data: {
1204
1214
  * posts: {
@@ -1212,7 +1222,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1212
1222
  * });
1213
1223
  *
1214
1224
  * // update many related entities (only available for one-to-many relations)
1215
- * await client.user.update({
1225
+ * await db.user.update({
1216
1226
  * where: { id: 1 },
1217
1227
  * data: {
1218
1228
  * posts: {
@@ -1225,13 +1235,13 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1225
1235
  * });
1226
1236
  *
1227
1237
  * // delete a one-to-many relation
1228
- * await client.user.update({
1238
+ * await db.user.update({
1229
1239
  * where: { id: 1 },
1230
1240
  * data: { posts: { delete: { id: 1 } } }
1231
1241
  * });
1232
1242
  *
1233
1243
  * // delete a one-to-one relation
1234
- * await client.user.update({
1244
+ * await db.user.update({
1235
1245
  * where: { id: 1 },
1236
1246
  * data: { profile: { delete: true } }
1237
1247
  * });
@@ -1246,13 +1256,13 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1246
1256
  * @example
1247
1257
  * ```ts
1248
1258
  * // update many entities
1249
- * await client.user.updateMany({
1259
+ * await db.user.updateMany({
1250
1260
  * where: { email: { endsWith: '@zenstack.dev' } },
1251
1261
  * data: { role: 'ADMIN' }
1252
1262
  * });
1253
1263
  *
1254
1264
  * // limit the number of updated entities
1255
- * await client.user.updateMany({
1265
+ * await db.user.updateMany({
1256
1266
  * where: { email: { endsWith: '@zenstack.dev' } },
1257
1267
  * data: { role: 'ADMIN' },
1258
1268
  * limit: 10
@@ -1267,14 +1277,14 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1267
1277
  * @example
1268
1278
  * ```ts
1269
1279
  * // update many entities and return selected fields
1270
- * await client.user.updateManyAndReturn({
1280
+ * await db.user.updateManyAndReturn({
1271
1281
  * where: { email: { endsWith: '@zenstack.dev' } },
1272
1282
  * data: { role: 'ADMIN' },
1273
1283
  * select: { id: true, email: true }
1274
1284
  * }); // result: `Array<{ id: string; email: string }>`
1275
1285
  *
1276
1286
  * // limit the number of updated entities
1277
- * await client.user.updateManyAndReturn({
1287
+ * await db.user.updateManyAndReturn({
1278
1288
  * where: { email: { endsWith: '@zenstack.dev' } },
1279
1289
  * data: { role: 'ADMIN' },
1280
1290
  * limit: 10
@@ -1290,7 +1300,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1290
1300
  * @example
1291
1301
  * ```ts
1292
1302
  * // upsert an entity
1293
- * await client.user.upsert({
1303
+ * await db.user.upsert({
1294
1304
  * // `where` clause is used to find the entity
1295
1305
  * where: { id: 1 },
1296
1306
  * // `create` clause is used if the entity is not found
@@ -1311,12 +1321,12 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1311
1321
  * @example
1312
1322
  * ```ts
1313
1323
  * // delete an entity
1314
- * await client.user.delete({
1324
+ * await db.user.delete({
1315
1325
  * where: { id: 1 }
1316
1326
  * });
1317
1327
  *
1318
1328
  * // delete an entity and return selected fields
1319
- * await client.user.delete({
1329
+ * await db.user.delete({
1320
1330
  * where: { id: 1 },
1321
1331
  * select: { id: true, email: true }
1322
1332
  * }); // result: `{ id: string; email: string }`
@@ -1331,12 +1341,12 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1331
1341
  * @example
1332
1342
  * ```ts
1333
1343
  * // delete many entities
1334
- * await client.user.deleteMany({
1344
+ * await db.user.deleteMany({
1335
1345
  * where: { email: { endsWith: '@zenstack.dev' } }
1336
1346
  * });
1337
1347
  *
1338
1348
  * // limit the number of deleted entities
1339
- * await client.user.deleteMany({
1349
+ * await db.user.deleteMany({
1340
1350
  * where: { email: { endsWith: '@zenstack.dev' } },
1341
1351
  * limit: 10
1342
1352
  * });
@@ -1351,13 +1361,13 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1351
1361
  * @example
1352
1362
  * ```ts
1353
1363
  * // count all
1354
- * await client.user.count();
1364
+ * await db.user.count();
1355
1365
  *
1356
1366
  * // count with a filter
1357
- * await client.user.count({ where: { email: { endsWith: '@zenstack.dev' } } });
1367
+ * await db.user.count({ where: { email: { endsWith: '@zenstack.dev' } } });
1358
1368
  *
1359
1369
  * // count rows and field values
1360
- * await client.user.count({
1370
+ * await db.user.count({
1361
1371
  * select: { _all: true, email: true }
1362
1372
  * }); // result: `{ _all: number, email: number }`
1363
1373
  */
@@ -1370,7 +1380,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1370
1380
  * @example
1371
1381
  * ```ts
1372
1382
  * // aggregate rows
1373
- * await client.profile.aggregate({
1383
+ * await db.profile.aggregate({
1374
1384
  * where: { email: { endsWith: '@zenstack.dev' } },
1375
1385
  * _count: true,
1376
1386
  * _avg: { age: true },
@@ -1388,26 +1398,26 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
1388
1398
  * @example
1389
1399
  * ```ts
1390
1400
  * // group by a field
1391
- * await client.profile.groupBy({
1401
+ * await db.profile.groupBy({
1392
1402
  * by: 'country',
1393
1403
  * _count: true
1394
1404
  * }); // result: `Array<{ country: string, _count: number }>`
1395
1405
  *
1396
1406
  * // group by multiple fields
1397
- * await client.profile.groupBy({
1407
+ * await db.profile.groupBy({
1398
1408
  * by: ['country', 'city'],
1399
1409
  * _count: true
1400
1410
  * }); // result: `Array<{ country: string, city: string, _count: number }>`
1401
1411
  *
1402
1412
  * // group by with sorting, the `orderBy` fields must be in the `by` list
1403
- * await client.profile.groupBy({
1413
+ * await db.profile.groupBy({
1404
1414
  * by: 'country',
1405
1415
  * orderBy: { country: 'desc' }
1406
1416
  * });
1407
1417
  *
1408
1418
  * // group by with having (post-aggregation filter), the `having` fields must
1409
1419
  * // be in the `by` list
1410
- * await client.profile.groupBy({
1420
+ * await db.profile.groupBy({
1411
1421
  * by: 'country',
1412
1422
  * having: { country: 'US' }
1413
1423
  * });