drizzle-kit 1.0.0-beta.1-34ee105 → 1.0.0-beta.1-a7dd17f

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.
Files changed (4) hide show
  1. package/api.js +494 -116
  2. package/api.mjs +494 -116
  3. package/bin.cjs +1 -1
  4. package/package.json +1 -1
package/api.mjs CHANGED
@@ -3484,17 +3484,17 @@ function processCreateParams(params) {
3484
3484
  if (errorMap2)
3485
3485
  return { errorMap: errorMap2, description };
3486
3486
  const customMap = (iss, ctx) => {
3487
- var _a456, _b336;
3487
+ var _a460, _b339;
3488
3488
  const { message } = params;
3489
3489
  if (iss.code === "invalid_enum_value") {
3490
3490
  return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
3491
3491
  }
3492
3492
  if (typeof ctx.data === "undefined") {
3493
- return { message: (_a456 = message !== null && message !== void 0 ? message : required_error) !== null && _a456 !== void 0 ? _a456 : ctx.defaultError };
3493
+ return { message: (_a460 = message !== null && message !== void 0 ? message : required_error) !== null && _a460 !== void 0 ? _a460 : ctx.defaultError };
3494
3494
  }
3495
3495
  if (iss.code !== "invalid_type")
3496
3496
  return { message: ctx.defaultError };
3497
- return { message: (_b336 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b336 !== void 0 ? _b336 : ctx.defaultError };
3497
+ return { message: (_b339 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b339 !== void 0 ? _b339 : ctx.defaultError };
3498
3498
  };
3499
3499
  return { errorMap: customMap, description };
3500
3500
  }
@@ -4156,11 +4156,11 @@ var init_lib = __esm({
4156
4156
  throw result.error;
4157
4157
  }
4158
4158
  safeParse(data, params) {
4159
- var _a456;
4159
+ var _a460;
4160
4160
  const ctx = {
4161
4161
  common: {
4162
4162
  issues: [],
4163
- async: (_a456 = params === null || params === void 0 ? void 0 : params.async) !== null && _a456 !== void 0 ? _a456 : false,
4163
+ async: (_a460 = params === null || params === void 0 ? void 0 : params.async) !== null && _a460 !== void 0 ? _a460 : false,
4164
4164
  contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
4165
4165
  },
4166
4166
  path: (params === null || params === void 0 ? void 0 : params.path) || [],
@@ -4482,7 +4482,7 @@ var init_lib = __esm({
4482
4482
  } else if (check.kind === "url") {
4483
4483
  try {
4484
4484
  new URL(input.data);
4485
- } catch (_a456) {
4485
+ } catch (_a460) {
4486
4486
  ctx = this._getOrReturnCtx(input, ctx);
4487
4487
  addIssueToContext(ctx, {
4488
4488
  validation: "url",
@@ -4652,7 +4652,7 @@ var init_lib = __esm({
4652
4652
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
4653
4653
  }
4654
4654
  datetime(options) {
4655
- var _a456, _b336;
4655
+ var _a460, _b339;
4656
4656
  if (typeof options === "string") {
4657
4657
  return this._addCheck({
4658
4658
  kind: "datetime",
@@ -4665,8 +4665,8 @@ var init_lib = __esm({
4665
4665
  return this._addCheck({
4666
4666
  kind: "datetime",
4667
4667
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
4668
- offset: (_a456 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a456 !== void 0 ? _a456 : false,
4669
- local: (_b336 = options === null || options === void 0 ? void 0 : options.local) !== null && _b336 !== void 0 ? _b336 : false,
4668
+ offset: (_a460 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a460 !== void 0 ? _a460 : false,
4669
+ local: (_b339 = options === null || options === void 0 ? void 0 : options.local) !== null && _b339 !== void 0 ? _b339 : false,
4670
4670
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
4671
4671
  });
4672
4672
  }
@@ -4829,11 +4829,11 @@ var init_lib = __esm({
4829
4829
  }
4830
4830
  };
4831
4831
  ZodString.create = (params) => {
4832
- var _a456;
4832
+ var _a460;
4833
4833
  return new ZodString({
4834
4834
  checks: [],
4835
4835
  typeName: ZodFirstPartyTypeKind.ZodString,
4836
- coerce: (_a456 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a456 !== void 0 ? _a456 : false,
4836
+ coerce: (_a460 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a460 !== void 0 ? _a460 : false,
4837
4837
  ...processCreateParams(params)
4838
4838
  });
4839
4839
  };
@@ -5226,11 +5226,11 @@ var init_lib = __esm({
5226
5226
  }
5227
5227
  };
5228
5228
  ZodBigInt.create = (params) => {
5229
- var _a456;
5229
+ var _a460;
5230
5230
  return new ZodBigInt({
5231
5231
  checks: [],
5232
5232
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
5233
- coerce: (_a456 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a456 !== void 0 ? _a456 : false,
5233
+ coerce: (_a460 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a460 !== void 0 ? _a460 : false,
5234
5234
  ...processCreateParams(params)
5235
5235
  });
5236
5236
  };
@@ -5710,8 +5710,8 @@ var init_lib = __esm({
5710
5710
  unknownKeys: "strict",
5711
5711
  ...message !== void 0 ? {
5712
5712
  errorMap: (issue, ctx) => {
5713
- var _a456, _b336, _c14, _d6;
5714
- const defaultError = (_c14 = (_b336 = (_a456 = this._def).errorMap) === null || _b336 === void 0 ? void 0 : _b336.call(_a456, issue, ctx).message) !== null && _c14 !== void 0 ? _c14 : ctx.defaultError;
5713
+ var _a460, _b339, _c14, _d6;
5714
+ const defaultError = (_c14 = (_b339 = (_a460 = this._def).errorMap) === null || _b339 === void 0 ? void 0 : _b339.call(_a460, issue, ctx).message) !== null && _c14 !== void 0 ? _c14 : ctx.defaultError;
5715
5715
  if (issue.code === "unrecognized_keys")
5716
5716
  return {
5717
5717
  message: (_d6 = errorUtil.errToObj(message).message) !== null && _d6 !== void 0 ? _d6 : defaultError
@@ -23063,8 +23063,8 @@ var init_sql = __esm({
23063
23063
  sql2.param = param2;
23064
23064
  })(sql || (sql = {}));
23065
23065
  ((SQL2) => {
23066
- var _a456;
23067
- _a456 = entityKind;
23066
+ var _a460;
23067
+ _a460 = entityKind;
23068
23068
  const _Aliased = class _Aliased {
23069
23069
  constructor(sql2, fieldAlias) {
23070
23070
  /** @internal */
@@ -23080,7 +23080,7 @@ var init_sql = __esm({
23080
23080
  return new _Aliased(this.sql, this.fieldAlias);
23081
23081
  }
23082
23082
  };
23083
- __publicField(_Aliased, _a456, "SQL.Aliased");
23083
+ __publicField(_Aliased, _a460, "SQL.Aliased");
23084
23084
  let Aliased = _Aliased;
23085
23085
  SQL2.Aliased = Aliased;
23086
23086
  })(SQL || (SQL = {}));
@@ -23727,12 +23727,15 @@ function buildRelationsParts(tables, config) {
23727
23727
  function getOrderByOperators() {
23728
23728
  return orderByOperators;
23729
23729
  }
23730
- function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, path2) {
23730
+ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, parseJsonIfString = false, path2) {
23731
23731
  for (const selectionItem of buildQueryResultSelection) {
23732
23732
  if (selectionItem.selection) {
23733
23733
  const currentPath = `${path2 ? `${path2}.` : ""}${selectionItem.key}`;
23734
23734
  if (row[selectionItem.key] === null) continue;
23735
23735
  if (parseJson) row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
23736
+ if (parseJsonIfString && typeof row[selectionItem.key] === "string") {
23737
+ row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
23738
+ }
23736
23739
  if (selectionItem.isArray) {
23737
23740
  for (const item of row[selectionItem.key]) {
23738
23741
  mapRelationalRow(
@@ -23740,6 +23743,7 @@ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (valu
23740
23743
  selectionItem.selection,
23741
23744
  mapColumnValue,
23742
23745
  false,
23746
+ parseJsonIfString,
23743
23747
  currentPath
23744
23748
  );
23745
23749
  }
@@ -23750,6 +23754,7 @@ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (valu
23750
23754
  selectionItem.selection,
23751
23755
  mapColumnValue,
23752
23756
  false,
23757
+ parseJsonIfString,
23753
23758
  currentPath
23754
23759
  );
23755
23760
  continue;
@@ -24516,6 +24521,7 @@ function isConfig(data) {
24516
24521
  if (Object.keys(data).length === 0) return true;
24517
24522
  return false;
24518
24523
  }
24524
+ var textDecoder;
24519
24525
  var init_utils2 = __esm({
24520
24526
  "../drizzle-orm/dist/utils.js"() {
24521
24527
  "use strict";
@@ -24525,6 +24531,7 @@ var init_utils2 = __esm({
24525
24531
  init_subquery();
24526
24532
  init_table();
24527
24533
  init_view_common();
24534
+ textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
24528
24535
  }
24529
24536
  });
24530
24537
 
@@ -24662,7 +24669,8 @@ __export(dist_exports, {
24662
24669
  relationsOrderToSQL: () => relationsOrderToSQL,
24663
24670
  sql: () => sql,
24664
24671
  sum: () => sum,
24665
- sumDistinct: () => sumDistinct
24672
+ sumDistinct: () => sumDistinct,
24673
+ textDecoder: () => textDecoder
24666
24674
  });
24667
24675
  var init_dist = __esm({
24668
24676
  "../drizzle-orm/dist/index.js"() {
@@ -32825,6 +32833,15 @@ var init_common3 = __esm({
32825
32833
  });
32826
32834
 
32827
32835
  // ../drizzle-orm/dist/sqlite-core/columns/blob.js
32836
+ function hexToText(hexString) {
32837
+ let result = "";
32838
+ for (let i = 0; i < hexString.length; i += 2) {
32839
+ const hexPair = hexString.substring(i, i + 2);
32840
+ const decimalValue = parseInt(hexPair, 16);
32841
+ result += String.fromCharCode(decimalValue);
32842
+ }
32843
+ return result;
32844
+ }
32828
32845
  function blob(a, b) {
32829
32846
  const { name: name2, config } = getColumnNameAndConfig(a, b);
32830
32847
  if (config?.mode === "json") {
@@ -32857,17 +32874,14 @@ var init_blob = __esm({
32857
32874
  return "blob";
32858
32875
  }
32859
32876
  mapFromDriverValue(value) {
32860
- if (Buffer.isBuffer(value)) {
32861
- return BigInt(value.toString());
32862
- }
32863
32877
  if (typeof value === "string") {
32864
- return BigInt(Buffer.from(value, "hex").toString());
32878
+ return BigInt(hexToText(value));
32865
32879
  }
32866
- if (value instanceof ArrayBuffer) {
32867
- const decoder = new TextDecoder();
32868
- return BigInt(decoder.decode(value));
32880
+ if (typeof Buffer !== "undefined" && Buffer.from) {
32881
+ const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
32882
+ return BigInt(buf.toString("utf8"));
32869
32883
  }
32870
- return BigInt(String.fromCodePoint(...value));
32884
+ return BigInt(textDecoder.decode(value));
32871
32885
  }
32872
32886
  mapToDriverValue(value) {
32873
32887
  return Buffer.from(value.toString());
@@ -32892,17 +32906,14 @@ var init_blob = __esm({
32892
32906
  return "blob";
32893
32907
  }
32894
32908
  mapFromDriverValue(value) {
32895
- if (Buffer.isBuffer(value)) {
32896
- return JSON.parse(value.toString());
32897
- }
32898
32909
  if (typeof value === "string") {
32899
- return JSON.parse(Buffer.from(value, "hex").toString());
32910
+ return JSON.parse(hexToText(value));
32900
32911
  }
32901
- if (value instanceof ArrayBuffer) {
32902
- const decoder = new TextDecoder();
32903
- return JSON.parse(decoder.decode(value));
32912
+ if (typeof Buffer !== "undefined" && Buffer.from) {
32913
+ const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
32914
+ return JSON.parse(buf.toString("utf8"));
32904
32915
  }
32905
- return JSON.parse(String.fromCodePoint(...value));
32916
+ return JSON.parse(textDecoder.decode(value));
32906
32917
  }
32907
32918
  mapToDriverValue(value) {
32908
32919
  return Buffer.from(JSON.stringify(value));
@@ -40606,7 +40617,7 @@ var init_dialect3 = __esm({
40606
40617
  mode,
40607
40618
  errorPath,
40608
40619
  depth,
40609
- isNested,
40620
+ isNestedMany,
40610
40621
  throughJoin
40611
40622
  }) {
40612
40623
  const selection = [];
@@ -40655,7 +40666,7 @@ var init_dialect3 = __esm({
40655
40666
  relationWhere: filter2,
40656
40667
  errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
40657
40668
  depth: currentDepth + 1,
40658
- isNested: true,
40669
+ isNestedMany: !isSingle2,
40659
40670
  throughJoin: throughJoin2
40660
40671
  });
40661
40672
  selection.push({
@@ -40680,7 +40691,7 @@ var init_dialect3 = __esm({
40680
40691
  message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}`
40681
40692
  });
40682
40693
  }
40683
- if (isNested && order) {
40694
+ if (isNestedMany && order) {
40684
40695
  selectionArr.push(sql`row_number() over (order by ${order})`);
40685
40696
  }
40686
40697
  const selectionSet = sql.join(selectionArr, sql`, `);
@@ -44610,6 +44621,10 @@ var init_float2 = __esm({
44610
44621
  }
44611
44622
  return this.unsigned ? `${type} unsigned` : type;
44612
44623
  }
44624
+ mapFromDriverValue(value) {
44625
+ if (typeof value !== "number") return Number(value);
44626
+ return value;
44627
+ }
44613
44628
  };
44614
44629
  __publicField(SingleStoreFloat, _a401, "SingleStoreFloat");
44615
44630
  }
@@ -45191,9 +45206,9 @@ var init_varchar3 = __esm({
45191
45206
  // ../drizzle-orm/dist/singlestore-core/columns/vector.js
45192
45207
  function vector2(a, b) {
45193
45208
  const { name: name2, config } = getColumnNameAndConfig(a, b);
45194
- return new SingleStoreVectorBuilder(name2, config);
45209
+ return config.elementType === "I64" ? new SingleStoreBigIntVectorBuilder(name2, config) : new SingleStoreVectorBuilder(name2, config);
45195
45210
  }
45196
- var _a430, _b324, SingleStoreVectorBuilder, _a431, _b325, SingleStoreVector;
45211
+ var _a430, _b324, SingleStoreVectorBuilder, _a431, _b325, SingleStoreVector, _a432, _b326, SingleStoreBigIntVectorBuilder, _a433, _b327, SingleStoreBigIntVector;
45197
45212
  var init_vector4 = __esm({
45198
45213
  "../drizzle-orm/dist/singlestore-core/columns/vector.js"() {
45199
45214
  "use strict";
@@ -45229,13 +45244,81 @@ var init_vector4 = __esm({
45229
45244
  return `vector(${this.config.length}, ${this.elementType || "F32"})`;
45230
45245
  }
45231
45246
  mapToDriverValue(value) {
45232
- return JSON.stringify(value);
45247
+ return `[${value.map((e) => e.toString()).join(",")}]`;
45233
45248
  }
45234
45249
  mapFromDriverValue(value) {
45235
- return JSON.parse(value);
45250
+ if (typeof value === "string") {
45251
+ if (value.startsWith("[")) return value.slice(1, -1).split(",").map(Number);
45252
+ value = Buffer.from(value, "hex");
45253
+ }
45254
+ if (Buffer.isBuffer(value)) {
45255
+ const type = this.elementType || "F32";
45256
+ const bytearr = new Uint8Array(value);
45257
+ switch (type) {
45258
+ case "I8": {
45259
+ return Array.from(new Int8Array(bytearr.buffer, 0, bytearr.length / 1));
45260
+ }
45261
+ case "I16": {
45262
+ return Array.from(new Int16Array(bytearr.buffer, 0, bytearr.length / 2));
45263
+ }
45264
+ case "I32": {
45265
+ return Array.from(new Int32Array(bytearr.buffer, 0, bytearr.length / 4));
45266
+ }
45267
+ case "F32": {
45268
+ return Array.from(new Float32Array(bytearr.buffer, 0, bytearr.length / 4));
45269
+ }
45270
+ case "F64": {
45271
+ return Array.from(new Float64Array(bytearr.buffer, 0, bytearr.length / 8));
45272
+ }
45273
+ }
45274
+ }
45275
+ return value;
45236
45276
  }
45237
45277
  };
45238
45278
  __publicField(SingleStoreVector, _a431, "SingleStoreVector");
45279
+ SingleStoreBigIntVectorBuilder = class extends (_b326 = SingleStoreColumnBuilder, _a432 = entityKind, _b326) {
45280
+ constructor(name2, config) {
45281
+ super(name2, "array int64vector", "SingleStoreBigIntVector");
45282
+ this.config.length = config.dimensions;
45283
+ this.config.isLengthExact = true;
45284
+ }
45285
+ /** @internal */
45286
+ build(table6) {
45287
+ return new SingleStoreBigIntVector(
45288
+ table6,
45289
+ this.config
45290
+ );
45291
+ }
45292
+ /** @internal */
45293
+ generatedAlwaysAs(as, config) {
45294
+ throw new Error("Method not implemented.");
45295
+ }
45296
+ };
45297
+ __publicField(SingleStoreBigIntVectorBuilder, _a432, "SingleStoreBigIntVectorBuilder");
45298
+ SingleStoreBigIntVector = class extends (_b327 = SingleStoreColumn, _a433 = entityKind, _b327) {
45299
+ constructor() {
45300
+ super(...arguments);
45301
+ __publicField(this, "elementType", "I64");
45302
+ }
45303
+ getSQLType() {
45304
+ return `vector(${this.config.length}, ${this.elementType}})`;
45305
+ }
45306
+ mapToDriverValue(value) {
45307
+ return `[${value.map((e) => e.toString()).join(",")}]`;
45308
+ }
45309
+ mapFromDriverValue(value) {
45310
+ if (typeof value === "string") {
45311
+ if (value.startsWith("[")) return value.slice(1, -1).split(",").map(BigInt);
45312
+ value = Buffer.from(value, "hex");
45313
+ }
45314
+ if (Buffer.isBuffer(value)) {
45315
+ const bytearr = new Uint8Array(value);
45316
+ return Array.from(new BigInt64Array(bytearr.buffer, 0, bytearr.length / 8));
45317
+ }
45318
+ return value;
45319
+ }
45320
+ };
45321
+ __publicField(SingleStoreBigIntVector, _a433, "SingleStoreBigIntVector");
45239
45322
  }
45240
45323
  });
45241
45324
 
@@ -45243,13 +45326,13 @@ var init_vector4 = __esm({
45243
45326
  function year2(name2) {
45244
45327
  return new SingleStoreYearBuilder(name2 ?? "");
45245
45328
  }
45246
- var _a432, _b326, SingleStoreYearBuilder, _a433, _b327, SingleStoreYear;
45329
+ var _a434, _b328, SingleStoreYearBuilder, _a435, _b329, SingleStoreYear;
45247
45330
  var init_year2 = __esm({
45248
45331
  "../drizzle-orm/dist/singlestore-core/columns/year.js"() {
45249
45332
  "use strict";
45250
45333
  init_entity();
45251
45334
  init_common5();
45252
- SingleStoreYearBuilder = class extends (_b326 = SingleStoreColumnBuilder, _a432 = entityKind, _b326) {
45335
+ SingleStoreYearBuilder = class extends (_b328 = SingleStoreColumnBuilder, _a434 = entityKind, _b328) {
45253
45336
  constructor(name2) {
45254
45337
  super(name2, "number year", "SingleStoreYear");
45255
45338
  }
@@ -45261,13 +45344,17 @@ var init_year2 = __esm({
45261
45344
  );
45262
45345
  }
45263
45346
  };
45264
- __publicField(SingleStoreYearBuilder, _a432, "SingleStoreYearBuilder");
45265
- SingleStoreYear = class extends (_b327 = SingleStoreColumn, _a433 = entityKind, _b327) {
45347
+ __publicField(SingleStoreYearBuilder, _a434, "SingleStoreYearBuilder");
45348
+ SingleStoreYear = class extends (_b329 = SingleStoreColumn, _a435 = entityKind, _b329) {
45266
45349
  getSQLType() {
45267
45350
  return `year`;
45268
45351
  }
45352
+ mapFromDriverValue(value) {
45353
+ if (typeof value !== "number") return Number(value);
45354
+ return value;
45355
+ }
45269
45356
  };
45270
- __publicField(SingleStoreYear, _a433, "SingleStoreYear");
45357
+ __publicField(SingleStoreYear, _a435, "SingleStoreYear");
45271
45358
  }
45272
45359
  });
45273
45360
 
@@ -45305,17 +45392,17 @@ var init_columns4 = __esm({
45305
45392
  });
45306
45393
 
45307
45394
  // ../drizzle-orm/dist/singlestore-core/query-builders/count.js
45308
- var _a434, _b328, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
45395
+ var _a436, _b330, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
45309
45396
  var init_count4 = __esm({
45310
45397
  "../drizzle-orm/dist/singlestore-core/query-builders/count.js"() {
45311
45398
  "use strict";
45312
45399
  init_entity();
45313
45400
  init_sql();
45314
- _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b328 = entityKind, _a434 = Symbol.toStringTag, _c12) {
45401
+ _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b330 = entityKind, _a436 = Symbol.toStringTag, _c12) {
45315
45402
  constructor(params) {
45316
45403
  super(_SingleStoreCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
45317
45404
  __publicField(this, "sql");
45318
- __publicField(this, _a434, "SingleStoreCountBuilder");
45405
+ __publicField(this, _a436, "SingleStoreCountBuilder");
45319
45406
  __publicField(this, "session");
45320
45407
  this.params = params;
45321
45408
  this.mapWith(Number);
@@ -45353,18 +45440,18 @@ var init_count4 = __esm({
45353
45440
  );
45354
45441
  }
45355
45442
  };
45356
- __publicField(_SingleStoreCountBuilder, _b328, "SingleStoreCountBuilder");
45443
+ __publicField(_SingleStoreCountBuilder, _b330, "SingleStoreCountBuilder");
45357
45444
  SingleStoreCountBuilder = _SingleStoreCountBuilder;
45358
45445
  }
45359
45446
  });
45360
45447
 
45361
45448
  // ../drizzle-orm/dist/singlestore-core/indexes.js
45362
- var _a435, IndexBuilderOn4, _a436, IndexBuilder4, _a437, Index6;
45449
+ var _a437, IndexBuilderOn4, _a438, IndexBuilder4, _a439, Index6;
45363
45450
  var init_indexes4 = __esm({
45364
45451
  "../drizzle-orm/dist/singlestore-core/indexes.js"() {
45365
45452
  "use strict";
45366
45453
  init_entity();
45367
- _a435 = entityKind;
45454
+ _a437 = entityKind;
45368
45455
  IndexBuilderOn4 = class {
45369
45456
  constructor(name2, unique) {
45370
45457
  this.name = name2;
@@ -45374,8 +45461,8 @@ var init_indexes4 = __esm({
45374
45461
  return new IndexBuilder4(this.name, columns, this.unique);
45375
45462
  }
45376
45463
  };
45377
- __publicField(IndexBuilderOn4, _a435, "SingleStoreIndexBuilderOn");
45378
- _a436 = entityKind;
45464
+ __publicField(IndexBuilderOn4, _a437, "SingleStoreIndexBuilderOn");
45465
+ _a438 = entityKind;
45379
45466
  IndexBuilder4 = class {
45380
45467
  constructor(name2, columns, unique) {
45381
45468
  /** @internal */
@@ -45403,15 +45490,15 @@ var init_indexes4 = __esm({
45403
45490
  return new Index6(this.config, table6);
45404
45491
  }
45405
45492
  };
45406
- __publicField(IndexBuilder4, _a436, "SingleStoreIndexBuilder");
45407
- _a437 = entityKind;
45493
+ __publicField(IndexBuilder4, _a438, "SingleStoreIndexBuilder");
45494
+ _a439 = entityKind;
45408
45495
  Index6 = class {
45409
45496
  constructor(config, table6) {
45410
45497
  __publicField(this, "config");
45411
45498
  this.config = { ...config, table: table6 };
45412
45499
  }
45413
45500
  };
45414
- __publicField(Index6, _a437, "SingleStoreIndex");
45501
+ __publicField(Index6, _a439, "SingleStoreIndex");
45415
45502
  }
45416
45503
  });
45417
45504
 
@@ -45499,20 +45586,20 @@ function singlestoreTableWithSchema(name2, columns, extraConfig, schema5, baseNa
45499
45586
  }
45500
45587
  return table6;
45501
45588
  }
45502
- var _a438, _b329, _c13, _d5, SingleStoreTable;
45589
+ var _a440, _b331, _c13, _d5, SingleStoreTable;
45503
45590
  var init_table5 = __esm({
45504
45591
  "../drizzle-orm/dist/singlestore-core/table.js"() {
45505
45592
  "use strict";
45506
45593
  init_entity();
45507
45594
  init_table();
45508
45595
  init_all4();
45509
- SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b329 = Table2.Symbol.Columns, _a438 = Table2.Symbol.ExtraConfigBuilder, _d5) {
45596
+ SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b331 = Table2.Symbol.Columns, _a440 = Table2.Symbol.ExtraConfigBuilder, _d5) {
45510
45597
  constructor() {
45511
45598
  super(...arguments);
45512
45599
  /** @internal */
45513
- __publicField(this, _b329);
45600
+ __publicField(this, _b331);
45514
45601
  /** @internal */
45515
- __publicField(this, _a438);
45602
+ __publicField(this, _a440);
45516
45603
  }
45517
45604
  };
45518
45605
  __publicField(SingleStoreTable, _c13, "SingleStoreTable");
@@ -45522,13 +45609,13 @@ var init_table5 = __esm({
45522
45609
  });
45523
45610
 
45524
45611
  // ../drizzle-orm/dist/singlestore-core/primary-keys.js
45525
- var _a439, PrimaryKeyBuilder4, _a440, PrimaryKey4;
45612
+ var _a441, PrimaryKeyBuilder4, _a442, PrimaryKey4;
45526
45613
  var init_primary_keys4 = __esm({
45527
45614
  "../drizzle-orm/dist/singlestore-core/primary-keys.js"() {
45528
45615
  "use strict";
45529
45616
  init_entity();
45530
45617
  init_table5();
45531
- _a439 = entityKind;
45618
+ _a441 = entityKind;
45532
45619
  PrimaryKeyBuilder4 = class {
45533
45620
  constructor(columns, name2) {
45534
45621
  /** @internal */
@@ -45543,8 +45630,8 @@ var init_primary_keys4 = __esm({
45543
45630
  return new PrimaryKey4(table6, this.columns, this.name);
45544
45631
  }
45545
45632
  };
45546
- __publicField(PrimaryKeyBuilder4, _a439, "SingleStorePrimaryKeyBuilder");
45547
- _a440 = entityKind;
45633
+ __publicField(PrimaryKeyBuilder4, _a441, "SingleStorePrimaryKeyBuilder");
45634
+ _a442 = entityKind;
45548
45635
  PrimaryKey4 = class {
45549
45636
  constructor(table6, columns, name2) {
45550
45637
  __publicField(this, "columns");
@@ -45557,7 +45644,7 @@ var init_primary_keys4 = __esm({
45557
45644
  return this.name ?? `${this.table[SingleStoreTable.Symbol.Name]}_${this.columns.map((column6) => column6.name).join("_")}_pk`;
45558
45645
  }
45559
45646
  };
45560
- __publicField(PrimaryKey4, _a440, "SingleStorePrimaryKey");
45647
+ __publicField(PrimaryKey4, _a442, "SingleStorePrimaryKey");
45561
45648
  }
45562
45649
  });
45563
45650
 
@@ -45621,7 +45708,7 @@ var init_utils10 = __esm({
45621
45708
  });
45622
45709
 
45623
45710
  // ../drizzle-orm/dist/singlestore-core/query-builders/delete.js
45624
- var _a441, _b330, SingleStoreDeleteBase;
45711
+ var _a443, _b332, SingleStoreDeleteBase;
45625
45712
  var init_delete4 = __esm({
45626
45713
  "../drizzle-orm/dist/singlestore-core/query-builders/delete.js"() {
45627
45714
  "use strict";
@@ -45630,7 +45717,7 @@ var init_delete4 = __esm({
45630
45717
  init_selection_proxy();
45631
45718
  init_table();
45632
45719
  init_utils10();
45633
- SingleStoreDeleteBase = class extends (_b330 = QueryPromise, _a441 = entityKind, _b330) {
45720
+ SingleStoreDeleteBase = class extends (_b332 = QueryPromise, _a443 = entityKind, _b332) {
45634
45721
  constructor(table6, session, dialect6, withList) {
45635
45722
  super();
45636
45723
  __publicField(this, "config");
@@ -45727,12 +45814,12 @@ var init_delete4 = __esm({
45727
45814
  return this;
45728
45815
  }
45729
45816
  };
45730
- __publicField(SingleStoreDeleteBase, _a441, "SingleStoreDelete");
45817
+ __publicField(SingleStoreDeleteBase, _a443, "SingleStoreDelete");
45731
45818
  }
45732
45819
  });
45733
45820
 
45734
45821
  // ../drizzle-orm/dist/singlestore-core/query-builders/insert.js
45735
- var _a442, SingleStoreInsertBuilder, _a443, _b331, SingleStoreInsertBase;
45822
+ var _a444, SingleStoreInsertBuilder, _a445, _b333, SingleStoreInsertBase;
45736
45823
  var init_insert4 = __esm({
45737
45824
  "../drizzle-orm/dist/singlestore-core/query-builders/insert.js"() {
45738
45825
  "use strict";
@@ -45742,7 +45829,7 @@ var init_insert4 = __esm({
45742
45829
  init_table();
45743
45830
  init_utils2();
45744
45831
  init_utils10();
45745
- _a442 = entityKind;
45832
+ _a444 = entityKind;
45746
45833
  SingleStoreInsertBuilder = class {
45747
45834
  constructor(table6, session, dialect6) {
45748
45835
  __publicField(this, "shouldIgnore", false);
@@ -45771,8 +45858,8 @@ var init_insert4 = __esm({
45771
45858
  return new SingleStoreInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
45772
45859
  }
45773
45860
  };
45774
- __publicField(SingleStoreInsertBuilder, _a442, "SingleStoreInsertBuilder");
45775
- SingleStoreInsertBase = class extends (_b331 = QueryPromise, _a443 = entityKind, _b331) {
45861
+ __publicField(SingleStoreInsertBuilder, _a444, "SingleStoreInsertBuilder");
45862
+ SingleStoreInsertBase = class extends (_b333 = QueryPromise, _a445 = entityKind, _b333) {
45776
45863
  constructor(table6, values, ignore, session, dialect6) {
45777
45864
  super();
45778
45865
  __publicField(this, "config");
@@ -45857,12 +45944,12 @@ var init_insert4 = __esm({
45857
45944
  return this;
45858
45945
  }
45859
45946
  };
45860
- __publicField(SingleStoreInsertBase, _a443, "SingleStoreInsert");
45947
+ __publicField(SingleStoreInsertBase, _a445, "SingleStoreInsert");
45861
45948
  }
45862
45949
  });
45863
45950
 
45864
45951
  // ../drizzle-orm/dist/singlestore-core/dialect.js
45865
- var _a444, SingleStoreDialect;
45952
+ var _a446, SingleStoreDialect;
45866
45953
  var init_dialect4 = __esm({
45867
45954
  "../drizzle-orm/dist/singlestore-core/dialect.js"() {
45868
45955
  "use strict";
@@ -45872,6 +45959,7 @@ var init_dialect4 = __esm({
45872
45959
  init_column();
45873
45960
  init_entity();
45874
45961
  init_errors();
45962
+ init_relations();
45875
45963
  init_expressions();
45876
45964
  init_sql();
45877
45965
  init_subquery();
@@ -45880,11 +45968,62 @@ var init_dialect4 = __esm({
45880
45968
  init_view_common();
45881
45969
  init_common5();
45882
45970
  init_table5();
45883
- _a444 = entityKind;
45971
+ _a446 = entityKind;
45884
45972
  SingleStoreDialect = class {
45885
45973
  constructor(config) {
45886
45974
  /** @internal */
45887
45975
  __publicField(this, "casing");
45976
+ __publicField(this, "unwrapAllColumns", (table6, selection) => {
45977
+ return sql.join(
45978
+ Object.entries(table6[TableColumns]).map(([k, v]) => {
45979
+ selection.push({
45980
+ key: k,
45981
+ field: v
45982
+ });
45983
+ return this.buildRqbColumn(table6, v, k);
45984
+ }),
45985
+ sql`, `
45986
+ );
45987
+ });
45988
+ __publicField(this, "getSelectedTableColumns", (table6, columns) => {
45989
+ const selectedColumns = [];
45990
+ const columnContainer = table6[TableColumns];
45991
+ const entries = Object.entries(columns);
45992
+ let colSelectionMode;
45993
+ for (const [k, v] of entries) {
45994
+ if (v === void 0) continue;
45995
+ colSelectionMode = colSelectionMode || v;
45996
+ if (v) {
45997
+ const column6 = columnContainer[k];
45998
+ selectedColumns.push({
45999
+ column: column6,
46000
+ tsName: k
46001
+ });
46002
+ }
46003
+ }
46004
+ if (colSelectionMode === false) {
46005
+ for (const [k, v] of Object.entries(columnContainer)) {
46006
+ if (columns[k] === false) continue;
46007
+ selectedColumns.push({
46008
+ column: v,
46009
+ tsName: k
46010
+ });
46011
+ }
46012
+ }
46013
+ return selectedColumns;
46014
+ });
46015
+ __publicField(this, "buildColumns", (table6, selection, params) => params?.columns ? (() => {
46016
+ const columnIdentifiers = [];
46017
+ const selectedColumns = this.getSelectedTableColumns(table6, params.columns);
46018
+ for (const { column: column6, tsName } of selectedColumns) {
46019
+ columnIdentifiers.push(this.buildRqbColumn(table6, column6, tsName));
46020
+ selection.push({
46021
+ key: tsName,
46022
+ field: column6
46023
+ });
46024
+ }
46025
+ return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
46026
+ })() : this.unwrapAllColumns(table6, selection));
45888
46027
  this.casing = new CasingCache(config?.casing);
45889
46028
  }
45890
46029
  async migrate(migrations, session, config) {
@@ -46219,7 +46358,7 @@ var init_dialect4 = __esm({
46219
46358
  invokeSource
46220
46359
  });
46221
46360
  }
46222
- buildRelationalQuery({
46361
+ _buildRelationalQuery({
46223
46362
  fullSchema,
46224
46363
  schema: schema5,
46225
46364
  tableNamesMap,
@@ -46329,7 +46468,7 @@ var init_dialect4 = __esm({
46329
46468
  )
46330
46469
  )
46331
46470
  );
46332
- const builtRelation = this.buildRelationalQuery({
46471
+ const builtRelation = this._buildRelationalQuery({
46333
46472
  fullSchema,
46334
46473
  schema: schema5,
46335
46474
  tableNamesMap,
@@ -46444,8 +46583,140 @@ var init_dialect4 = __esm({
46444
46583
  selection
46445
46584
  };
46446
46585
  }
46586
+ nestedSelectionerror() {
46587
+ throw new DrizzleError({
46588
+ message: `Views with nested selections are not supported by the relational query builder`
46589
+ });
46590
+ }
46591
+ buildRqbColumn(table6, column6, key) {
46592
+ if (is(column6, Column2)) {
46593
+ const name2 = sql`${table6}.${sql.identifier(this.casing.getColumnCasing(column6))}`;
46594
+ switch (column6.columnType) {
46595
+ case "SingleStoreBinary":
46596
+ case "SingleStoreVarBinary":
46597
+ case "SingleStoreTime":
46598
+ case "SingleStoreDateTimeString":
46599
+ case "SingleStoreTimestampString":
46600
+ case "SingleStoreFloat":
46601
+ case "SingleStoreDecimal":
46602
+ case "SingleStoreDecimalNumber":
46603
+ case "SingleStoreDecimalBigInt":
46604
+ case "SingleStoreBigInt64":
46605
+ case "SingleStoreEnumColumn": {
46606
+ return sql`cast(${name2} as char) as ${sql.identifier(key)}`;
46607
+ }
46608
+ case "SingleStoreVector":
46609
+ case "SingleStoreBigIntVector": {
46610
+ return sql`hex(${name2} :> blob) as ${sql.identifier(key)}`;
46611
+ }
46612
+ case "SingleStoreCustomColumn": {
46613
+ return sql`${column6.jsonSelectIdentifier(name2, sql)} as ${sql.identifier(key)}`;
46614
+ }
46615
+ default: {
46616
+ return sql`${name2} as ${sql.identifier(key)}`;
46617
+ }
46618
+ }
46619
+ }
46620
+ return sql`${table6}.${is(column6, SQL.Aliased) ? sql.identifier(column6.fieldAlias) : isSQLWrapper(column6) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
46621
+ }
46622
+ buildRelationalQuery({
46623
+ schema: schema5,
46624
+ table: table6,
46625
+ tableConfig,
46626
+ queryConfig: config,
46627
+ relationWhere,
46628
+ mode,
46629
+ errorPath,
46630
+ depth,
46631
+ isNestedMany,
46632
+ throughJoin
46633
+ }) {
46634
+ const selection = [];
46635
+ const isSingle = mode === "first";
46636
+ const params = config === true ? void 0 : config;
46637
+ const currentPath = errorPath ?? "";
46638
+ const currentDepth = depth ?? 0;
46639
+ if (!currentDepth) table6 = aliasedTable(table6, `d${currentDepth}`);
46640
+ const limit = isSingle ? 1 : params?.limit;
46641
+ const offset = params?.offset;
46642
+ const columns = this.buildColumns(table6, selection, params);
46643
+ const where = params?.where && relationWhere ? and(
46644
+ relationsFilterToSQL(table6, params.where, tableConfig.relations, schema5, this.casing),
46645
+ relationWhere
46646
+ ) : params?.where ? relationsFilterToSQL(table6, params.where, tableConfig.relations, schema5, this.casing) : relationWhere;
46647
+ const order = params?.orderBy ? relationsOrderToSQL(table6, params.orderBy) : void 0;
46648
+ const extras = params?.extras ? relationExtrasToSQL(table6, params.extras) : void 0;
46649
+ if (extras) selection.push(...extras.selection);
46650
+ const selectionArr = columns ? [columns] : [];
46651
+ const joins = params ? (() => {
46652
+ const { with: joins2 } = params;
46653
+ if (!joins2) return;
46654
+ const withEntries = Object.entries(joins2).filter(([_2, v]) => v);
46655
+ if (!withEntries.length) return;
46656
+ return sql.join(
46657
+ withEntries.map(([k, join]) => {
46658
+ const relation = tableConfig.relations[k];
46659
+ const isSingle2 = is(relation, One);
46660
+ selectionArr.push(
46661
+ isSingle2 ? sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}` : sql`coalesce(${sql.identifier(k)}.${sql.identifier("r")}, json_build_array()) as ${sql.identifier(k)}`
46662
+ );
46663
+ const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
46664
+ const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
46665
+ const { filter: filter2, joinCondition } = relationToSQL(
46666
+ this.casing,
46667
+ relation,
46668
+ table6,
46669
+ targetTable,
46670
+ throughTable
46671
+ );
46672
+ const throughJoin2 = throughTable ? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}` : void 0;
46673
+ const innerQuery = this.buildRelationalQuery({
46674
+ table: targetTable,
46675
+ mode: isSingle2 ? "first" : "many",
46676
+ schema: schema5,
46677
+ queryConfig: join,
46678
+ tableConfig: schema5[relation.targetTableName],
46679
+ relationWhere: filter2,
46680
+ errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
46681
+ depth: currentDepth + 1,
46682
+ isNestedMany: !isSingle2,
46683
+ throughJoin: throughJoin2
46684
+ });
46685
+ selection.push({
46686
+ field: targetTable,
46687
+ key: k,
46688
+ selection: innerQuery.selection,
46689
+ isArray: !isSingle2,
46690
+ isOptional: (relation.optional ?? false) || join !== true && !!join.where
46691
+ });
46692
+ const jsonColumns = sql.join(
46693
+ innerQuery.selection.map((s) => sql`${sql.raw(this.escapeString(s.key))}, ${sql.identifier(s.key)}`),
46694
+ sql`, `
46695
+ );
46696
+ const joinQuery = sql` left join lateral(select ${sql`${isSingle2 ? sql`json_build_object(${jsonColumns})` : sql`json_agg(json_build_object(${jsonColumns})${innerQuery.order ? sql` ORDER BY ${sql.identifier(`$drizzle_order_row_number`)}` : void 0})`} as ${sql.identifier("r")}`} from (${innerQuery.sql}) as ${sql.identifier("t")}) as ${sql.identifier(k)} on true`;
46697
+ return joinQuery;
46698
+ })
46699
+ );
46700
+ })() : void 0;
46701
+ if (extras?.sql) selectionArr.push(extras.sql);
46702
+ if (!selectionArr.length) {
46703
+ throw new DrizzleError({
46704
+ message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}`
46705
+ });
46706
+ }
46707
+ if (isNestedMany && order) {
46708
+ selectionArr.push(sql`row_number() over (order by ${order}) as ${sql.identifier(`$drizzle_order_row_number`)}`);
46709
+ }
46710
+ const selectionSet = sql.join(selectionArr, sql`, `);
46711
+ const query = sql`select ${selectionSet} from ${getTableAsAliasSQL(table6)}${throughJoin}${sql`${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
46712
+ return {
46713
+ sql: query,
46714
+ selection,
46715
+ order
46716
+ };
46717
+ }
46447
46718
  };
46448
- __publicField(SingleStoreDialect, _a444, "SingleStoreDialect");
46719
+ __publicField(SingleStoreDialect, _a446, "SingleStoreDialect");
46449
46720
  }
46450
46721
  });
46451
46722
 
@@ -46467,7 +46738,7 @@ function createSetOperator4(type, isAll) {
46467
46738
  return leftSelect.addSetOperators(setOperators);
46468
46739
  };
46469
46740
  }
46470
- var _a445, SingleStoreSelectBuilder, _a446, _b332, SingleStoreSelectQueryBuilderBase, _a447, _b333, SingleStoreSelectBase, getSingleStoreSetOperators, union5, unionAll4, intersect4, except4, minus;
46741
+ var _a447, SingleStoreSelectBuilder, _a448, _b334, SingleStoreSelectQueryBuilderBase, _a449, _b335, SingleStoreSelectBase, getSingleStoreSetOperators, union5, unionAll4, intersect4, except4, minus;
46471
46742
  var init_select5 = __esm({
46472
46743
  "../drizzle-orm/dist/singlestore-core/query-builders/select.js"() {
46473
46744
  "use strict";
@@ -46480,7 +46751,7 @@ var init_select5 = __esm({
46480
46751
  init_table();
46481
46752
  init_utils2();
46482
46753
  init_utils10();
46483
- _a445 = entityKind;
46754
+ _a447 = entityKind;
46484
46755
  SingleStoreSelectBuilder = class {
46485
46756
  constructor(config) {
46486
46757
  __publicField(this, "fields");
@@ -46523,8 +46794,8 @@ var init_select5 = __esm({
46523
46794
  );
46524
46795
  }
46525
46796
  };
46526
- __publicField(SingleStoreSelectBuilder, _a445, "SingleStoreSelectBuilder");
46527
- SingleStoreSelectQueryBuilderBase = class extends (_b332 = TypedQueryBuilder, _a446 = entityKind, _b332) {
46797
+ __publicField(SingleStoreSelectBuilder, _a447, "SingleStoreSelectBuilder");
46798
+ SingleStoreSelectQueryBuilderBase = class extends (_b334 = TypedQueryBuilder, _a448 = entityKind, _b334) {
46528
46799
  constructor({ table: table6, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
46529
46800
  super();
46530
46801
  __publicField(this, "_");
@@ -47145,8 +47416,8 @@ var init_select5 = __esm({
47145
47416
  return this;
47146
47417
  }
47147
47418
  };
47148
- __publicField(SingleStoreSelectQueryBuilderBase, _a446, "SingleStoreSelectQueryBuilder");
47149
- SingleStoreSelectBase = class extends (_b333 = SingleStoreSelectQueryBuilderBase, _a447 = entityKind, _b333) {
47419
+ __publicField(SingleStoreSelectQueryBuilderBase, _a448, "SingleStoreSelectQueryBuilder");
47420
+ SingleStoreSelectBase = class extends (_b335 = SingleStoreSelectQueryBuilderBase, _a449 = entityKind, _b335) {
47150
47421
  constructor() {
47151
47422
  super(...arguments);
47152
47423
  __publicField(this, "execute", (placeholderValues) => {
@@ -47177,7 +47448,7 @@ var init_select5 = __esm({
47177
47448
  return this;
47178
47449
  }
47179
47450
  };
47180
- __publicField(SingleStoreSelectBase, _a447, "SingleStoreSelect");
47451
+ __publicField(SingleStoreSelectBase, _a449, "SingleStoreSelect");
47181
47452
  applyMixins(SingleStoreSelectBase, [QueryPromise]);
47182
47453
  getSingleStoreSetOperators = () => ({
47183
47454
  union: union5,
@@ -47195,7 +47466,7 @@ var init_select5 = __esm({
47195
47466
  });
47196
47467
 
47197
47468
  // ../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js
47198
- var _a448, QueryBuilder4;
47469
+ var _a450, QueryBuilder4;
47199
47470
  var init_query_builder5 = __esm({
47200
47471
  "../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js"() {
47201
47472
  "use strict";
@@ -47204,7 +47475,7 @@ var init_query_builder5 = __esm({
47204
47475
  init_dialect4();
47205
47476
  init_subquery();
47206
47477
  init_select5();
47207
- _a448 = entityKind;
47478
+ _a450 = entityKind;
47208
47479
  QueryBuilder4 = class {
47209
47480
  constructor(dialect6) {
47210
47481
  __publicField(this, "dialect");
@@ -47274,7 +47545,7 @@ var init_query_builder5 = __esm({
47274
47545
  return this.dialect;
47275
47546
  }
47276
47547
  };
47277
- __publicField(QueryBuilder4, _a448, "SingleStoreQueryBuilder");
47548
+ __publicField(QueryBuilder4, _a450, "SingleStoreQueryBuilder");
47278
47549
  }
47279
47550
  });
47280
47551
 
@@ -47286,7 +47557,7 @@ var init_select_types4 = __esm({
47286
47557
  });
47287
47558
 
47288
47559
  // ../drizzle-orm/dist/singlestore-core/query-builders/update.js
47289
- var _a449, SingleStoreUpdateBuilder, _a450, _b334, SingleStoreUpdateBase;
47560
+ var _a451, SingleStoreUpdateBuilder, _a452, _b336, SingleStoreUpdateBase;
47290
47561
  var init_update4 = __esm({
47291
47562
  "../drizzle-orm/dist/singlestore-core/query-builders/update.js"() {
47292
47563
  "use strict";
@@ -47296,7 +47567,7 @@ var init_update4 = __esm({
47296
47567
  init_table();
47297
47568
  init_utils2();
47298
47569
  init_utils10();
47299
- _a449 = entityKind;
47570
+ _a451 = entityKind;
47300
47571
  SingleStoreUpdateBuilder = class {
47301
47572
  constructor(table6, session, dialect6, withList) {
47302
47573
  this.table = table6;
@@ -47314,8 +47585,8 @@ var init_update4 = __esm({
47314
47585
  );
47315
47586
  }
47316
47587
  };
47317
- __publicField(SingleStoreUpdateBuilder, _a449, "SingleStoreUpdateBuilder");
47318
- SingleStoreUpdateBase = class extends (_b334 = QueryPromise, _a450 = entityKind, _b334) {
47588
+ __publicField(SingleStoreUpdateBuilder, _a451, "SingleStoreUpdateBuilder");
47589
+ SingleStoreUpdateBase = class extends (_b336 = QueryPromise, _a452 = entityKind, _b336) {
47319
47590
  constructor(table6, set, session, dialect6, withList) {
47320
47591
  super();
47321
47592
  __publicField(this, "config");
@@ -47415,7 +47686,7 @@ var init_update4 = __esm({
47415
47686
  return this;
47416
47687
  }
47417
47688
  };
47418
- __publicField(SingleStoreUpdateBase, _a450, "SingleStoreUpdate");
47689
+ __publicField(SingleStoreUpdateBase, _a452, "SingleStoreUpdate");
47419
47690
  }
47420
47691
  });
47421
47692
 
@@ -47432,8 +47703,103 @@ var init_query_builders4 = __esm({
47432
47703
  }
47433
47704
  });
47434
47705
 
47706
+ // ../drizzle-orm/dist/singlestore-core/query-builders/query.js
47707
+ var _a453, RelationalQueryBuilder4, _a454, _b337, SingleStoreRelationalQuery;
47708
+ var init_query7 = __esm({
47709
+ "../drizzle-orm/dist/singlestore-core/query-builders/query.js"() {
47710
+ "use strict";
47711
+ init_entity();
47712
+ init_query_promise();
47713
+ init_relations();
47714
+ _a453 = entityKind;
47715
+ RelationalQueryBuilder4 = class {
47716
+ constructor(schema5, table6, tableConfig, dialect6, session) {
47717
+ this.schema = schema5;
47718
+ this.table = table6;
47719
+ this.tableConfig = tableConfig;
47720
+ this.dialect = dialect6;
47721
+ this.session = session;
47722
+ }
47723
+ findMany(config) {
47724
+ return new SingleStoreRelationalQuery(
47725
+ this.schema,
47726
+ this.table,
47727
+ this.tableConfig,
47728
+ this.dialect,
47729
+ this.session,
47730
+ config ?? true,
47731
+ "many"
47732
+ );
47733
+ }
47734
+ findFirst(config) {
47735
+ return new SingleStoreRelationalQuery(
47736
+ this.schema,
47737
+ this.table,
47738
+ this.tableConfig,
47739
+ this.dialect,
47740
+ this.session,
47741
+ config ?? true,
47742
+ "first"
47743
+ );
47744
+ }
47745
+ };
47746
+ __publicField(RelationalQueryBuilder4, _a453, "SingleStoreRelationalQueryBuilderV2");
47747
+ SingleStoreRelationalQuery = class extends (_b337 = QueryPromise, _a454 = entityKind, _b337) {
47748
+ constructor(schema5, table6, tableConfig, dialect6, session, config, mode) {
47749
+ super();
47750
+ this.schema = schema5;
47751
+ this.table = table6;
47752
+ this.tableConfig = tableConfig;
47753
+ this.dialect = dialect6;
47754
+ this.session = session;
47755
+ this.config = config;
47756
+ this.mode = mode;
47757
+ }
47758
+ prepare() {
47759
+ const { query, builtQuery } = this._toSQL();
47760
+ return this.session.prepareRelationalQuery(
47761
+ builtQuery,
47762
+ void 0,
47763
+ (rawRows) => {
47764
+ const rows = rawRows.map((row) => mapRelationalRow(row, query.selection, void 0, void 0, true));
47765
+ if (this.mode === "first") {
47766
+ return rows[0];
47767
+ }
47768
+ return rows;
47769
+ }
47770
+ );
47771
+ }
47772
+ _getQuery() {
47773
+ return this.dialect.buildRelationalQuery({
47774
+ schema: this.schema,
47775
+ table: this.table,
47776
+ tableConfig: this.tableConfig,
47777
+ queryConfig: this.config,
47778
+ mode: this.mode
47779
+ });
47780
+ }
47781
+ _toSQL() {
47782
+ const query = this._getQuery();
47783
+ const builtQuery = this.dialect.sqlToQuery(query.sql);
47784
+ return { builtQuery, query };
47785
+ }
47786
+ /** @internal */
47787
+ getSQL() {
47788
+ return this._getQuery().sql;
47789
+ }
47790
+ toSQL() {
47791
+ return this._toSQL().builtQuery;
47792
+ }
47793
+ execute() {
47794
+ return this.prepare().execute();
47795
+ }
47796
+ };
47797
+ __publicField(SingleStoreRelationalQuery, _a454, "SingleStoreRelationalQueryV2");
47798
+ }
47799
+ });
47800
+
47435
47801
  // ../drizzle-orm/dist/singlestore-core/db.js
47436
- var _a451, SingleStoreDatabase;
47802
+ var _a455, SingleStoreDatabase;
47437
47803
  var init_db4 = __esm({
47438
47804
  "../drizzle-orm/dist/singlestore-core/db.js"() {
47439
47805
  "use strict";
@@ -47443,11 +47809,11 @@ var init_db4 = __esm({
47443
47809
  init_subquery();
47444
47810
  init_count4();
47445
47811
  init_query_builders4();
47446
- _a451 = entityKind;
47812
+ init_query7();
47813
+ _a455 = entityKind;
47447
47814
  SingleStoreDatabase = class {
47448
- constructor(dialect6, session, schema5) {
47449
- // We are waiting for SingleStore support for `json_array` function
47450
- /**@inrernal */
47815
+ constructor(dialect6, session, relations, schema5) {
47816
+ // TO-DO: Figure out how to pass DrizzleTypeError without breaking withReplicas
47451
47817
  __publicField(this, "query");
47452
47818
  /**
47453
47819
  * Creates a subquery that defines a temporary named result set as a CTE.
@@ -47505,13 +47871,24 @@ var init_db4 = __esm({
47505
47871
  this._ = schema5 ? {
47506
47872
  schema: schema5.schema,
47507
47873
  fullSchema: schema5.fullSchema,
47508
- tableNamesMap: schema5.tableNamesMap
47874
+ tableNamesMap: schema5.tableNamesMap,
47875
+ relations
47509
47876
  } : {
47510
47877
  schema: void 0,
47511
47878
  fullSchema: {},
47512
- tableNamesMap: {}
47879
+ tableNamesMap: {},
47880
+ relations
47513
47881
  };
47514
47882
  this.query = {};
47883
+ for (const [tableName, relation] of Object.entries(relations)) {
47884
+ this.query[tableName] = new RelationalQueryBuilder4(
47885
+ relations,
47886
+ relations[relation.name].table,
47887
+ relation,
47888
+ dialect6,
47889
+ session
47890
+ );
47891
+ }
47515
47892
  this.$cache = { invalidate: async (_params) => {
47516
47893
  } };
47517
47894
  }
@@ -47650,18 +48027,18 @@ var init_db4 = __esm({
47650
48027
  return this.session.transaction(transaction, config);
47651
48028
  }
47652
48029
  };
47653
- __publicField(SingleStoreDatabase, _a451, "SingleStoreDatabase");
48030
+ __publicField(SingleStoreDatabase, _a455, "SingleStoreDatabase");
47654
48031
  }
47655
48032
  });
47656
48033
 
47657
48034
  // ../drizzle-orm/dist/singlestore-core/schema.js
47658
- var _a452, SingleStoreSchema5;
48035
+ var _a456, SingleStoreSchema5;
47659
48036
  var init_schema3 = __esm({
47660
48037
  "../drizzle-orm/dist/singlestore-core/schema.js"() {
47661
48038
  "use strict";
47662
48039
  init_entity();
47663
48040
  init_table5();
47664
- _a452 = entityKind;
48041
+ _a456 = entityKind;
47665
48042
  SingleStoreSchema5 = class {
47666
48043
  constructor(schemaName) {
47667
48044
  __publicField(this, "table", (name2, columns, extraConfig) => {
@@ -47674,12 +48051,12 @@ var init_schema3 = __esm({
47674
48051
  return singlestoreViewWithSchema(name, columns, this.schemaName);
47675
48052
  }) as typeof singlestoreView; */
47676
48053
  };
47677
- __publicField(SingleStoreSchema5, _a452, "SingleStoreSchema");
48054
+ __publicField(SingleStoreSchema5, _a456, "SingleStoreSchema");
47678
48055
  }
47679
48056
  });
47680
48057
 
47681
48058
  // ../drizzle-orm/dist/singlestore-core/session.js
47682
- var _a453, SingleStorePreparedQuery, _a454, SingleStoreSession, _a455, _b335, SingleStoreTransaction;
48059
+ var _a457, SingleStorePreparedQuery, _a458, SingleStoreSession, _a459, _b338, SingleStoreTransaction;
47683
48060
  var init_session4 = __esm({
47684
48061
  "../drizzle-orm/dist/singlestore-core/session.js"() {
47685
48062
  "use strict";
@@ -47688,7 +48065,7 @@ var init_session4 = __esm({
47688
48065
  init_errors();
47689
48066
  init_sql();
47690
48067
  init_db4();
47691
- _a453 = entityKind;
48068
+ _a457 = entityKind;
47692
48069
  SingleStorePreparedQuery = class {
47693
48070
  constructor(cache, queryMetadata, cacheConfig) {
47694
48071
  /** @internal */
@@ -47770,8 +48147,8 @@ var init_session4 = __esm({
47770
48147
  }
47771
48148
  }
47772
48149
  };
47773
- __publicField(SingleStorePreparedQuery, _a453, "SingleStorePreparedQuery");
47774
- _a454 = entityKind;
48150
+ __publicField(SingleStorePreparedQuery, _a457, "SingleStorePreparedQuery");
48151
+ _a458 = entityKind;
47775
48152
  SingleStoreSession = class {
47776
48153
  constructor(dialect6) {
47777
48154
  this.dialect = dialect6;
@@ -47806,10 +48183,11 @@ var init_session4 = __esm({
47806
48183
  return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
47807
48184
  }
47808
48185
  };
47809
- __publicField(SingleStoreSession, _a454, "SingleStoreSession");
47810
- SingleStoreTransaction = class extends (_b335 = SingleStoreDatabase, _a455 = entityKind, _b335) {
47811
- constructor(dialect6, session, schema5, nestedIndex) {
47812
- super(dialect6, session, schema5);
48186
+ __publicField(SingleStoreSession, _a458, "SingleStoreSession");
48187
+ SingleStoreTransaction = class extends (_b338 = SingleStoreDatabase, _a459 = entityKind, _b338) {
48188
+ constructor(dialect6, session, relations, schema5, nestedIndex) {
48189
+ super(dialect6, session, relations, schema5);
48190
+ this.relations = relations;
47813
48191
  this.schema = schema5;
47814
48192
  this.nestedIndex = nestedIndex;
47815
48193
  }
@@ -47817,7 +48195,7 @@ var init_session4 = __esm({
47817
48195
  throw new TransactionRollbackError();
47818
48196
  }
47819
48197
  };
47820
- __publicField(SingleStoreTransaction, _a455, "SingleStoreTransaction");
48198
+ __publicField(SingleStoreTransaction, _a459, "SingleStoreTransaction");
47821
48199
  }
47822
48200
  });
47823
48201