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.js CHANGED
@@ -3479,17 +3479,17 @@ function processCreateParams(params) {
3479
3479
  if (errorMap2)
3480
3480
  return { errorMap: errorMap2, description };
3481
3481
  const customMap = (iss, ctx) => {
3482
- var _a456, _b336;
3482
+ var _a460, _b339;
3483
3483
  const { message } = params;
3484
3484
  if (iss.code === "invalid_enum_value") {
3485
3485
  return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
3486
3486
  }
3487
3487
  if (typeof ctx.data === "undefined") {
3488
- return { message: (_a456 = message !== null && message !== void 0 ? message : required_error) !== null && _a456 !== void 0 ? _a456 : ctx.defaultError };
3488
+ return { message: (_a460 = message !== null && message !== void 0 ? message : required_error) !== null && _a460 !== void 0 ? _a460 : ctx.defaultError };
3489
3489
  }
3490
3490
  if (iss.code !== "invalid_type")
3491
3491
  return { message: ctx.defaultError };
3492
- return { message: (_b336 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b336 !== void 0 ? _b336 : ctx.defaultError };
3492
+ return { message: (_b339 = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b339 !== void 0 ? _b339 : ctx.defaultError };
3493
3493
  };
3494
3494
  return { errorMap: customMap, description };
3495
3495
  }
@@ -4151,11 +4151,11 @@ var init_lib = __esm({
4151
4151
  throw result.error;
4152
4152
  }
4153
4153
  safeParse(data, params) {
4154
- var _a456;
4154
+ var _a460;
4155
4155
  const ctx = {
4156
4156
  common: {
4157
4157
  issues: [],
4158
- async: (_a456 = params === null || params === void 0 ? void 0 : params.async) !== null && _a456 !== void 0 ? _a456 : false,
4158
+ async: (_a460 = params === null || params === void 0 ? void 0 : params.async) !== null && _a460 !== void 0 ? _a460 : false,
4159
4159
  contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
4160
4160
  },
4161
4161
  path: (params === null || params === void 0 ? void 0 : params.path) || [],
@@ -4477,7 +4477,7 @@ var init_lib = __esm({
4477
4477
  } else if (check.kind === "url") {
4478
4478
  try {
4479
4479
  new URL(input.data);
4480
- } catch (_a456) {
4480
+ } catch (_a460) {
4481
4481
  ctx = this._getOrReturnCtx(input, ctx);
4482
4482
  addIssueToContext(ctx, {
4483
4483
  validation: "url",
@@ -4647,7 +4647,7 @@ var init_lib = __esm({
4647
4647
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
4648
4648
  }
4649
4649
  datetime(options) {
4650
- var _a456, _b336;
4650
+ var _a460, _b339;
4651
4651
  if (typeof options === "string") {
4652
4652
  return this._addCheck({
4653
4653
  kind: "datetime",
@@ -4660,8 +4660,8 @@ var init_lib = __esm({
4660
4660
  return this._addCheck({
4661
4661
  kind: "datetime",
4662
4662
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
4663
- offset: (_a456 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a456 !== void 0 ? _a456 : false,
4664
- local: (_b336 = options === null || options === void 0 ? void 0 : options.local) !== null && _b336 !== void 0 ? _b336 : false,
4663
+ offset: (_a460 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a460 !== void 0 ? _a460 : false,
4664
+ local: (_b339 = options === null || options === void 0 ? void 0 : options.local) !== null && _b339 !== void 0 ? _b339 : false,
4665
4665
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
4666
4666
  });
4667
4667
  }
@@ -4824,11 +4824,11 @@ var init_lib = __esm({
4824
4824
  }
4825
4825
  };
4826
4826
  ZodString.create = (params) => {
4827
- var _a456;
4827
+ var _a460;
4828
4828
  return new ZodString({
4829
4829
  checks: [],
4830
4830
  typeName: ZodFirstPartyTypeKind.ZodString,
4831
- coerce: (_a456 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a456 !== void 0 ? _a456 : false,
4831
+ coerce: (_a460 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a460 !== void 0 ? _a460 : false,
4832
4832
  ...processCreateParams(params)
4833
4833
  });
4834
4834
  };
@@ -5221,11 +5221,11 @@ var init_lib = __esm({
5221
5221
  }
5222
5222
  };
5223
5223
  ZodBigInt.create = (params) => {
5224
- var _a456;
5224
+ var _a460;
5225
5225
  return new ZodBigInt({
5226
5226
  checks: [],
5227
5227
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
5228
- coerce: (_a456 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a456 !== void 0 ? _a456 : false,
5228
+ coerce: (_a460 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a460 !== void 0 ? _a460 : false,
5229
5229
  ...processCreateParams(params)
5230
5230
  });
5231
5231
  };
@@ -5705,8 +5705,8 @@ var init_lib = __esm({
5705
5705
  unknownKeys: "strict",
5706
5706
  ...message !== void 0 ? {
5707
5707
  errorMap: (issue, ctx) => {
5708
- var _a456, _b336, _c14, _d6;
5709
- 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;
5708
+ var _a460, _b339, _c14, _d6;
5709
+ 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;
5710
5710
  if (issue.code === "unrecognized_keys")
5711
5711
  return {
5712
5712
  message: (_d6 = errorUtil.errToObj(message).message) !== null && _d6 !== void 0 ? _d6 : defaultError
@@ -23058,8 +23058,8 @@ var init_sql = __esm({
23058
23058
  sql2.param = param2;
23059
23059
  })(sql || (sql = {}));
23060
23060
  ((SQL2) => {
23061
- var _a456;
23062
- _a456 = entityKind;
23061
+ var _a460;
23062
+ _a460 = entityKind;
23063
23063
  const _Aliased = class _Aliased {
23064
23064
  constructor(sql2, fieldAlias) {
23065
23065
  /** @internal */
@@ -23075,7 +23075,7 @@ var init_sql = __esm({
23075
23075
  return new _Aliased(this.sql, this.fieldAlias);
23076
23076
  }
23077
23077
  };
23078
- __publicField(_Aliased, _a456, "SQL.Aliased");
23078
+ __publicField(_Aliased, _a460, "SQL.Aliased");
23079
23079
  let Aliased = _Aliased;
23080
23080
  SQL2.Aliased = Aliased;
23081
23081
  })(SQL || (SQL = {}));
@@ -23722,12 +23722,15 @@ function buildRelationsParts(tables, config) {
23722
23722
  function getOrderByOperators() {
23723
23723
  return orderByOperators;
23724
23724
  }
23725
- function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, path2) {
23725
+ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, parseJsonIfString = false, path2) {
23726
23726
  for (const selectionItem of buildQueryResultSelection) {
23727
23727
  if (selectionItem.selection) {
23728
23728
  const currentPath = `${path2 ? `${path2}.` : ""}${selectionItem.key}`;
23729
23729
  if (row[selectionItem.key] === null) continue;
23730
23730
  if (parseJson) row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
23731
+ if (parseJsonIfString && typeof row[selectionItem.key] === "string") {
23732
+ row[selectionItem.key] = JSON.parse(row[selectionItem.key]);
23733
+ }
23731
23734
  if (selectionItem.isArray) {
23732
23735
  for (const item of row[selectionItem.key]) {
23733
23736
  mapRelationalRow(
@@ -23735,6 +23738,7 @@ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (valu
23735
23738
  selectionItem.selection,
23736
23739
  mapColumnValue,
23737
23740
  false,
23741
+ parseJsonIfString,
23738
23742
  currentPath
23739
23743
  );
23740
23744
  }
@@ -23745,6 +23749,7 @@ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (valu
23745
23749
  selectionItem.selection,
23746
23750
  mapColumnValue,
23747
23751
  false,
23752
+ parseJsonIfString,
23748
23753
  currentPath
23749
23754
  );
23750
23755
  continue;
@@ -24511,6 +24516,7 @@ function isConfig(data) {
24511
24516
  if (Object.keys(data).length === 0) return true;
24512
24517
  return false;
24513
24518
  }
24519
+ var textDecoder;
24514
24520
  var init_utils2 = __esm({
24515
24521
  "../drizzle-orm/dist/utils.js"() {
24516
24522
  "use strict";
@@ -24520,6 +24526,7 @@ var init_utils2 = __esm({
24520
24526
  init_subquery();
24521
24527
  init_table();
24522
24528
  init_view_common();
24529
+ textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
24523
24530
  }
24524
24531
  });
24525
24532
 
@@ -24657,7 +24664,8 @@ __export(dist_exports, {
24657
24664
  relationsOrderToSQL: () => relationsOrderToSQL,
24658
24665
  sql: () => sql,
24659
24666
  sum: () => sum,
24660
- sumDistinct: () => sumDistinct
24667
+ sumDistinct: () => sumDistinct,
24668
+ textDecoder: () => textDecoder
24661
24669
  });
24662
24670
  var init_dist = __esm({
24663
24671
  "../drizzle-orm/dist/index.js"() {
@@ -32820,6 +32828,15 @@ var init_common3 = __esm({
32820
32828
  });
32821
32829
 
32822
32830
  // ../drizzle-orm/dist/sqlite-core/columns/blob.js
32831
+ function hexToText(hexString) {
32832
+ let result = "";
32833
+ for (let i = 0; i < hexString.length; i += 2) {
32834
+ const hexPair = hexString.substring(i, i + 2);
32835
+ const decimalValue = parseInt(hexPair, 16);
32836
+ result += String.fromCharCode(decimalValue);
32837
+ }
32838
+ return result;
32839
+ }
32823
32840
  function blob(a, b) {
32824
32841
  const { name: name2, config } = getColumnNameAndConfig(a, b);
32825
32842
  if (config?.mode === "json") {
@@ -32852,17 +32869,14 @@ var init_blob = __esm({
32852
32869
  return "blob";
32853
32870
  }
32854
32871
  mapFromDriverValue(value) {
32855
- if (Buffer.isBuffer(value)) {
32856
- return BigInt(value.toString());
32857
- }
32858
32872
  if (typeof value === "string") {
32859
- return BigInt(Buffer.from(value, "hex").toString());
32873
+ return BigInt(hexToText(value));
32860
32874
  }
32861
- if (value instanceof ArrayBuffer) {
32862
- const decoder = new TextDecoder();
32863
- return BigInt(decoder.decode(value));
32875
+ if (typeof Buffer !== "undefined" && Buffer.from) {
32876
+ 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);
32877
+ return BigInt(buf.toString("utf8"));
32864
32878
  }
32865
- return BigInt(String.fromCodePoint(...value));
32879
+ return BigInt(textDecoder.decode(value));
32866
32880
  }
32867
32881
  mapToDriverValue(value) {
32868
32882
  return Buffer.from(value.toString());
@@ -32887,17 +32901,14 @@ var init_blob = __esm({
32887
32901
  return "blob";
32888
32902
  }
32889
32903
  mapFromDriverValue(value) {
32890
- if (Buffer.isBuffer(value)) {
32891
- return JSON.parse(value.toString());
32892
- }
32893
32904
  if (typeof value === "string") {
32894
- return JSON.parse(Buffer.from(value, "hex").toString());
32905
+ return JSON.parse(hexToText(value));
32895
32906
  }
32896
- if (value instanceof ArrayBuffer) {
32897
- const decoder = new TextDecoder();
32898
- return JSON.parse(decoder.decode(value));
32907
+ if (typeof Buffer !== "undefined" && Buffer.from) {
32908
+ 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);
32909
+ return JSON.parse(buf.toString("utf8"));
32899
32910
  }
32900
- return JSON.parse(String.fromCodePoint(...value));
32911
+ return JSON.parse(textDecoder.decode(value));
32901
32912
  }
32902
32913
  mapToDriverValue(value) {
32903
32914
  return Buffer.from(JSON.stringify(value));
@@ -40601,7 +40612,7 @@ var init_dialect3 = __esm({
40601
40612
  mode,
40602
40613
  errorPath,
40603
40614
  depth,
40604
- isNested,
40615
+ isNestedMany,
40605
40616
  throughJoin
40606
40617
  }) {
40607
40618
  const selection = [];
@@ -40650,7 +40661,7 @@ var init_dialect3 = __esm({
40650
40661
  relationWhere: filter2,
40651
40662
  errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
40652
40663
  depth: currentDepth + 1,
40653
- isNested: true,
40664
+ isNestedMany: !isSingle2,
40654
40665
  throughJoin: throughJoin2
40655
40666
  });
40656
40667
  selection.push({
@@ -40675,7 +40686,7 @@ var init_dialect3 = __esm({
40675
40686
  message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}`
40676
40687
  });
40677
40688
  }
40678
- if (isNested && order) {
40689
+ if (isNestedMany && order) {
40679
40690
  selectionArr.push(sql`row_number() over (order by ${order})`);
40680
40691
  }
40681
40692
  const selectionSet = sql.join(selectionArr, sql`, `);
@@ -44605,6 +44616,10 @@ var init_float2 = __esm({
44605
44616
  }
44606
44617
  return this.unsigned ? `${type} unsigned` : type;
44607
44618
  }
44619
+ mapFromDriverValue(value) {
44620
+ if (typeof value !== "number") return Number(value);
44621
+ return value;
44622
+ }
44608
44623
  };
44609
44624
  __publicField(SingleStoreFloat, _a401, "SingleStoreFloat");
44610
44625
  }
@@ -45186,9 +45201,9 @@ var init_varchar3 = __esm({
45186
45201
  // ../drizzle-orm/dist/singlestore-core/columns/vector.js
45187
45202
  function vector2(a, b) {
45188
45203
  const { name: name2, config } = getColumnNameAndConfig(a, b);
45189
- return new SingleStoreVectorBuilder(name2, config);
45204
+ return config.elementType === "I64" ? new SingleStoreBigIntVectorBuilder(name2, config) : new SingleStoreVectorBuilder(name2, config);
45190
45205
  }
45191
- var _a430, _b324, SingleStoreVectorBuilder, _a431, _b325, SingleStoreVector;
45206
+ var _a430, _b324, SingleStoreVectorBuilder, _a431, _b325, SingleStoreVector, _a432, _b326, SingleStoreBigIntVectorBuilder, _a433, _b327, SingleStoreBigIntVector;
45192
45207
  var init_vector4 = __esm({
45193
45208
  "../drizzle-orm/dist/singlestore-core/columns/vector.js"() {
45194
45209
  "use strict";
@@ -45224,13 +45239,81 @@ var init_vector4 = __esm({
45224
45239
  return `vector(${this.config.length}, ${this.elementType || "F32"})`;
45225
45240
  }
45226
45241
  mapToDriverValue(value) {
45227
- return JSON.stringify(value);
45242
+ return `[${value.map((e) => e.toString()).join(",")}]`;
45228
45243
  }
45229
45244
  mapFromDriverValue(value) {
45230
- return JSON.parse(value);
45245
+ if (typeof value === "string") {
45246
+ if (value.startsWith("[")) return value.slice(1, -1).split(",").map(Number);
45247
+ value = Buffer.from(value, "hex");
45248
+ }
45249
+ if (Buffer.isBuffer(value)) {
45250
+ const type = this.elementType || "F32";
45251
+ const bytearr = new Uint8Array(value);
45252
+ switch (type) {
45253
+ case "I8": {
45254
+ return Array.from(new Int8Array(bytearr.buffer, 0, bytearr.length / 1));
45255
+ }
45256
+ case "I16": {
45257
+ return Array.from(new Int16Array(bytearr.buffer, 0, bytearr.length / 2));
45258
+ }
45259
+ case "I32": {
45260
+ return Array.from(new Int32Array(bytearr.buffer, 0, bytearr.length / 4));
45261
+ }
45262
+ case "F32": {
45263
+ return Array.from(new Float32Array(bytearr.buffer, 0, bytearr.length / 4));
45264
+ }
45265
+ case "F64": {
45266
+ return Array.from(new Float64Array(bytearr.buffer, 0, bytearr.length / 8));
45267
+ }
45268
+ }
45269
+ }
45270
+ return value;
45231
45271
  }
45232
45272
  };
45233
45273
  __publicField(SingleStoreVector, _a431, "SingleStoreVector");
45274
+ SingleStoreBigIntVectorBuilder = class extends (_b326 = SingleStoreColumnBuilder, _a432 = entityKind, _b326) {
45275
+ constructor(name2, config) {
45276
+ super(name2, "array int64vector", "SingleStoreBigIntVector");
45277
+ this.config.length = config.dimensions;
45278
+ this.config.isLengthExact = true;
45279
+ }
45280
+ /** @internal */
45281
+ build(table6) {
45282
+ return new SingleStoreBigIntVector(
45283
+ table6,
45284
+ this.config
45285
+ );
45286
+ }
45287
+ /** @internal */
45288
+ generatedAlwaysAs(as, config) {
45289
+ throw new Error("Method not implemented.");
45290
+ }
45291
+ };
45292
+ __publicField(SingleStoreBigIntVectorBuilder, _a432, "SingleStoreBigIntVectorBuilder");
45293
+ SingleStoreBigIntVector = class extends (_b327 = SingleStoreColumn, _a433 = entityKind, _b327) {
45294
+ constructor() {
45295
+ super(...arguments);
45296
+ __publicField(this, "elementType", "I64");
45297
+ }
45298
+ getSQLType() {
45299
+ return `vector(${this.config.length}, ${this.elementType}})`;
45300
+ }
45301
+ mapToDriverValue(value) {
45302
+ return `[${value.map((e) => e.toString()).join(",")}]`;
45303
+ }
45304
+ mapFromDriverValue(value) {
45305
+ if (typeof value === "string") {
45306
+ if (value.startsWith("[")) return value.slice(1, -1).split(",").map(BigInt);
45307
+ value = Buffer.from(value, "hex");
45308
+ }
45309
+ if (Buffer.isBuffer(value)) {
45310
+ const bytearr = new Uint8Array(value);
45311
+ return Array.from(new BigInt64Array(bytearr.buffer, 0, bytearr.length / 8));
45312
+ }
45313
+ return value;
45314
+ }
45315
+ };
45316
+ __publicField(SingleStoreBigIntVector, _a433, "SingleStoreBigIntVector");
45234
45317
  }
45235
45318
  });
45236
45319
 
@@ -45238,13 +45321,13 @@ var init_vector4 = __esm({
45238
45321
  function year2(name2) {
45239
45322
  return new SingleStoreYearBuilder(name2 ?? "");
45240
45323
  }
45241
- var _a432, _b326, SingleStoreYearBuilder, _a433, _b327, SingleStoreYear;
45324
+ var _a434, _b328, SingleStoreYearBuilder, _a435, _b329, SingleStoreYear;
45242
45325
  var init_year2 = __esm({
45243
45326
  "../drizzle-orm/dist/singlestore-core/columns/year.js"() {
45244
45327
  "use strict";
45245
45328
  init_entity();
45246
45329
  init_common5();
45247
- SingleStoreYearBuilder = class extends (_b326 = SingleStoreColumnBuilder, _a432 = entityKind, _b326) {
45330
+ SingleStoreYearBuilder = class extends (_b328 = SingleStoreColumnBuilder, _a434 = entityKind, _b328) {
45248
45331
  constructor(name2) {
45249
45332
  super(name2, "number year", "SingleStoreYear");
45250
45333
  }
@@ -45256,13 +45339,17 @@ var init_year2 = __esm({
45256
45339
  );
45257
45340
  }
45258
45341
  };
45259
- __publicField(SingleStoreYearBuilder, _a432, "SingleStoreYearBuilder");
45260
- SingleStoreYear = class extends (_b327 = SingleStoreColumn, _a433 = entityKind, _b327) {
45342
+ __publicField(SingleStoreYearBuilder, _a434, "SingleStoreYearBuilder");
45343
+ SingleStoreYear = class extends (_b329 = SingleStoreColumn, _a435 = entityKind, _b329) {
45261
45344
  getSQLType() {
45262
45345
  return `year`;
45263
45346
  }
45347
+ mapFromDriverValue(value) {
45348
+ if (typeof value !== "number") return Number(value);
45349
+ return value;
45350
+ }
45264
45351
  };
45265
- __publicField(SingleStoreYear, _a433, "SingleStoreYear");
45352
+ __publicField(SingleStoreYear, _a435, "SingleStoreYear");
45266
45353
  }
45267
45354
  });
45268
45355
 
@@ -45300,17 +45387,17 @@ var init_columns4 = __esm({
45300
45387
  });
45301
45388
 
45302
45389
  // ../drizzle-orm/dist/singlestore-core/query-builders/count.js
45303
- var _a434, _b328, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
45390
+ var _a436, _b330, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
45304
45391
  var init_count4 = __esm({
45305
45392
  "../drizzle-orm/dist/singlestore-core/query-builders/count.js"() {
45306
45393
  "use strict";
45307
45394
  init_entity();
45308
45395
  init_sql();
45309
- _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b328 = entityKind, _a434 = Symbol.toStringTag, _c12) {
45396
+ _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b330 = entityKind, _a436 = Symbol.toStringTag, _c12) {
45310
45397
  constructor(params) {
45311
45398
  super(_SingleStoreCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
45312
45399
  __publicField(this, "sql");
45313
- __publicField(this, _a434, "SingleStoreCountBuilder");
45400
+ __publicField(this, _a436, "SingleStoreCountBuilder");
45314
45401
  __publicField(this, "session");
45315
45402
  this.params = params;
45316
45403
  this.mapWith(Number);
@@ -45348,18 +45435,18 @@ var init_count4 = __esm({
45348
45435
  );
45349
45436
  }
45350
45437
  };
45351
- __publicField(_SingleStoreCountBuilder, _b328, "SingleStoreCountBuilder");
45438
+ __publicField(_SingleStoreCountBuilder, _b330, "SingleStoreCountBuilder");
45352
45439
  SingleStoreCountBuilder = _SingleStoreCountBuilder;
45353
45440
  }
45354
45441
  });
45355
45442
 
45356
45443
  // ../drizzle-orm/dist/singlestore-core/indexes.js
45357
- var _a435, IndexBuilderOn4, _a436, IndexBuilder4, _a437, Index6;
45444
+ var _a437, IndexBuilderOn4, _a438, IndexBuilder4, _a439, Index6;
45358
45445
  var init_indexes4 = __esm({
45359
45446
  "../drizzle-orm/dist/singlestore-core/indexes.js"() {
45360
45447
  "use strict";
45361
45448
  init_entity();
45362
- _a435 = entityKind;
45449
+ _a437 = entityKind;
45363
45450
  IndexBuilderOn4 = class {
45364
45451
  constructor(name2, unique) {
45365
45452
  this.name = name2;
@@ -45369,8 +45456,8 @@ var init_indexes4 = __esm({
45369
45456
  return new IndexBuilder4(this.name, columns, this.unique);
45370
45457
  }
45371
45458
  };
45372
- __publicField(IndexBuilderOn4, _a435, "SingleStoreIndexBuilderOn");
45373
- _a436 = entityKind;
45459
+ __publicField(IndexBuilderOn4, _a437, "SingleStoreIndexBuilderOn");
45460
+ _a438 = entityKind;
45374
45461
  IndexBuilder4 = class {
45375
45462
  constructor(name2, columns, unique) {
45376
45463
  /** @internal */
@@ -45398,15 +45485,15 @@ var init_indexes4 = __esm({
45398
45485
  return new Index6(this.config, table6);
45399
45486
  }
45400
45487
  };
45401
- __publicField(IndexBuilder4, _a436, "SingleStoreIndexBuilder");
45402
- _a437 = entityKind;
45488
+ __publicField(IndexBuilder4, _a438, "SingleStoreIndexBuilder");
45489
+ _a439 = entityKind;
45403
45490
  Index6 = class {
45404
45491
  constructor(config, table6) {
45405
45492
  __publicField(this, "config");
45406
45493
  this.config = { ...config, table: table6 };
45407
45494
  }
45408
45495
  };
45409
- __publicField(Index6, _a437, "SingleStoreIndex");
45496
+ __publicField(Index6, _a439, "SingleStoreIndex");
45410
45497
  }
45411
45498
  });
45412
45499
 
@@ -45494,20 +45581,20 @@ function singlestoreTableWithSchema(name2, columns, extraConfig, schema5, baseNa
45494
45581
  }
45495
45582
  return table6;
45496
45583
  }
45497
- var _a438, _b329, _c13, _d5, SingleStoreTable;
45584
+ var _a440, _b331, _c13, _d5, SingleStoreTable;
45498
45585
  var init_table5 = __esm({
45499
45586
  "../drizzle-orm/dist/singlestore-core/table.js"() {
45500
45587
  "use strict";
45501
45588
  init_entity();
45502
45589
  init_table();
45503
45590
  init_all4();
45504
- SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b329 = Table2.Symbol.Columns, _a438 = Table2.Symbol.ExtraConfigBuilder, _d5) {
45591
+ SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b331 = Table2.Symbol.Columns, _a440 = Table2.Symbol.ExtraConfigBuilder, _d5) {
45505
45592
  constructor() {
45506
45593
  super(...arguments);
45507
45594
  /** @internal */
45508
- __publicField(this, _b329);
45595
+ __publicField(this, _b331);
45509
45596
  /** @internal */
45510
- __publicField(this, _a438);
45597
+ __publicField(this, _a440);
45511
45598
  }
45512
45599
  };
45513
45600
  __publicField(SingleStoreTable, _c13, "SingleStoreTable");
@@ -45517,13 +45604,13 @@ var init_table5 = __esm({
45517
45604
  });
45518
45605
 
45519
45606
  // ../drizzle-orm/dist/singlestore-core/primary-keys.js
45520
- var _a439, PrimaryKeyBuilder4, _a440, PrimaryKey4;
45607
+ var _a441, PrimaryKeyBuilder4, _a442, PrimaryKey4;
45521
45608
  var init_primary_keys4 = __esm({
45522
45609
  "../drizzle-orm/dist/singlestore-core/primary-keys.js"() {
45523
45610
  "use strict";
45524
45611
  init_entity();
45525
45612
  init_table5();
45526
- _a439 = entityKind;
45613
+ _a441 = entityKind;
45527
45614
  PrimaryKeyBuilder4 = class {
45528
45615
  constructor(columns, name2) {
45529
45616
  /** @internal */
@@ -45538,8 +45625,8 @@ var init_primary_keys4 = __esm({
45538
45625
  return new PrimaryKey4(table6, this.columns, this.name);
45539
45626
  }
45540
45627
  };
45541
- __publicField(PrimaryKeyBuilder4, _a439, "SingleStorePrimaryKeyBuilder");
45542
- _a440 = entityKind;
45628
+ __publicField(PrimaryKeyBuilder4, _a441, "SingleStorePrimaryKeyBuilder");
45629
+ _a442 = entityKind;
45543
45630
  PrimaryKey4 = class {
45544
45631
  constructor(table6, columns, name2) {
45545
45632
  __publicField(this, "columns");
@@ -45552,7 +45639,7 @@ var init_primary_keys4 = __esm({
45552
45639
  return this.name ?? `${this.table[SingleStoreTable.Symbol.Name]}_${this.columns.map((column6) => column6.name).join("_")}_pk`;
45553
45640
  }
45554
45641
  };
45555
- __publicField(PrimaryKey4, _a440, "SingleStorePrimaryKey");
45642
+ __publicField(PrimaryKey4, _a442, "SingleStorePrimaryKey");
45556
45643
  }
45557
45644
  });
45558
45645
 
@@ -45616,7 +45703,7 @@ var init_utils10 = __esm({
45616
45703
  });
45617
45704
 
45618
45705
  // ../drizzle-orm/dist/singlestore-core/query-builders/delete.js
45619
- var _a441, _b330, SingleStoreDeleteBase;
45706
+ var _a443, _b332, SingleStoreDeleteBase;
45620
45707
  var init_delete4 = __esm({
45621
45708
  "../drizzle-orm/dist/singlestore-core/query-builders/delete.js"() {
45622
45709
  "use strict";
@@ -45625,7 +45712,7 @@ var init_delete4 = __esm({
45625
45712
  init_selection_proxy();
45626
45713
  init_table();
45627
45714
  init_utils10();
45628
- SingleStoreDeleteBase = class extends (_b330 = QueryPromise, _a441 = entityKind, _b330) {
45715
+ SingleStoreDeleteBase = class extends (_b332 = QueryPromise, _a443 = entityKind, _b332) {
45629
45716
  constructor(table6, session, dialect6, withList) {
45630
45717
  super();
45631
45718
  __publicField(this, "config");
@@ -45722,12 +45809,12 @@ var init_delete4 = __esm({
45722
45809
  return this;
45723
45810
  }
45724
45811
  };
45725
- __publicField(SingleStoreDeleteBase, _a441, "SingleStoreDelete");
45812
+ __publicField(SingleStoreDeleteBase, _a443, "SingleStoreDelete");
45726
45813
  }
45727
45814
  });
45728
45815
 
45729
45816
  // ../drizzle-orm/dist/singlestore-core/query-builders/insert.js
45730
- var _a442, SingleStoreInsertBuilder, _a443, _b331, SingleStoreInsertBase;
45817
+ var _a444, SingleStoreInsertBuilder, _a445, _b333, SingleStoreInsertBase;
45731
45818
  var init_insert4 = __esm({
45732
45819
  "../drizzle-orm/dist/singlestore-core/query-builders/insert.js"() {
45733
45820
  "use strict";
@@ -45737,7 +45824,7 @@ var init_insert4 = __esm({
45737
45824
  init_table();
45738
45825
  init_utils2();
45739
45826
  init_utils10();
45740
- _a442 = entityKind;
45827
+ _a444 = entityKind;
45741
45828
  SingleStoreInsertBuilder = class {
45742
45829
  constructor(table6, session, dialect6) {
45743
45830
  __publicField(this, "shouldIgnore", false);
@@ -45766,8 +45853,8 @@ var init_insert4 = __esm({
45766
45853
  return new SingleStoreInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
45767
45854
  }
45768
45855
  };
45769
- __publicField(SingleStoreInsertBuilder, _a442, "SingleStoreInsertBuilder");
45770
- SingleStoreInsertBase = class extends (_b331 = QueryPromise, _a443 = entityKind, _b331) {
45856
+ __publicField(SingleStoreInsertBuilder, _a444, "SingleStoreInsertBuilder");
45857
+ SingleStoreInsertBase = class extends (_b333 = QueryPromise, _a445 = entityKind, _b333) {
45771
45858
  constructor(table6, values, ignore, session, dialect6) {
45772
45859
  super();
45773
45860
  __publicField(this, "config");
@@ -45852,12 +45939,12 @@ var init_insert4 = __esm({
45852
45939
  return this;
45853
45940
  }
45854
45941
  };
45855
- __publicField(SingleStoreInsertBase, _a443, "SingleStoreInsert");
45942
+ __publicField(SingleStoreInsertBase, _a445, "SingleStoreInsert");
45856
45943
  }
45857
45944
  });
45858
45945
 
45859
45946
  // ../drizzle-orm/dist/singlestore-core/dialect.js
45860
- var _a444, SingleStoreDialect;
45947
+ var _a446, SingleStoreDialect;
45861
45948
  var init_dialect4 = __esm({
45862
45949
  "../drizzle-orm/dist/singlestore-core/dialect.js"() {
45863
45950
  "use strict";
@@ -45867,6 +45954,7 @@ var init_dialect4 = __esm({
45867
45954
  init_column();
45868
45955
  init_entity();
45869
45956
  init_errors();
45957
+ init_relations();
45870
45958
  init_expressions();
45871
45959
  init_sql();
45872
45960
  init_subquery();
@@ -45875,11 +45963,62 @@ var init_dialect4 = __esm({
45875
45963
  init_view_common();
45876
45964
  init_common5();
45877
45965
  init_table5();
45878
- _a444 = entityKind;
45966
+ _a446 = entityKind;
45879
45967
  SingleStoreDialect = class {
45880
45968
  constructor(config) {
45881
45969
  /** @internal */
45882
45970
  __publicField(this, "casing");
45971
+ __publicField(this, "unwrapAllColumns", (table6, selection) => {
45972
+ return sql.join(
45973
+ Object.entries(table6[TableColumns]).map(([k, v]) => {
45974
+ selection.push({
45975
+ key: k,
45976
+ field: v
45977
+ });
45978
+ return this.buildRqbColumn(table6, v, k);
45979
+ }),
45980
+ sql`, `
45981
+ );
45982
+ });
45983
+ __publicField(this, "getSelectedTableColumns", (table6, columns) => {
45984
+ const selectedColumns = [];
45985
+ const columnContainer = table6[TableColumns];
45986
+ const entries = Object.entries(columns);
45987
+ let colSelectionMode;
45988
+ for (const [k, v] of entries) {
45989
+ if (v === void 0) continue;
45990
+ colSelectionMode = colSelectionMode || v;
45991
+ if (v) {
45992
+ const column6 = columnContainer[k];
45993
+ selectedColumns.push({
45994
+ column: column6,
45995
+ tsName: k
45996
+ });
45997
+ }
45998
+ }
45999
+ if (colSelectionMode === false) {
46000
+ for (const [k, v] of Object.entries(columnContainer)) {
46001
+ if (columns[k] === false) continue;
46002
+ selectedColumns.push({
46003
+ column: v,
46004
+ tsName: k
46005
+ });
46006
+ }
46007
+ }
46008
+ return selectedColumns;
46009
+ });
46010
+ __publicField(this, "buildColumns", (table6, selection, params) => params?.columns ? (() => {
46011
+ const columnIdentifiers = [];
46012
+ const selectedColumns = this.getSelectedTableColumns(table6, params.columns);
46013
+ for (const { column: column6, tsName } of selectedColumns) {
46014
+ columnIdentifiers.push(this.buildRqbColumn(table6, column6, tsName));
46015
+ selection.push({
46016
+ key: tsName,
46017
+ field: column6
46018
+ });
46019
+ }
46020
+ return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
46021
+ })() : this.unwrapAllColumns(table6, selection));
45883
46022
  this.casing = new CasingCache(config?.casing);
45884
46023
  }
45885
46024
  async migrate(migrations, session, config) {
@@ -46214,7 +46353,7 @@ var init_dialect4 = __esm({
46214
46353
  invokeSource
46215
46354
  });
46216
46355
  }
46217
- buildRelationalQuery({
46356
+ _buildRelationalQuery({
46218
46357
  fullSchema,
46219
46358
  schema: schema5,
46220
46359
  tableNamesMap,
@@ -46324,7 +46463,7 @@ var init_dialect4 = __esm({
46324
46463
  )
46325
46464
  )
46326
46465
  );
46327
- const builtRelation = this.buildRelationalQuery({
46466
+ const builtRelation = this._buildRelationalQuery({
46328
46467
  fullSchema,
46329
46468
  schema: schema5,
46330
46469
  tableNamesMap,
@@ -46439,8 +46578,140 @@ var init_dialect4 = __esm({
46439
46578
  selection
46440
46579
  };
46441
46580
  }
46581
+ nestedSelectionerror() {
46582
+ throw new DrizzleError({
46583
+ message: `Views with nested selections are not supported by the relational query builder`
46584
+ });
46585
+ }
46586
+ buildRqbColumn(table6, column6, key) {
46587
+ if (is(column6, Column2)) {
46588
+ const name2 = sql`${table6}.${sql.identifier(this.casing.getColumnCasing(column6))}`;
46589
+ switch (column6.columnType) {
46590
+ case "SingleStoreBinary":
46591
+ case "SingleStoreVarBinary":
46592
+ case "SingleStoreTime":
46593
+ case "SingleStoreDateTimeString":
46594
+ case "SingleStoreTimestampString":
46595
+ case "SingleStoreFloat":
46596
+ case "SingleStoreDecimal":
46597
+ case "SingleStoreDecimalNumber":
46598
+ case "SingleStoreDecimalBigInt":
46599
+ case "SingleStoreBigInt64":
46600
+ case "SingleStoreEnumColumn": {
46601
+ return sql`cast(${name2} as char) as ${sql.identifier(key)}`;
46602
+ }
46603
+ case "SingleStoreVector":
46604
+ case "SingleStoreBigIntVector": {
46605
+ return sql`hex(${name2} :> blob) as ${sql.identifier(key)}`;
46606
+ }
46607
+ case "SingleStoreCustomColumn": {
46608
+ return sql`${column6.jsonSelectIdentifier(name2, sql)} as ${sql.identifier(key)}`;
46609
+ }
46610
+ default: {
46611
+ return sql`${name2} as ${sql.identifier(key)}`;
46612
+ }
46613
+ }
46614
+ }
46615
+ return sql`${table6}.${is(column6, SQL.Aliased) ? sql.identifier(column6.fieldAlias) : isSQLWrapper(column6) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
46616
+ }
46617
+ buildRelationalQuery({
46618
+ schema: schema5,
46619
+ table: table6,
46620
+ tableConfig,
46621
+ queryConfig: config,
46622
+ relationWhere,
46623
+ mode,
46624
+ errorPath,
46625
+ depth,
46626
+ isNestedMany,
46627
+ throughJoin
46628
+ }) {
46629
+ const selection = [];
46630
+ const isSingle = mode === "first";
46631
+ const params = config === true ? void 0 : config;
46632
+ const currentPath = errorPath ?? "";
46633
+ const currentDepth = depth ?? 0;
46634
+ if (!currentDepth) table6 = aliasedTable(table6, `d${currentDepth}`);
46635
+ const limit = isSingle ? 1 : params?.limit;
46636
+ const offset = params?.offset;
46637
+ const columns = this.buildColumns(table6, selection, params);
46638
+ const where = params?.where && relationWhere ? and(
46639
+ relationsFilterToSQL(table6, params.where, tableConfig.relations, schema5, this.casing),
46640
+ relationWhere
46641
+ ) : params?.where ? relationsFilterToSQL(table6, params.where, tableConfig.relations, schema5, this.casing) : relationWhere;
46642
+ const order = params?.orderBy ? relationsOrderToSQL(table6, params.orderBy) : void 0;
46643
+ const extras = params?.extras ? relationExtrasToSQL(table6, params.extras) : void 0;
46644
+ if (extras) selection.push(...extras.selection);
46645
+ const selectionArr = columns ? [columns] : [];
46646
+ const joins = params ? (() => {
46647
+ const { with: joins2 } = params;
46648
+ if (!joins2) return;
46649
+ const withEntries = Object.entries(joins2).filter(([_2, v]) => v);
46650
+ if (!withEntries.length) return;
46651
+ return sql.join(
46652
+ withEntries.map(([k, join]) => {
46653
+ const relation = tableConfig.relations[k];
46654
+ const isSingle2 = is(relation, One);
46655
+ selectionArr.push(
46656
+ 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)}`
46657
+ );
46658
+ const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
46659
+ const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
46660
+ const { filter: filter2, joinCondition } = relationToSQL(
46661
+ this.casing,
46662
+ relation,
46663
+ table6,
46664
+ targetTable,
46665
+ throughTable
46666
+ );
46667
+ const throughJoin2 = throughTable ? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}` : void 0;
46668
+ const innerQuery = this.buildRelationalQuery({
46669
+ table: targetTable,
46670
+ mode: isSingle2 ? "first" : "many",
46671
+ schema: schema5,
46672
+ queryConfig: join,
46673
+ tableConfig: schema5[relation.targetTableName],
46674
+ relationWhere: filter2,
46675
+ errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
46676
+ depth: currentDepth + 1,
46677
+ isNestedMany: !isSingle2,
46678
+ throughJoin: throughJoin2
46679
+ });
46680
+ selection.push({
46681
+ field: targetTable,
46682
+ key: k,
46683
+ selection: innerQuery.selection,
46684
+ isArray: !isSingle2,
46685
+ isOptional: (relation.optional ?? false) || join !== true && !!join.where
46686
+ });
46687
+ const jsonColumns = sql.join(
46688
+ innerQuery.selection.map((s) => sql`${sql.raw(this.escapeString(s.key))}, ${sql.identifier(s.key)}`),
46689
+ sql`, `
46690
+ );
46691
+ 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`;
46692
+ return joinQuery;
46693
+ })
46694
+ );
46695
+ })() : void 0;
46696
+ if (extras?.sql) selectionArr.push(extras.sql);
46697
+ if (!selectionArr.length) {
46698
+ throw new DrizzleError({
46699
+ message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}`
46700
+ });
46701
+ }
46702
+ if (isNestedMany && order) {
46703
+ selectionArr.push(sql`row_number() over (order by ${order}) as ${sql.identifier(`$drizzle_order_row_number`)}`);
46704
+ }
46705
+ const selectionSet = sql.join(selectionArr, sql`, `);
46706
+ 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)}`;
46707
+ return {
46708
+ sql: query,
46709
+ selection,
46710
+ order
46711
+ };
46712
+ }
46442
46713
  };
46443
- __publicField(SingleStoreDialect, _a444, "SingleStoreDialect");
46714
+ __publicField(SingleStoreDialect, _a446, "SingleStoreDialect");
46444
46715
  }
46445
46716
  });
46446
46717
 
@@ -46462,7 +46733,7 @@ function createSetOperator4(type, isAll) {
46462
46733
  return leftSelect.addSetOperators(setOperators);
46463
46734
  };
46464
46735
  }
46465
- var _a445, SingleStoreSelectBuilder, _a446, _b332, SingleStoreSelectQueryBuilderBase, _a447, _b333, SingleStoreSelectBase, getSingleStoreSetOperators, union5, unionAll4, intersect4, except4, minus;
46736
+ var _a447, SingleStoreSelectBuilder, _a448, _b334, SingleStoreSelectQueryBuilderBase, _a449, _b335, SingleStoreSelectBase, getSingleStoreSetOperators, union5, unionAll4, intersect4, except4, minus;
46466
46737
  var init_select5 = __esm({
46467
46738
  "../drizzle-orm/dist/singlestore-core/query-builders/select.js"() {
46468
46739
  "use strict";
@@ -46475,7 +46746,7 @@ var init_select5 = __esm({
46475
46746
  init_table();
46476
46747
  init_utils2();
46477
46748
  init_utils10();
46478
- _a445 = entityKind;
46749
+ _a447 = entityKind;
46479
46750
  SingleStoreSelectBuilder = class {
46480
46751
  constructor(config) {
46481
46752
  __publicField(this, "fields");
@@ -46518,8 +46789,8 @@ var init_select5 = __esm({
46518
46789
  );
46519
46790
  }
46520
46791
  };
46521
- __publicField(SingleStoreSelectBuilder, _a445, "SingleStoreSelectBuilder");
46522
- SingleStoreSelectQueryBuilderBase = class extends (_b332 = TypedQueryBuilder, _a446 = entityKind, _b332) {
46792
+ __publicField(SingleStoreSelectBuilder, _a447, "SingleStoreSelectBuilder");
46793
+ SingleStoreSelectQueryBuilderBase = class extends (_b334 = TypedQueryBuilder, _a448 = entityKind, _b334) {
46523
46794
  constructor({ table: table6, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
46524
46795
  super();
46525
46796
  __publicField(this, "_");
@@ -47140,8 +47411,8 @@ var init_select5 = __esm({
47140
47411
  return this;
47141
47412
  }
47142
47413
  };
47143
- __publicField(SingleStoreSelectQueryBuilderBase, _a446, "SingleStoreSelectQueryBuilder");
47144
- SingleStoreSelectBase = class extends (_b333 = SingleStoreSelectQueryBuilderBase, _a447 = entityKind, _b333) {
47414
+ __publicField(SingleStoreSelectQueryBuilderBase, _a448, "SingleStoreSelectQueryBuilder");
47415
+ SingleStoreSelectBase = class extends (_b335 = SingleStoreSelectQueryBuilderBase, _a449 = entityKind, _b335) {
47145
47416
  constructor() {
47146
47417
  super(...arguments);
47147
47418
  __publicField(this, "execute", (placeholderValues) => {
@@ -47172,7 +47443,7 @@ var init_select5 = __esm({
47172
47443
  return this;
47173
47444
  }
47174
47445
  };
47175
- __publicField(SingleStoreSelectBase, _a447, "SingleStoreSelect");
47446
+ __publicField(SingleStoreSelectBase, _a449, "SingleStoreSelect");
47176
47447
  applyMixins(SingleStoreSelectBase, [QueryPromise]);
47177
47448
  getSingleStoreSetOperators = () => ({
47178
47449
  union: union5,
@@ -47190,7 +47461,7 @@ var init_select5 = __esm({
47190
47461
  });
47191
47462
 
47192
47463
  // ../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js
47193
- var _a448, QueryBuilder4;
47464
+ var _a450, QueryBuilder4;
47194
47465
  var init_query_builder5 = __esm({
47195
47466
  "../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js"() {
47196
47467
  "use strict";
@@ -47199,7 +47470,7 @@ var init_query_builder5 = __esm({
47199
47470
  init_dialect4();
47200
47471
  init_subquery();
47201
47472
  init_select5();
47202
- _a448 = entityKind;
47473
+ _a450 = entityKind;
47203
47474
  QueryBuilder4 = class {
47204
47475
  constructor(dialect6) {
47205
47476
  __publicField(this, "dialect");
@@ -47269,7 +47540,7 @@ var init_query_builder5 = __esm({
47269
47540
  return this.dialect;
47270
47541
  }
47271
47542
  };
47272
- __publicField(QueryBuilder4, _a448, "SingleStoreQueryBuilder");
47543
+ __publicField(QueryBuilder4, _a450, "SingleStoreQueryBuilder");
47273
47544
  }
47274
47545
  });
47275
47546
 
@@ -47281,7 +47552,7 @@ var init_select_types4 = __esm({
47281
47552
  });
47282
47553
 
47283
47554
  // ../drizzle-orm/dist/singlestore-core/query-builders/update.js
47284
- var _a449, SingleStoreUpdateBuilder, _a450, _b334, SingleStoreUpdateBase;
47555
+ var _a451, SingleStoreUpdateBuilder, _a452, _b336, SingleStoreUpdateBase;
47285
47556
  var init_update4 = __esm({
47286
47557
  "../drizzle-orm/dist/singlestore-core/query-builders/update.js"() {
47287
47558
  "use strict";
@@ -47291,7 +47562,7 @@ var init_update4 = __esm({
47291
47562
  init_table();
47292
47563
  init_utils2();
47293
47564
  init_utils10();
47294
- _a449 = entityKind;
47565
+ _a451 = entityKind;
47295
47566
  SingleStoreUpdateBuilder = class {
47296
47567
  constructor(table6, session, dialect6, withList) {
47297
47568
  this.table = table6;
@@ -47309,8 +47580,8 @@ var init_update4 = __esm({
47309
47580
  );
47310
47581
  }
47311
47582
  };
47312
- __publicField(SingleStoreUpdateBuilder, _a449, "SingleStoreUpdateBuilder");
47313
- SingleStoreUpdateBase = class extends (_b334 = QueryPromise, _a450 = entityKind, _b334) {
47583
+ __publicField(SingleStoreUpdateBuilder, _a451, "SingleStoreUpdateBuilder");
47584
+ SingleStoreUpdateBase = class extends (_b336 = QueryPromise, _a452 = entityKind, _b336) {
47314
47585
  constructor(table6, set, session, dialect6, withList) {
47315
47586
  super();
47316
47587
  __publicField(this, "config");
@@ -47410,7 +47681,7 @@ var init_update4 = __esm({
47410
47681
  return this;
47411
47682
  }
47412
47683
  };
47413
- __publicField(SingleStoreUpdateBase, _a450, "SingleStoreUpdate");
47684
+ __publicField(SingleStoreUpdateBase, _a452, "SingleStoreUpdate");
47414
47685
  }
47415
47686
  });
47416
47687
 
@@ -47427,8 +47698,103 @@ var init_query_builders4 = __esm({
47427
47698
  }
47428
47699
  });
47429
47700
 
47701
+ // ../drizzle-orm/dist/singlestore-core/query-builders/query.js
47702
+ var _a453, RelationalQueryBuilder4, _a454, _b337, SingleStoreRelationalQuery;
47703
+ var init_query7 = __esm({
47704
+ "../drizzle-orm/dist/singlestore-core/query-builders/query.js"() {
47705
+ "use strict";
47706
+ init_entity();
47707
+ init_query_promise();
47708
+ init_relations();
47709
+ _a453 = entityKind;
47710
+ RelationalQueryBuilder4 = class {
47711
+ constructor(schema5, table6, tableConfig, dialect6, session) {
47712
+ this.schema = schema5;
47713
+ this.table = table6;
47714
+ this.tableConfig = tableConfig;
47715
+ this.dialect = dialect6;
47716
+ this.session = session;
47717
+ }
47718
+ findMany(config) {
47719
+ return new SingleStoreRelationalQuery(
47720
+ this.schema,
47721
+ this.table,
47722
+ this.tableConfig,
47723
+ this.dialect,
47724
+ this.session,
47725
+ config ?? true,
47726
+ "many"
47727
+ );
47728
+ }
47729
+ findFirst(config) {
47730
+ return new SingleStoreRelationalQuery(
47731
+ this.schema,
47732
+ this.table,
47733
+ this.tableConfig,
47734
+ this.dialect,
47735
+ this.session,
47736
+ config ?? true,
47737
+ "first"
47738
+ );
47739
+ }
47740
+ };
47741
+ __publicField(RelationalQueryBuilder4, _a453, "SingleStoreRelationalQueryBuilderV2");
47742
+ SingleStoreRelationalQuery = class extends (_b337 = QueryPromise, _a454 = entityKind, _b337) {
47743
+ constructor(schema5, table6, tableConfig, dialect6, session, config, mode) {
47744
+ super();
47745
+ this.schema = schema5;
47746
+ this.table = table6;
47747
+ this.tableConfig = tableConfig;
47748
+ this.dialect = dialect6;
47749
+ this.session = session;
47750
+ this.config = config;
47751
+ this.mode = mode;
47752
+ }
47753
+ prepare() {
47754
+ const { query, builtQuery } = this._toSQL();
47755
+ return this.session.prepareRelationalQuery(
47756
+ builtQuery,
47757
+ void 0,
47758
+ (rawRows) => {
47759
+ const rows = rawRows.map((row) => mapRelationalRow(row, query.selection, void 0, void 0, true));
47760
+ if (this.mode === "first") {
47761
+ return rows[0];
47762
+ }
47763
+ return rows;
47764
+ }
47765
+ );
47766
+ }
47767
+ _getQuery() {
47768
+ return this.dialect.buildRelationalQuery({
47769
+ schema: this.schema,
47770
+ table: this.table,
47771
+ tableConfig: this.tableConfig,
47772
+ queryConfig: this.config,
47773
+ mode: this.mode
47774
+ });
47775
+ }
47776
+ _toSQL() {
47777
+ const query = this._getQuery();
47778
+ const builtQuery = this.dialect.sqlToQuery(query.sql);
47779
+ return { builtQuery, query };
47780
+ }
47781
+ /** @internal */
47782
+ getSQL() {
47783
+ return this._getQuery().sql;
47784
+ }
47785
+ toSQL() {
47786
+ return this._toSQL().builtQuery;
47787
+ }
47788
+ execute() {
47789
+ return this.prepare().execute();
47790
+ }
47791
+ };
47792
+ __publicField(SingleStoreRelationalQuery, _a454, "SingleStoreRelationalQueryV2");
47793
+ }
47794
+ });
47795
+
47430
47796
  // ../drizzle-orm/dist/singlestore-core/db.js
47431
- var _a451, SingleStoreDatabase;
47797
+ var _a455, SingleStoreDatabase;
47432
47798
  var init_db4 = __esm({
47433
47799
  "../drizzle-orm/dist/singlestore-core/db.js"() {
47434
47800
  "use strict";
@@ -47438,11 +47804,11 @@ var init_db4 = __esm({
47438
47804
  init_subquery();
47439
47805
  init_count4();
47440
47806
  init_query_builders4();
47441
- _a451 = entityKind;
47807
+ init_query7();
47808
+ _a455 = entityKind;
47442
47809
  SingleStoreDatabase = class {
47443
- constructor(dialect6, session, schema5) {
47444
- // We are waiting for SingleStore support for `json_array` function
47445
- /**@inrernal */
47810
+ constructor(dialect6, session, relations, schema5) {
47811
+ // TO-DO: Figure out how to pass DrizzleTypeError without breaking withReplicas
47446
47812
  __publicField(this, "query");
47447
47813
  /**
47448
47814
  * Creates a subquery that defines a temporary named result set as a CTE.
@@ -47500,13 +47866,24 @@ var init_db4 = __esm({
47500
47866
  this._ = schema5 ? {
47501
47867
  schema: schema5.schema,
47502
47868
  fullSchema: schema5.fullSchema,
47503
- tableNamesMap: schema5.tableNamesMap
47869
+ tableNamesMap: schema5.tableNamesMap,
47870
+ relations
47504
47871
  } : {
47505
47872
  schema: void 0,
47506
47873
  fullSchema: {},
47507
- tableNamesMap: {}
47874
+ tableNamesMap: {},
47875
+ relations
47508
47876
  };
47509
47877
  this.query = {};
47878
+ for (const [tableName, relation] of Object.entries(relations)) {
47879
+ this.query[tableName] = new RelationalQueryBuilder4(
47880
+ relations,
47881
+ relations[relation.name].table,
47882
+ relation,
47883
+ dialect6,
47884
+ session
47885
+ );
47886
+ }
47510
47887
  this.$cache = { invalidate: async (_params) => {
47511
47888
  } };
47512
47889
  }
@@ -47645,18 +48022,18 @@ var init_db4 = __esm({
47645
48022
  return this.session.transaction(transaction, config);
47646
48023
  }
47647
48024
  };
47648
- __publicField(SingleStoreDatabase, _a451, "SingleStoreDatabase");
48025
+ __publicField(SingleStoreDatabase, _a455, "SingleStoreDatabase");
47649
48026
  }
47650
48027
  });
47651
48028
 
47652
48029
  // ../drizzle-orm/dist/singlestore-core/schema.js
47653
- var _a452, SingleStoreSchema5;
48030
+ var _a456, SingleStoreSchema5;
47654
48031
  var init_schema3 = __esm({
47655
48032
  "../drizzle-orm/dist/singlestore-core/schema.js"() {
47656
48033
  "use strict";
47657
48034
  init_entity();
47658
48035
  init_table5();
47659
- _a452 = entityKind;
48036
+ _a456 = entityKind;
47660
48037
  SingleStoreSchema5 = class {
47661
48038
  constructor(schemaName) {
47662
48039
  __publicField(this, "table", (name2, columns, extraConfig) => {
@@ -47669,12 +48046,12 @@ var init_schema3 = __esm({
47669
48046
  return singlestoreViewWithSchema(name, columns, this.schemaName);
47670
48047
  }) as typeof singlestoreView; */
47671
48048
  };
47672
- __publicField(SingleStoreSchema5, _a452, "SingleStoreSchema");
48049
+ __publicField(SingleStoreSchema5, _a456, "SingleStoreSchema");
47673
48050
  }
47674
48051
  });
47675
48052
 
47676
48053
  // ../drizzle-orm/dist/singlestore-core/session.js
47677
- var _a453, SingleStorePreparedQuery, _a454, SingleStoreSession, _a455, _b335, SingleStoreTransaction;
48054
+ var _a457, SingleStorePreparedQuery, _a458, SingleStoreSession, _a459, _b338, SingleStoreTransaction;
47678
48055
  var init_session4 = __esm({
47679
48056
  "../drizzle-orm/dist/singlestore-core/session.js"() {
47680
48057
  "use strict";
@@ -47683,7 +48060,7 @@ var init_session4 = __esm({
47683
48060
  init_errors();
47684
48061
  init_sql();
47685
48062
  init_db4();
47686
- _a453 = entityKind;
48063
+ _a457 = entityKind;
47687
48064
  SingleStorePreparedQuery = class {
47688
48065
  constructor(cache, queryMetadata, cacheConfig) {
47689
48066
  /** @internal */
@@ -47765,8 +48142,8 @@ var init_session4 = __esm({
47765
48142
  }
47766
48143
  }
47767
48144
  };
47768
- __publicField(SingleStorePreparedQuery, _a453, "SingleStorePreparedQuery");
47769
- _a454 = entityKind;
48145
+ __publicField(SingleStorePreparedQuery, _a457, "SingleStorePreparedQuery");
48146
+ _a458 = entityKind;
47770
48147
  SingleStoreSession = class {
47771
48148
  constructor(dialect6) {
47772
48149
  this.dialect = dialect6;
@@ -47801,10 +48178,11 @@ var init_session4 = __esm({
47801
48178
  return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
47802
48179
  }
47803
48180
  };
47804
- __publicField(SingleStoreSession, _a454, "SingleStoreSession");
47805
- SingleStoreTransaction = class extends (_b335 = SingleStoreDatabase, _a455 = entityKind, _b335) {
47806
- constructor(dialect6, session, schema5, nestedIndex) {
47807
- super(dialect6, session, schema5);
48181
+ __publicField(SingleStoreSession, _a458, "SingleStoreSession");
48182
+ SingleStoreTransaction = class extends (_b338 = SingleStoreDatabase, _a459 = entityKind, _b338) {
48183
+ constructor(dialect6, session, relations, schema5, nestedIndex) {
48184
+ super(dialect6, session, relations, schema5);
48185
+ this.relations = relations;
47808
48186
  this.schema = schema5;
47809
48187
  this.nestedIndex = nestedIndex;
47810
48188
  }
@@ -47812,7 +48190,7 @@ var init_session4 = __esm({
47812
48190
  throw new TransactionRollbackError();
47813
48191
  }
47814
48192
  };
47815
- __publicField(SingleStoreTransaction, _a455, "SingleStoreTransaction");
48193
+ __publicField(SingleStoreTransaction, _a459, "SingleStoreTransaction");
47816
48194
  }
47817
48195
  });
47818
48196