drizzle-kit 1.0.0-beta.1-94774b0 → 1.0.0-beta.1-69a2ca0

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 +534 -128
  2. package/api.mjs +534 -128
  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 = {}));
@@ -23573,37 +23573,65 @@ function processRelations(tablesConfig, tables) {
23573
23573
  if (!is(relation, Relation)) {
23574
23574
  continue;
23575
23575
  }
23576
- const relationPrintName = `relations -> ${tableConfig.name}: { ${relationFieldName}: r.${is(relation, One) ? "one" : "many"}.${relation.targetTableName}(...) }`;
23577
- if (typeof relation.alias === "string" && !relation.alias) {
23576
+ let reverseRelation;
23577
+ const {
23578
+ targetTableName,
23579
+ alias,
23580
+ sourceColumns,
23581
+ targetColumns,
23582
+ throughTable,
23583
+ sourceTable,
23584
+ through,
23585
+ targetTable,
23586
+ where,
23587
+ sourceColumnTableNames,
23588
+ targetColumnTableNames
23589
+ } = relation;
23590
+ const relationPrintName = `relations -> ${tableConfig.name}: { ${relationFieldName}: r.${is(relation, One) ? "one" : "many"}.${targetTableName}(...) }`;
23591
+ if (typeof alias === "string" && !alias) {
23578
23592
  throw new Error(`${relationPrintName}: "alias" cannot be an empty string - omit it if you don't need it`);
23579
23593
  }
23580
- if (relation.sourceColumns?.length === 0) {
23581
- throw new Error(`${relationPrintName}: "from" cannot be an empty array`);
23594
+ if (sourceColumns?.length === 0) {
23595
+ throw new Error(`${relationPrintName}: "from" cannot be empty`);
23582
23596
  }
23583
- if (relation.targetColumns?.length === 0) {
23584
- throw new Error(`${relationPrintName}: "to" cannot be an empty array`);
23597
+ if (targetColumns?.length === 0) {
23598
+ throw new Error(`${relationPrintName}: "to" cannot be empty`);
23585
23599
  }
23586
- if (relation.sourceColumns && relation.targetColumns) {
23587
- if (relation.sourceColumns.length !== relation.targetColumns.length && !relation.throughTable) {
23600
+ if (sourceColumns && targetColumns) {
23601
+ if (sourceColumns.length !== targetColumns.length && !throughTable) {
23588
23602
  throw new Error(
23589
23603
  `${relationPrintName}: "from" and "to" fields without "through" must have the same length`
23590
23604
  );
23591
23605
  }
23592
- if (relation.through) {
23593
- if (relation.through.source.length !== relation.sourceColumns.length || relation.through.target.length !== relation.targetColumns.length) {
23606
+ for (const sName of sourceColumnTableNames) {
23607
+ if (sName !== sourceTableName) {
23608
+ throw new Error(
23609
+ `${relationPrintName}: all "from" columns must belong to table "${sourceTableName}", found column of table "${sName}"`
23610
+ );
23611
+ }
23612
+ }
23613
+ for (const tName of targetColumnTableNames) {
23614
+ if (tName !== targetTableName) {
23615
+ throw new Error(
23616
+ `${relationPrintName}: all "to" columns must belong to table "${targetTable}", found column of table "${tName}"`
23617
+ );
23618
+ }
23619
+ }
23620
+ if (through) {
23621
+ if (through.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
23594
23622
  throw new Error(
23595
23623
  `${relationPrintName}: ".through(column)" must be used either on all columns in "from" and "to" or not defined on any of them`
23596
23624
  );
23597
23625
  }
23598
- for (const column6 of relation.through.source) {
23599
- if (tables[column6._.tableName] !== relation.throughTable) {
23626
+ for (const column6 of through.source) {
23627
+ if (tables[column6._.tableName] !== throughTable) {
23600
23628
  throw new Error(
23601
23629
  `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
23602
23630
  );
23603
23631
  }
23604
23632
  }
23605
- for (const column6 of relation.through.target) {
23606
- if (tables[column6._.tableName] !== relation.throughTable) {
23633
+ for (const column6 of through.target) {
23634
+ if (tables[column6._.tableName] !== throughTable) {
23607
23635
  throw new Error(
23608
23636
  `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
23609
23637
  );
@@ -23612,54 +23640,52 @@ function processRelations(tablesConfig, tables) {
23612
23640
  }
23613
23641
  continue;
23614
23642
  }
23615
- if (relation.sourceColumns || relation.targetColumns) {
23643
+ if (sourceColumns || targetColumns) {
23616
23644
  throw new Error(
23617
23645
  `${relationPrintName}: relation must have either both "from" and "to" defined, or none of them`
23618
23646
  );
23619
23647
  }
23620
- let reverseRelation;
23621
- const targetTableTsName = relation.targetTableName;
23622
- const reverseTableConfig = tablesConfig[targetTableTsName];
23648
+ const reverseTableConfig = tablesConfig[targetTableName];
23623
23649
  if (!reverseTableConfig) {
23624
23650
  throw new Error(
23625
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableTsName}" were found"`
23651
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableName}" were found"`
23626
23652
  );
23627
23653
  }
23628
- if (relation.alias) {
23654
+ if (alias) {
23629
23655
  const reverseRelations = Object.values(reverseTableConfig.relations).filter(
23630
- (it) => is(it, Relation) && it.alias === relation.alias && it !== relation
23656
+ (it) => is(it, Relation) && it.alias === alias && it !== relation
23631
23657
  );
23632
23658
  if (reverseRelations.length > 1) {
23633
23659
  throw new Error(
23634
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${relation.alias}" found in table "${targetTableTsName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
23660
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${alias}" found in table "${targetTableName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
23635
23661
  );
23636
23662
  }
23637
23663
  reverseRelation = reverseRelations[0];
23638
23664
  if (!reverseRelation) {
23639
23665
  throw new Error(
23640
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableTsName}" with alias "${relation.alias}"`
23666
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableName}" with alias "${alias}"`
23641
23667
  );
23642
23668
  }
23643
23669
  } else {
23644
23670
  const reverseRelations = Object.values(reverseTableConfig.relations).filter(
23645
- (it) => is(it, Relation) && it.targetTable === relation.sourceTable && !it.alias && it !== relation
23671
+ (it) => is(it, Relation) && it.targetTable === sourceTable && !it.alias && it !== relation
23646
23672
  );
23647
23673
  if (reverseRelations.length > 1) {
23648
23674
  throw new Error(
23649
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableTsName}" and "${sourceTableName}" were found.
23675
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableName}" and "${sourceTableName}" were found.
23650
23676
  Hint: you can specify "alias" on both sides of the relation with the same value`
23651
23677
  );
23652
23678
  }
23653
23679
  reverseRelation = reverseRelations[0];
23654
23680
  if (!reverseRelation) {
23655
23681
  throw new Error(
23656
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableTsName}" with target table "${sourceTableName}" was found`
23682
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableName}" with target table "${sourceTableName}" was found`
23657
23683
  );
23658
23684
  }
23659
23685
  }
23660
23686
  if (!reverseRelation.sourceColumns || !reverseRelation.targetColumns) {
23661
23687
  throw new Error(
23662
- `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableTsName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
23688
+ `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
23663
23689
  );
23664
23690
  }
23665
23691
  relation.sourceColumns = reverseRelation.targetColumns;
@@ -23669,8 +23695,8 @@ Hint: you can specify "alias" on both sides of the relation with the same value`
23669
23695
  target: reverseRelation.through.source
23670
23696
  } : void 0;
23671
23697
  relation.throughTable = reverseRelation.throughTable;
23672
- relation.isReversed = !relation.where;
23673
- relation.where = relation.where ?? reverseRelation.where;
23698
+ relation.isReversed = !where;
23699
+ relation.where = where ?? reverseRelation.where;
23674
23700
  }
23675
23701
  }
23676
23702
  return tablesConfig;
@@ -23701,12 +23727,15 @@ function buildRelationsParts(tables, config) {
23701
23727
  function getOrderByOperators() {
23702
23728
  return orderByOperators;
23703
23729
  }
23704
- function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, path2) {
23730
+ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (value) => value, parseJson = false, parseJsonIfString = false, path2) {
23705
23731
  for (const selectionItem of buildQueryResultSelection) {
23706
23732
  if (selectionItem.selection) {
23707
23733
  const currentPath = `${path2 ? `${path2}.` : ""}${selectionItem.key}`;
23708
23734
  if (row[selectionItem.key] === null) continue;
23709
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
+ }
23710
23739
  if (selectionItem.isArray) {
23711
23740
  for (const item of row[selectionItem.key]) {
23712
23741
  mapRelationalRow(
@@ -23714,6 +23743,7 @@ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (valu
23714
23743
  selectionItem.selection,
23715
23744
  mapColumnValue,
23716
23745
  false,
23746
+ parseJsonIfString,
23717
23747
  currentPath
23718
23748
  );
23719
23749
  }
@@ -23724,6 +23754,7 @@ function mapRelationalRow(row, buildQueryResultSelection, mapColumnValue = (valu
23724
23754
  selectionItem.selection,
23725
23755
  mapColumnValue,
23726
23756
  false,
23757
+ parseJsonIfString,
23727
23758
  currentPath
23728
23759
  );
23729
23760
  continue;
@@ -24030,6 +24061,10 @@ var init_relations = __esm({
24030
24061
  __publicField(this, "through");
24031
24062
  __publicField(this, "throughTable");
24032
24063
  __publicField(this, "isReversed");
24064
+ /** @internal */
24065
+ __publicField(this, "sourceColumnTableNames", []);
24066
+ /** @internal */
24067
+ __publicField(this, "targetColumnTableNames", []);
24033
24068
  this.targetTableName = targetTableName;
24034
24069
  this.targetTable = targetTable;
24035
24070
  }
@@ -24045,12 +24080,14 @@ var init_relations = __esm({
24045
24080
  if (config?.from) {
24046
24081
  this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
24047
24082
  this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
24083
+ this.sourceColumnTableNames.push(it._.tableName);
24048
24084
  return it._.column;
24049
24085
  });
24050
24086
  }
24051
24087
  if (config?.to) {
24052
24088
  this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
24053
24089
  this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
24090
+ this.targetColumnTableNames.push(it._.tableName);
24054
24091
  return it._.column;
24055
24092
  });
24056
24093
  }
@@ -24074,12 +24111,14 @@ var init_relations = __esm({
24074
24111
  if (config?.from) {
24075
24112
  this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
24076
24113
  this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
24114
+ this.sourceColumnTableNames.push(it._.tableName);
24077
24115
  return it._.column;
24078
24116
  });
24079
24117
  }
24080
24118
  if (config?.to) {
24081
24119
  this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
24082
24120
  this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
24121
+ this.targetColumnTableNames.push(it._.tableName);
24083
24122
  return it._.column;
24084
24123
  });
24085
24124
  }
@@ -40572,7 +40611,7 @@ var init_dialect3 = __esm({
40572
40611
  mode,
40573
40612
  errorPath,
40574
40613
  depth,
40575
- isNested,
40614
+ isNestedMany,
40576
40615
  throughJoin
40577
40616
  }) {
40578
40617
  const selection = [];
@@ -40621,7 +40660,7 @@ var init_dialect3 = __esm({
40621
40660
  relationWhere: filter2,
40622
40661
  errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
40623
40662
  depth: currentDepth + 1,
40624
- isNested: true,
40663
+ isNestedMany: !isSingle2,
40625
40664
  throughJoin: throughJoin2
40626
40665
  });
40627
40666
  selection.push({
@@ -40646,7 +40685,7 @@ var init_dialect3 = __esm({
40646
40685
  message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}`
40647
40686
  });
40648
40687
  }
40649
- if (isNested && order) {
40688
+ if (isNestedMany && order) {
40650
40689
  selectionArr.push(sql`row_number() over (order by ${order})`);
40651
40690
  }
40652
40691
  const selectionSet = sql.join(selectionArr, sql`, `);
@@ -44576,6 +44615,10 @@ var init_float2 = __esm({
44576
44615
  }
44577
44616
  return this.unsigned ? `${type} unsigned` : type;
44578
44617
  }
44618
+ mapFromDriverValue(value) {
44619
+ if (typeof value !== "number") return Number(value);
44620
+ return value;
44621
+ }
44579
44622
  };
44580
44623
  __publicField(SingleStoreFloat, _a401, "SingleStoreFloat");
44581
44624
  }
@@ -45157,9 +45200,9 @@ var init_varchar3 = __esm({
45157
45200
  // ../drizzle-orm/dist/singlestore-core/columns/vector.js
45158
45201
  function vector2(a, b) {
45159
45202
  const { name: name2, config } = getColumnNameAndConfig(a, b);
45160
- return new SingleStoreVectorBuilder(name2, config);
45203
+ return config.elementType === "I64" ? new SingleStoreBigIntVectorBuilder(name2, config) : new SingleStoreVectorBuilder(name2, config);
45161
45204
  }
45162
- var _a430, _b324, SingleStoreVectorBuilder, _a431, _b325, SingleStoreVector;
45205
+ var _a430, _b324, SingleStoreVectorBuilder, _a431, _b325, SingleStoreVector, _a432, _b326, SingleStoreBigIntVectorBuilder, _a433, _b327, SingleStoreBigIntVector;
45163
45206
  var init_vector4 = __esm({
45164
45207
  "../drizzle-orm/dist/singlestore-core/columns/vector.js"() {
45165
45208
  "use strict";
@@ -45195,13 +45238,81 @@ var init_vector4 = __esm({
45195
45238
  return `vector(${this.config.length}, ${this.elementType || "F32"})`;
45196
45239
  }
45197
45240
  mapToDriverValue(value) {
45198
- return JSON.stringify(value);
45241
+ return `[${value.map((e) => e.toString()).join(",")}]`;
45199
45242
  }
45200
45243
  mapFromDriverValue(value) {
45201
- return JSON.parse(value);
45244
+ if (typeof value === "string") {
45245
+ if (value.startsWith("[")) return value.slice(1, -1).split(",").map(Number);
45246
+ value = Buffer.from(value, "hex");
45247
+ }
45248
+ if (Buffer.isBuffer(value)) {
45249
+ const type = this.elementType || "F32";
45250
+ const bytearr = new Uint8Array(value);
45251
+ switch (type) {
45252
+ case "I8": {
45253
+ return Array.from(new Int8Array(bytearr.buffer, 0, bytearr.length / 1));
45254
+ }
45255
+ case "I16": {
45256
+ return Array.from(new Int16Array(bytearr.buffer, 0, bytearr.length / 2));
45257
+ }
45258
+ case "I32": {
45259
+ return Array.from(new Int32Array(bytearr.buffer, 0, bytearr.length / 4));
45260
+ }
45261
+ case "F32": {
45262
+ return Array.from(new Float32Array(bytearr.buffer, 0, bytearr.length / 4));
45263
+ }
45264
+ case "F64": {
45265
+ return Array.from(new Float64Array(bytearr.buffer, 0, bytearr.length / 8));
45266
+ }
45267
+ }
45268
+ }
45269
+ return value;
45202
45270
  }
45203
45271
  };
45204
45272
  __publicField(SingleStoreVector, _a431, "SingleStoreVector");
45273
+ SingleStoreBigIntVectorBuilder = class extends (_b326 = SingleStoreColumnBuilder, _a432 = entityKind, _b326) {
45274
+ constructor(name2, config) {
45275
+ super(name2, "array int64vector", "SingleStoreBigIntVector");
45276
+ this.config.length = config.dimensions;
45277
+ this.config.isLengthExact = true;
45278
+ }
45279
+ /** @internal */
45280
+ build(table6) {
45281
+ return new SingleStoreBigIntVector(
45282
+ table6,
45283
+ this.config
45284
+ );
45285
+ }
45286
+ /** @internal */
45287
+ generatedAlwaysAs(as, config) {
45288
+ throw new Error("Method not implemented.");
45289
+ }
45290
+ };
45291
+ __publicField(SingleStoreBigIntVectorBuilder, _a432, "SingleStoreBigIntVectorBuilder");
45292
+ SingleStoreBigIntVector = class extends (_b327 = SingleStoreColumn, _a433 = entityKind, _b327) {
45293
+ constructor() {
45294
+ super(...arguments);
45295
+ __publicField(this, "elementType", "I64");
45296
+ }
45297
+ getSQLType() {
45298
+ return `vector(${this.config.length}, ${this.elementType}})`;
45299
+ }
45300
+ mapToDriverValue(value) {
45301
+ return `[${value.map((e) => e.toString()).join(",")}]`;
45302
+ }
45303
+ mapFromDriverValue(value) {
45304
+ if (typeof value === "string") {
45305
+ if (value.startsWith("[")) return value.slice(1, -1).split(",").map(BigInt);
45306
+ value = Buffer.from(value, "hex");
45307
+ }
45308
+ if (Buffer.isBuffer(value)) {
45309
+ const bytearr = new Uint8Array(value);
45310
+ return Array.from(new BigInt64Array(bytearr.buffer, 0, bytearr.length / 8));
45311
+ }
45312
+ return value;
45313
+ }
45314
+ };
45315
+ __publicField(SingleStoreBigIntVector, _a433, "SingleStoreBigIntVector");
45205
45316
  }
45206
45317
  });
45207
45318
 
@@ -45209,13 +45320,13 @@ var init_vector4 = __esm({
45209
45320
  function year2(name2) {
45210
45321
  return new SingleStoreYearBuilder(name2 ?? "");
45211
45322
  }
45212
- var _a432, _b326, SingleStoreYearBuilder, _a433, _b327, SingleStoreYear;
45323
+ var _a434, _b328, SingleStoreYearBuilder, _a435, _b329, SingleStoreYear;
45213
45324
  var init_year2 = __esm({
45214
45325
  "../drizzle-orm/dist/singlestore-core/columns/year.js"() {
45215
45326
  "use strict";
45216
45327
  init_entity();
45217
45328
  init_common5();
45218
- SingleStoreYearBuilder = class extends (_b326 = SingleStoreColumnBuilder, _a432 = entityKind, _b326) {
45329
+ SingleStoreYearBuilder = class extends (_b328 = SingleStoreColumnBuilder, _a434 = entityKind, _b328) {
45219
45330
  constructor(name2) {
45220
45331
  super(name2, "number year", "SingleStoreYear");
45221
45332
  }
@@ -45227,13 +45338,17 @@ var init_year2 = __esm({
45227
45338
  );
45228
45339
  }
45229
45340
  };
45230
- __publicField(SingleStoreYearBuilder, _a432, "SingleStoreYearBuilder");
45231
- SingleStoreYear = class extends (_b327 = SingleStoreColumn, _a433 = entityKind, _b327) {
45341
+ __publicField(SingleStoreYearBuilder, _a434, "SingleStoreYearBuilder");
45342
+ SingleStoreYear = class extends (_b329 = SingleStoreColumn, _a435 = entityKind, _b329) {
45232
45343
  getSQLType() {
45233
45344
  return `year`;
45234
45345
  }
45346
+ mapFromDriverValue(value) {
45347
+ if (typeof value !== "number") return Number(value);
45348
+ return value;
45349
+ }
45235
45350
  };
45236
- __publicField(SingleStoreYear, _a433, "SingleStoreYear");
45351
+ __publicField(SingleStoreYear, _a435, "SingleStoreYear");
45237
45352
  }
45238
45353
  });
45239
45354
 
@@ -45271,17 +45386,17 @@ var init_columns4 = __esm({
45271
45386
  });
45272
45387
 
45273
45388
  // ../drizzle-orm/dist/singlestore-core/query-builders/count.js
45274
- var _a434, _b328, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
45389
+ var _a436, _b330, _c12, _SingleStoreCountBuilder, SingleStoreCountBuilder;
45275
45390
  var init_count4 = __esm({
45276
45391
  "../drizzle-orm/dist/singlestore-core/query-builders/count.js"() {
45277
45392
  "use strict";
45278
45393
  init_entity();
45279
45394
  init_sql();
45280
- _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b328 = entityKind, _a434 = Symbol.toStringTag, _c12) {
45395
+ _SingleStoreCountBuilder = class _SingleStoreCountBuilder extends (_c12 = SQL, _b330 = entityKind, _a436 = Symbol.toStringTag, _c12) {
45281
45396
  constructor(params) {
45282
45397
  super(_SingleStoreCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
45283
45398
  __publicField(this, "sql");
45284
- __publicField(this, _a434, "SingleStoreCountBuilder");
45399
+ __publicField(this, _a436, "SingleStoreCountBuilder");
45285
45400
  __publicField(this, "session");
45286
45401
  this.params = params;
45287
45402
  this.mapWith(Number);
@@ -45319,18 +45434,18 @@ var init_count4 = __esm({
45319
45434
  );
45320
45435
  }
45321
45436
  };
45322
- __publicField(_SingleStoreCountBuilder, _b328, "SingleStoreCountBuilder");
45437
+ __publicField(_SingleStoreCountBuilder, _b330, "SingleStoreCountBuilder");
45323
45438
  SingleStoreCountBuilder = _SingleStoreCountBuilder;
45324
45439
  }
45325
45440
  });
45326
45441
 
45327
45442
  // ../drizzle-orm/dist/singlestore-core/indexes.js
45328
- var _a435, IndexBuilderOn4, _a436, IndexBuilder4, _a437, Index6;
45443
+ var _a437, IndexBuilderOn4, _a438, IndexBuilder4, _a439, Index6;
45329
45444
  var init_indexes4 = __esm({
45330
45445
  "../drizzle-orm/dist/singlestore-core/indexes.js"() {
45331
45446
  "use strict";
45332
45447
  init_entity();
45333
- _a435 = entityKind;
45448
+ _a437 = entityKind;
45334
45449
  IndexBuilderOn4 = class {
45335
45450
  constructor(name2, unique) {
45336
45451
  this.name = name2;
@@ -45340,8 +45455,8 @@ var init_indexes4 = __esm({
45340
45455
  return new IndexBuilder4(this.name, columns, this.unique);
45341
45456
  }
45342
45457
  };
45343
- __publicField(IndexBuilderOn4, _a435, "SingleStoreIndexBuilderOn");
45344
- _a436 = entityKind;
45458
+ __publicField(IndexBuilderOn4, _a437, "SingleStoreIndexBuilderOn");
45459
+ _a438 = entityKind;
45345
45460
  IndexBuilder4 = class {
45346
45461
  constructor(name2, columns, unique) {
45347
45462
  /** @internal */
@@ -45369,15 +45484,15 @@ var init_indexes4 = __esm({
45369
45484
  return new Index6(this.config, table6);
45370
45485
  }
45371
45486
  };
45372
- __publicField(IndexBuilder4, _a436, "SingleStoreIndexBuilder");
45373
- _a437 = entityKind;
45487
+ __publicField(IndexBuilder4, _a438, "SingleStoreIndexBuilder");
45488
+ _a439 = entityKind;
45374
45489
  Index6 = class {
45375
45490
  constructor(config, table6) {
45376
45491
  __publicField(this, "config");
45377
45492
  this.config = { ...config, table: table6 };
45378
45493
  }
45379
45494
  };
45380
- __publicField(Index6, _a437, "SingleStoreIndex");
45495
+ __publicField(Index6, _a439, "SingleStoreIndex");
45381
45496
  }
45382
45497
  });
45383
45498
 
@@ -45465,20 +45580,20 @@ function singlestoreTableWithSchema(name2, columns, extraConfig, schema5, baseNa
45465
45580
  }
45466
45581
  return table6;
45467
45582
  }
45468
- var _a438, _b329, _c13, _d5, SingleStoreTable;
45583
+ var _a440, _b331, _c13, _d5, SingleStoreTable;
45469
45584
  var init_table5 = __esm({
45470
45585
  "../drizzle-orm/dist/singlestore-core/table.js"() {
45471
45586
  "use strict";
45472
45587
  init_entity();
45473
45588
  init_table();
45474
45589
  init_all4();
45475
- SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b329 = Table2.Symbol.Columns, _a438 = Table2.Symbol.ExtraConfigBuilder, _d5) {
45590
+ SingleStoreTable = class extends (_d5 = Table2, _c13 = entityKind, _b331 = Table2.Symbol.Columns, _a440 = Table2.Symbol.ExtraConfigBuilder, _d5) {
45476
45591
  constructor() {
45477
45592
  super(...arguments);
45478
45593
  /** @internal */
45479
- __publicField(this, _b329);
45594
+ __publicField(this, _b331);
45480
45595
  /** @internal */
45481
- __publicField(this, _a438);
45596
+ __publicField(this, _a440);
45482
45597
  }
45483
45598
  };
45484
45599
  __publicField(SingleStoreTable, _c13, "SingleStoreTable");
@@ -45488,13 +45603,13 @@ var init_table5 = __esm({
45488
45603
  });
45489
45604
 
45490
45605
  // ../drizzle-orm/dist/singlestore-core/primary-keys.js
45491
- var _a439, PrimaryKeyBuilder4, _a440, PrimaryKey4;
45606
+ var _a441, PrimaryKeyBuilder4, _a442, PrimaryKey4;
45492
45607
  var init_primary_keys4 = __esm({
45493
45608
  "../drizzle-orm/dist/singlestore-core/primary-keys.js"() {
45494
45609
  "use strict";
45495
45610
  init_entity();
45496
45611
  init_table5();
45497
- _a439 = entityKind;
45612
+ _a441 = entityKind;
45498
45613
  PrimaryKeyBuilder4 = class {
45499
45614
  constructor(columns, name2) {
45500
45615
  /** @internal */
@@ -45509,8 +45624,8 @@ var init_primary_keys4 = __esm({
45509
45624
  return new PrimaryKey4(table6, this.columns, this.name);
45510
45625
  }
45511
45626
  };
45512
- __publicField(PrimaryKeyBuilder4, _a439, "SingleStorePrimaryKeyBuilder");
45513
- _a440 = entityKind;
45627
+ __publicField(PrimaryKeyBuilder4, _a441, "SingleStorePrimaryKeyBuilder");
45628
+ _a442 = entityKind;
45514
45629
  PrimaryKey4 = class {
45515
45630
  constructor(table6, columns, name2) {
45516
45631
  __publicField(this, "columns");
@@ -45523,7 +45638,7 @@ var init_primary_keys4 = __esm({
45523
45638
  return this.name ?? `${this.table[SingleStoreTable.Symbol.Name]}_${this.columns.map((column6) => column6.name).join("_")}_pk`;
45524
45639
  }
45525
45640
  };
45526
- __publicField(PrimaryKey4, _a440, "SingleStorePrimaryKey");
45641
+ __publicField(PrimaryKey4, _a442, "SingleStorePrimaryKey");
45527
45642
  }
45528
45643
  });
45529
45644
 
@@ -45587,7 +45702,7 @@ var init_utils10 = __esm({
45587
45702
  });
45588
45703
 
45589
45704
  // ../drizzle-orm/dist/singlestore-core/query-builders/delete.js
45590
- var _a441, _b330, SingleStoreDeleteBase;
45705
+ var _a443, _b332, SingleStoreDeleteBase;
45591
45706
  var init_delete4 = __esm({
45592
45707
  "../drizzle-orm/dist/singlestore-core/query-builders/delete.js"() {
45593
45708
  "use strict";
@@ -45596,7 +45711,7 @@ var init_delete4 = __esm({
45596
45711
  init_selection_proxy();
45597
45712
  init_table();
45598
45713
  init_utils10();
45599
- SingleStoreDeleteBase = class extends (_b330 = QueryPromise, _a441 = entityKind, _b330) {
45714
+ SingleStoreDeleteBase = class extends (_b332 = QueryPromise, _a443 = entityKind, _b332) {
45600
45715
  constructor(table6, session, dialect6, withList) {
45601
45716
  super();
45602
45717
  __publicField(this, "config");
@@ -45693,12 +45808,12 @@ var init_delete4 = __esm({
45693
45808
  return this;
45694
45809
  }
45695
45810
  };
45696
- __publicField(SingleStoreDeleteBase, _a441, "SingleStoreDelete");
45811
+ __publicField(SingleStoreDeleteBase, _a443, "SingleStoreDelete");
45697
45812
  }
45698
45813
  });
45699
45814
 
45700
45815
  // ../drizzle-orm/dist/singlestore-core/query-builders/insert.js
45701
- var _a442, SingleStoreInsertBuilder, _a443, _b331, SingleStoreInsertBase;
45816
+ var _a444, SingleStoreInsertBuilder, _a445, _b333, SingleStoreInsertBase;
45702
45817
  var init_insert4 = __esm({
45703
45818
  "../drizzle-orm/dist/singlestore-core/query-builders/insert.js"() {
45704
45819
  "use strict";
@@ -45708,7 +45823,7 @@ var init_insert4 = __esm({
45708
45823
  init_table();
45709
45824
  init_utils2();
45710
45825
  init_utils10();
45711
- _a442 = entityKind;
45826
+ _a444 = entityKind;
45712
45827
  SingleStoreInsertBuilder = class {
45713
45828
  constructor(table6, session, dialect6) {
45714
45829
  __publicField(this, "shouldIgnore", false);
@@ -45737,8 +45852,8 @@ var init_insert4 = __esm({
45737
45852
  return new SingleStoreInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
45738
45853
  }
45739
45854
  };
45740
- __publicField(SingleStoreInsertBuilder, _a442, "SingleStoreInsertBuilder");
45741
- SingleStoreInsertBase = class extends (_b331 = QueryPromise, _a443 = entityKind, _b331) {
45855
+ __publicField(SingleStoreInsertBuilder, _a444, "SingleStoreInsertBuilder");
45856
+ SingleStoreInsertBase = class extends (_b333 = QueryPromise, _a445 = entityKind, _b333) {
45742
45857
  constructor(table6, values, ignore, session, dialect6) {
45743
45858
  super();
45744
45859
  __publicField(this, "config");
@@ -45823,12 +45938,12 @@ var init_insert4 = __esm({
45823
45938
  return this;
45824
45939
  }
45825
45940
  };
45826
- __publicField(SingleStoreInsertBase, _a443, "SingleStoreInsert");
45941
+ __publicField(SingleStoreInsertBase, _a445, "SingleStoreInsert");
45827
45942
  }
45828
45943
  });
45829
45944
 
45830
45945
  // ../drizzle-orm/dist/singlestore-core/dialect.js
45831
- var _a444, SingleStoreDialect;
45946
+ var _a446, SingleStoreDialect;
45832
45947
  var init_dialect4 = __esm({
45833
45948
  "../drizzle-orm/dist/singlestore-core/dialect.js"() {
45834
45949
  "use strict";
@@ -45838,6 +45953,7 @@ var init_dialect4 = __esm({
45838
45953
  init_column();
45839
45954
  init_entity();
45840
45955
  init_errors();
45956
+ init_relations();
45841
45957
  init_expressions();
45842
45958
  init_sql();
45843
45959
  init_subquery();
@@ -45846,11 +45962,62 @@ var init_dialect4 = __esm({
45846
45962
  init_view_common();
45847
45963
  init_common5();
45848
45964
  init_table5();
45849
- _a444 = entityKind;
45965
+ _a446 = entityKind;
45850
45966
  SingleStoreDialect = class {
45851
45967
  constructor(config) {
45852
45968
  /** @internal */
45853
45969
  __publicField(this, "casing");
45970
+ __publicField(this, "unwrapAllColumns", (table6, selection) => {
45971
+ return sql.join(
45972
+ Object.entries(table6[TableColumns]).map(([k, v]) => {
45973
+ selection.push({
45974
+ key: k,
45975
+ field: v
45976
+ });
45977
+ return this.buildRqbColumn(table6, v, k);
45978
+ }),
45979
+ sql`, `
45980
+ );
45981
+ });
45982
+ __publicField(this, "getSelectedTableColumns", (table6, columns) => {
45983
+ const selectedColumns = [];
45984
+ const columnContainer = table6[TableColumns];
45985
+ const entries = Object.entries(columns);
45986
+ let colSelectionMode;
45987
+ for (const [k, v] of entries) {
45988
+ if (v === void 0) continue;
45989
+ colSelectionMode = colSelectionMode || v;
45990
+ if (v) {
45991
+ const column6 = columnContainer[k];
45992
+ selectedColumns.push({
45993
+ column: column6,
45994
+ tsName: k
45995
+ });
45996
+ }
45997
+ }
45998
+ if (colSelectionMode === false) {
45999
+ for (const [k, v] of Object.entries(columnContainer)) {
46000
+ if (columns[k] === false) continue;
46001
+ selectedColumns.push({
46002
+ column: v,
46003
+ tsName: k
46004
+ });
46005
+ }
46006
+ }
46007
+ return selectedColumns;
46008
+ });
46009
+ __publicField(this, "buildColumns", (table6, selection, params) => params?.columns ? (() => {
46010
+ const columnIdentifiers = [];
46011
+ const selectedColumns = this.getSelectedTableColumns(table6, params.columns);
46012
+ for (const { column: column6, tsName } of selectedColumns) {
46013
+ columnIdentifiers.push(this.buildRqbColumn(table6, column6, tsName));
46014
+ selection.push({
46015
+ key: tsName,
46016
+ field: column6
46017
+ });
46018
+ }
46019
+ return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
46020
+ })() : this.unwrapAllColumns(table6, selection));
45854
46021
  this.casing = new CasingCache(config?.casing);
45855
46022
  }
45856
46023
  async migrate(migrations, session, config) {
@@ -46185,7 +46352,7 @@ var init_dialect4 = __esm({
46185
46352
  invokeSource
46186
46353
  });
46187
46354
  }
46188
- buildRelationalQuery({
46355
+ _buildRelationalQuery({
46189
46356
  fullSchema,
46190
46357
  schema: schema5,
46191
46358
  tableNamesMap,
@@ -46295,7 +46462,7 @@ var init_dialect4 = __esm({
46295
46462
  )
46296
46463
  )
46297
46464
  );
46298
- const builtRelation = this.buildRelationalQuery({
46465
+ const builtRelation = this._buildRelationalQuery({
46299
46466
  fullSchema,
46300
46467
  schema: schema5,
46301
46468
  tableNamesMap,
@@ -46410,8 +46577,140 @@ var init_dialect4 = __esm({
46410
46577
  selection
46411
46578
  };
46412
46579
  }
46580
+ nestedSelectionerror() {
46581
+ throw new DrizzleError({
46582
+ message: `Views with nested selections are not supported by the relational query builder`
46583
+ });
46584
+ }
46585
+ buildRqbColumn(table6, column6, key) {
46586
+ if (is(column6, Column2)) {
46587
+ const name2 = sql`${table6}.${sql.identifier(this.casing.getColumnCasing(column6))}`;
46588
+ switch (column6.columnType) {
46589
+ case "SingleStoreBinary":
46590
+ case "SingleStoreVarBinary":
46591
+ case "SingleStoreTime":
46592
+ case "SingleStoreDateTimeString":
46593
+ case "SingleStoreTimestampString":
46594
+ case "SingleStoreFloat":
46595
+ case "SingleStoreDecimal":
46596
+ case "SingleStoreDecimalNumber":
46597
+ case "SingleStoreDecimalBigInt":
46598
+ case "SingleStoreBigInt64":
46599
+ case "SingleStoreEnumColumn": {
46600
+ return sql`cast(${name2} as char) as ${sql.identifier(key)}`;
46601
+ }
46602
+ case "SingleStoreVector":
46603
+ case "SingleStoreBigIntVector": {
46604
+ return sql`hex(${name2} :> blob) as ${sql.identifier(key)}`;
46605
+ }
46606
+ case "SingleStoreCustomColumn": {
46607
+ return sql`${column6.jsonSelectIdentifier(name2, sql)} as ${sql.identifier(key)}`;
46608
+ }
46609
+ default: {
46610
+ return sql`${name2} as ${sql.identifier(key)}`;
46611
+ }
46612
+ }
46613
+ }
46614
+ return sql`${table6}.${is(column6, SQL.Aliased) ? sql.identifier(column6.fieldAlias) : isSQLWrapper(column6) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
46615
+ }
46616
+ buildRelationalQuery({
46617
+ schema: schema5,
46618
+ table: table6,
46619
+ tableConfig,
46620
+ queryConfig: config,
46621
+ relationWhere,
46622
+ mode,
46623
+ errorPath,
46624
+ depth,
46625
+ isNestedMany,
46626
+ throughJoin
46627
+ }) {
46628
+ const selection = [];
46629
+ const isSingle = mode === "first";
46630
+ const params = config === true ? void 0 : config;
46631
+ const currentPath = errorPath ?? "";
46632
+ const currentDepth = depth ?? 0;
46633
+ if (!currentDepth) table6 = aliasedTable(table6, `d${currentDepth}`);
46634
+ const limit = isSingle ? 1 : params?.limit;
46635
+ const offset = params?.offset;
46636
+ const columns = this.buildColumns(table6, selection, params);
46637
+ const where = params?.where && relationWhere ? and(
46638
+ relationsFilterToSQL(table6, params.where, tableConfig.relations, schema5, this.casing),
46639
+ relationWhere
46640
+ ) : params?.where ? relationsFilterToSQL(table6, params.where, tableConfig.relations, schema5, this.casing) : relationWhere;
46641
+ const order = params?.orderBy ? relationsOrderToSQL(table6, params.orderBy) : void 0;
46642
+ const extras = params?.extras ? relationExtrasToSQL(table6, params.extras) : void 0;
46643
+ if (extras) selection.push(...extras.selection);
46644
+ const selectionArr = columns ? [columns] : [];
46645
+ const joins = params ? (() => {
46646
+ const { with: joins2 } = params;
46647
+ if (!joins2) return;
46648
+ const withEntries = Object.entries(joins2).filter(([_2, v]) => v);
46649
+ if (!withEntries.length) return;
46650
+ return sql.join(
46651
+ withEntries.map(([k, join]) => {
46652
+ const relation = tableConfig.relations[k];
46653
+ const isSingle2 = is(relation, One);
46654
+ selectionArr.push(
46655
+ 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)}`
46656
+ );
46657
+ const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
46658
+ const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
46659
+ const { filter: filter2, joinCondition } = relationToSQL(
46660
+ this.casing,
46661
+ relation,
46662
+ table6,
46663
+ targetTable,
46664
+ throughTable
46665
+ );
46666
+ const throughJoin2 = throughTable ? sql` inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}` : void 0;
46667
+ const innerQuery = this.buildRelationalQuery({
46668
+ table: targetTable,
46669
+ mode: isSingle2 ? "first" : "many",
46670
+ schema: schema5,
46671
+ queryConfig: join,
46672
+ tableConfig: schema5[relation.targetTableName],
46673
+ relationWhere: filter2,
46674
+ errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
46675
+ depth: currentDepth + 1,
46676
+ isNestedMany: !isSingle2,
46677
+ throughJoin: throughJoin2
46678
+ });
46679
+ selection.push({
46680
+ field: targetTable,
46681
+ key: k,
46682
+ selection: innerQuery.selection,
46683
+ isArray: !isSingle2,
46684
+ isOptional: (relation.optional ?? false) || join !== true && !!join.where
46685
+ });
46686
+ const jsonColumns = sql.join(
46687
+ innerQuery.selection.map((s) => sql`${sql.raw(this.escapeString(s.key))}, ${sql.identifier(s.key)}`),
46688
+ sql`, `
46689
+ );
46690
+ 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`;
46691
+ return joinQuery;
46692
+ })
46693
+ );
46694
+ })() : void 0;
46695
+ if (extras?.sql) selectionArr.push(extras.sql);
46696
+ if (!selectionArr.length) {
46697
+ throw new DrizzleError({
46698
+ message: `No fields selected for table "${tableConfig.name}"${currentPath ? ` ("${currentPath}")` : ""}`
46699
+ });
46700
+ }
46701
+ if (isNestedMany && order) {
46702
+ selectionArr.push(sql`row_number() over (order by ${order}) as ${sql.identifier(`$drizzle_order_row_number`)}`);
46703
+ }
46704
+ const selectionSet = sql.join(selectionArr, sql`, `);
46705
+ 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)}`;
46706
+ return {
46707
+ sql: query,
46708
+ selection,
46709
+ order
46710
+ };
46711
+ }
46413
46712
  };
46414
- __publicField(SingleStoreDialect, _a444, "SingleStoreDialect");
46713
+ __publicField(SingleStoreDialect, _a446, "SingleStoreDialect");
46415
46714
  }
46416
46715
  });
46417
46716
 
@@ -46433,7 +46732,7 @@ function createSetOperator4(type, isAll) {
46433
46732
  return leftSelect.addSetOperators(setOperators);
46434
46733
  };
46435
46734
  }
46436
- var _a445, SingleStoreSelectBuilder, _a446, _b332, SingleStoreSelectQueryBuilderBase, _a447, _b333, SingleStoreSelectBase, getSingleStoreSetOperators, union5, unionAll4, intersect4, except4, minus;
46735
+ var _a447, SingleStoreSelectBuilder, _a448, _b334, SingleStoreSelectQueryBuilderBase, _a449, _b335, SingleStoreSelectBase, getSingleStoreSetOperators, union5, unionAll4, intersect4, except4, minus;
46437
46736
  var init_select5 = __esm({
46438
46737
  "../drizzle-orm/dist/singlestore-core/query-builders/select.js"() {
46439
46738
  "use strict";
@@ -46446,7 +46745,7 @@ var init_select5 = __esm({
46446
46745
  init_table();
46447
46746
  init_utils2();
46448
46747
  init_utils10();
46449
- _a445 = entityKind;
46748
+ _a447 = entityKind;
46450
46749
  SingleStoreSelectBuilder = class {
46451
46750
  constructor(config) {
46452
46751
  __publicField(this, "fields");
@@ -46489,8 +46788,8 @@ var init_select5 = __esm({
46489
46788
  );
46490
46789
  }
46491
46790
  };
46492
- __publicField(SingleStoreSelectBuilder, _a445, "SingleStoreSelectBuilder");
46493
- SingleStoreSelectQueryBuilderBase = class extends (_b332 = TypedQueryBuilder, _a446 = entityKind, _b332) {
46791
+ __publicField(SingleStoreSelectBuilder, _a447, "SingleStoreSelectBuilder");
46792
+ SingleStoreSelectQueryBuilderBase = class extends (_b334 = TypedQueryBuilder, _a448 = entityKind, _b334) {
46494
46793
  constructor({ table: table6, fields, isPartialSelect, session, dialect: dialect6, withList, distinct }) {
46495
46794
  super();
46496
46795
  __publicField(this, "_");
@@ -47111,8 +47410,8 @@ var init_select5 = __esm({
47111
47410
  return this;
47112
47411
  }
47113
47412
  };
47114
- __publicField(SingleStoreSelectQueryBuilderBase, _a446, "SingleStoreSelectQueryBuilder");
47115
- SingleStoreSelectBase = class extends (_b333 = SingleStoreSelectQueryBuilderBase, _a447 = entityKind, _b333) {
47413
+ __publicField(SingleStoreSelectQueryBuilderBase, _a448, "SingleStoreSelectQueryBuilder");
47414
+ SingleStoreSelectBase = class extends (_b335 = SingleStoreSelectQueryBuilderBase, _a449 = entityKind, _b335) {
47116
47415
  constructor() {
47117
47416
  super(...arguments);
47118
47417
  __publicField(this, "execute", (placeholderValues) => {
@@ -47143,7 +47442,7 @@ var init_select5 = __esm({
47143
47442
  return this;
47144
47443
  }
47145
47444
  };
47146
- __publicField(SingleStoreSelectBase, _a447, "SingleStoreSelect");
47445
+ __publicField(SingleStoreSelectBase, _a449, "SingleStoreSelect");
47147
47446
  applyMixins(SingleStoreSelectBase, [QueryPromise]);
47148
47447
  getSingleStoreSetOperators = () => ({
47149
47448
  union: union5,
@@ -47161,7 +47460,7 @@ var init_select5 = __esm({
47161
47460
  });
47162
47461
 
47163
47462
  // ../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js
47164
- var _a448, QueryBuilder4;
47463
+ var _a450, QueryBuilder4;
47165
47464
  var init_query_builder5 = __esm({
47166
47465
  "../drizzle-orm/dist/singlestore-core/query-builders/query-builder.js"() {
47167
47466
  "use strict";
@@ -47170,7 +47469,7 @@ var init_query_builder5 = __esm({
47170
47469
  init_dialect4();
47171
47470
  init_subquery();
47172
47471
  init_select5();
47173
- _a448 = entityKind;
47472
+ _a450 = entityKind;
47174
47473
  QueryBuilder4 = class {
47175
47474
  constructor(dialect6) {
47176
47475
  __publicField(this, "dialect");
@@ -47240,7 +47539,7 @@ var init_query_builder5 = __esm({
47240
47539
  return this.dialect;
47241
47540
  }
47242
47541
  };
47243
- __publicField(QueryBuilder4, _a448, "SingleStoreQueryBuilder");
47542
+ __publicField(QueryBuilder4, _a450, "SingleStoreQueryBuilder");
47244
47543
  }
47245
47544
  });
47246
47545
 
@@ -47252,7 +47551,7 @@ var init_select_types4 = __esm({
47252
47551
  });
47253
47552
 
47254
47553
  // ../drizzle-orm/dist/singlestore-core/query-builders/update.js
47255
- var _a449, SingleStoreUpdateBuilder, _a450, _b334, SingleStoreUpdateBase;
47554
+ var _a451, SingleStoreUpdateBuilder, _a452, _b336, SingleStoreUpdateBase;
47256
47555
  var init_update4 = __esm({
47257
47556
  "../drizzle-orm/dist/singlestore-core/query-builders/update.js"() {
47258
47557
  "use strict";
@@ -47262,7 +47561,7 @@ var init_update4 = __esm({
47262
47561
  init_table();
47263
47562
  init_utils2();
47264
47563
  init_utils10();
47265
- _a449 = entityKind;
47564
+ _a451 = entityKind;
47266
47565
  SingleStoreUpdateBuilder = class {
47267
47566
  constructor(table6, session, dialect6, withList) {
47268
47567
  this.table = table6;
@@ -47280,8 +47579,8 @@ var init_update4 = __esm({
47280
47579
  );
47281
47580
  }
47282
47581
  };
47283
- __publicField(SingleStoreUpdateBuilder, _a449, "SingleStoreUpdateBuilder");
47284
- SingleStoreUpdateBase = class extends (_b334 = QueryPromise, _a450 = entityKind, _b334) {
47582
+ __publicField(SingleStoreUpdateBuilder, _a451, "SingleStoreUpdateBuilder");
47583
+ SingleStoreUpdateBase = class extends (_b336 = QueryPromise, _a452 = entityKind, _b336) {
47285
47584
  constructor(table6, set, session, dialect6, withList) {
47286
47585
  super();
47287
47586
  __publicField(this, "config");
@@ -47381,7 +47680,7 @@ var init_update4 = __esm({
47381
47680
  return this;
47382
47681
  }
47383
47682
  };
47384
- __publicField(SingleStoreUpdateBase, _a450, "SingleStoreUpdate");
47683
+ __publicField(SingleStoreUpdateBase, _a452, "SingleStoreUpdate");
47385
47684
  }
47386
47685
  });
47387
47686
 
@@ -47398,8 +47697,103 @@ var init_query_builders4 = __esm({
47398
47697
  }
47399
47698
  });
47400
47699
 
47700
+ // ../drizzle-orm/dist/singlestore-core/query-builders/query.js
47701
+ var _a453, RelationalQueryBuilder4, _a454, _b337, SingleStoreRelationalQuery;
47702
+ var init_query7 = __esm({
47703
+ "../drizzle-orm/dist/singlestore-core/query-builders/query.js"() {
47704
+ "use strict";
47705
+ init_entity();
47706
+ init_query_promise();
47707
+ init_relations();
47708
+ _a453 = entityKind;
47709
+ RelationalQueryBuilder4 = class {
47710
+ constructor(schema5, table6, tableConfig, dialect6, session) {
47711
+ this.schema = schema5;
47712
+ this.table = table6;
47713
+ this.tableConfig = tableConfig;
47714
+ this.dialect = dialect6;
47715
+ this.session = session;
47716
+ }
47717
+ findMany(config) {
47718
+ return new SingleStoreRelationalQuery(
47719
+ this.schema,
47720
+ this.table,
47721
+ this.tableConfig,
47722
+ this.dialect,
47723
+ this.session,
47724
+ config ?? true,
47725
+ "many"
47726
+ );
47727
+ }
47728
+ findFirst(config) {
47729
+ return new SingleStoreRelationalQuery(
47730
+ this.schema,
47731
+ this.table,
47732
+ this.tableConfig,
47733
+ this.dialect,
47734
+ this.session,
47735
+ config ?? true,
47736
+ "first"
47737
+ );
47738
+ }
47739
+ };
47740
+ __publicField(RelationalQueryBuilder4, _a453, "SingleStoreRelationalQueryBuilderV2");
47741
+ SingleStoreRelationalQuery = class extends (_b337 = QueryPromise, _a454 = entityKind, _b337) {
47742
+ constructor(schema5, table6, tableConfig, dialect6, session, config, mode) {
47743
+ super();
47744
+ this.schema = schema5;
47745
+ this.table = table6;
47746
+ this.tableConfig = tableConfig;
47747
+ this.dialect = dialect6;
47748
+ this.session = session;
47749
+ this.config = config;
47750
+ this.mode = mode;
47751
+ }
47752
+ prepare() {
47753
+ const { query, builtQuery } = this._toSQL();
47754
+ return this.session.prepareRelationalQuery(
47755
+ builtQuery,
47756
+ void 0,
47757
+ (rawRows) => {
47758
+ const rows = rawRows.map((row) => mapRelationalRow(row, query.selection, void 0, void 0, true));
47759
+ if (this.mode === "first") {
47760
+ return rows[0];
47761
+ }
47762
+ return rows;
47763
+ }
47764
+ );
47765
+ }
47766
+ _getQuery() {
47767
+ return this.dialect.buildRelationalQuery({
47768
+ schema: this.schema,
47769
+ table: this.table,
47770
+ tableConfig: this.tableConfig,
47771
+ queryConfig: this.config,
47772
+ mode: this.mode
47773
+ });
47774
+ }
47775
+ _toSQL() {
47776
+ const query = this._getQuery();
47777
+ const builtQuery = this.dialect.sqlToQuery(query.sql);
47778
+ return { builtQuery, query };
47779
+ }
47780
+ /** @internal */
47781
+ getSQL() {
47782
+ return this._getQuery().sql;
47783
+ }
47784
+ toSQL() {
47785
+ return this._toSQL().builtQuery;
47786
+ }
47787
+ execute() {
47788
+ return this.prepare().execute();
47789
+ }
47790
+ };
47791
+ __publicField(SingleStoreRelationalQuery, _a454, "SingleStoreRelationalQueryV2");
47792
+ }
47793
+ });
47794
+
47401
47795
  // ../drizzle-orm/dist/singlestore-core/db.js
47402
- var _a451, SingleStoreDatabase;
47796
+ var _a455, SingleStoreDatabase;
47403
47797
  var init_db4 = __esm({
47404
47798
  "../drizzle-orm/dist/singlestore-core/db.js"() {
47405
47799
  "use strict";
@@ -47409,11 +47803,11 @@ var init_db4 = __esm({
47409
47803
  init_subquery();
47410
47804
  init_count4();
47411
47805
  init_query_builders4();
47412
- _a451 = entityKind;
47806
+ init_query7();
47807
+ _a455 = entityKind;
47413
47808
  SingleStoreDatabase = class {
47414
- constructor(dialect6, session, schema5) {
47415
- // We are waiting for SingleStore support for `json_array` function
47416
- /**@inrernal */
47809
+ constructor(dialect6, session, relations, schema5) {
47810
+ // TO-DO: Figure out how to pass DrizzleTypeError without breaking withReplicas
47417
47811
  __publicField(this, "query");
47418
47812
  /**
47419
47813
  * Creates a subquery that defines a temporary named result set as a CTE.
@@ -47471,13 +47865,24 @@ var init_db4 = __esm({
47471
47865
  this._ = schema5 ? {
47472
47866
  schema: schema5.schema,
47473
47867
  fullSchema: schema5.fullSchema,
47474
- tableNamesMap: schema5.tableNamesMap
47868
+ tableNamesMap: schema5.tableNamesMap,
47869
+ relations
47475
47870
  } : {
47476
47871
  schema: void 0,
47477
47872
  fullSchema: {},
47478
- tableNamesMap: {}
47873
+ tableNamesMap: {},
47874
+ relations
47479
47875
  };
47480
47876
  this.query = {};
47877
+ for (const [tableName, relation] of Object.entries(relations)) {
47878
+ this.query[tableName] = new RelationalQueryBuilder4(
47879
+ relations,
47880
+ relations[relation.name].table,
47881
+ relation,
47882
+ dialect6,
47883
+ session
47884
+ );
47885
+ }
47481
47886
  this.$cache = { invalidate: async (_params) => {
47482
47887
  } };
47483
47888
  }
@@ -47616,18 +48021,18 @@ var init_db4 = __esm({
47616
48021
  return this.session.transaction(transaction, config);
47617
48022
  }
47618
48023
  };
47619
- __publicField(SingleStoreDatabase, _a451, "SingleStoreDatabase");
48024
+ __publicField(SingleStoreDatabase, _a455, "SingleStoreDatabase");
47620
48025
  }
47621
48026
  });
47622
48027
 
47623
48028
  // ../drizzle-orm/dist/singlestore-core/schema.js
47624
- var _a452, SingleStoreSchema5;
48029
+ var _a456, SingleStoreSchema5;
47625
48030
  var init_schema3 = __esm({
47626
48031
  "../drizzle-orm/dist/singlestore-core/schema.js"() {
47627
48032
  "use strict";
47628
48033
  init_entity();
47629
48034
  init_table5();
47630
- _a452 = entityKind;
48035
+ _a456 = entityKind;
47631
48036
  SingleStoreSchema5 = class {
47632
48037
  constructor(schemaName) {
47633
48038
  __publicField(this, "table", (name2, columns, extraConfig) => {
@@ -47640,12 +48045,12 @@ var init_schema3 = __esm({
47640
48045
  return singlestoreViewWithSchema(name, columns, this.schemaName);
47641
48046
  }) as typeof singlestoreView; */
47642
48047
  };
47643
- __publicField(SingleStoreSchema5, _a452, "SingleStoreSchema");
48048
+ __publicField(SingleStoreSchema5, _a456, "SingleStoreSchema");
47644
48049
  }
47645
48050
  });
47646
48051
 
47647
48052
  // ../drizzle-orm/dist/singlestore-core/session.js
47648
- var _a453, SingleStorePreparedQuery, _a454, SingleStoreSession, _a455, _b335, SingleStoreTransaction;
48053
+ var _a457, SingleStorePreparedQuery, _a458, SingleStoreSession, _a459, _b338, SingleStoreTransaction;
47649
48054
  var init_session4 = __esm({
47650
48055
  "../drizzle-orm/dist/singlestore-core/session.js"() {
47651
48056
  "use strict";
@@ -47654,7 +48059,7 @@ var init_session4 = __esm({
47654
48059
  init_errors();
47655
48060
  init_sql();
47656
48061
  init_db4();
47657
- _a453 = entityKind;
48062
+ _a457 = entityKind;
47658
48063
  SingleStorePreparedQuery = class {
47659
48064
  constructor(cache, queryMetadata, cacheConfig) {
47660
48065
  /** @internal */
@@ -47736,8 +48141,8 @@ var init_session4 = __esm({
47736
48141
  }
47737
48142
  }
47738
48143
  };
47739
- __publicField(SingleStorePreparedQuery, _a453, "SingleStorePreparedQuery");
47740
- _a454 = entityKind;
48144
+ __publicField(SingleStorePreparedQuery, _a457, "SingleStorePreparedQuery");
48145
+ _a458 = entityKind;
47741
48146
  SingleStoreSession = class {
47742
48147
  constructor(dialect6) {
47743
48148
  this.dialect = dialect6;
@@ -47772,10 +48177,11 @@ var init_session4 = __esm({
47772
48177
  return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
47773
48178
  }
47774
48179
  };
47775
- __publicField(SingleStoreSession, _a454, "SingleStoreSession");
47776
- SingleStoreTransaction = class extends (_b335 = SingleStoreDatabase, _a455 = entityKind, _b335) {
47777
- constructor(dialect6, session, schema5, nestedIndex) {
47778
- super(dialect6, session, schema5);
48180
+ __publicField(SingleStoreSession, _a458, "SingleStoreSession");
48181
+ SingleStoreTransaction = class extends (_b338 = SingleStoreDatabase, _a459 = entityKind, _b338) {
48182
+ constructor(dialect6, session, relations, schema5, nestedIndex) {
48183
+ super(dialect6, session, relations, schema5);
48184
+ this.relations = relations;
47779
48185
  this.schema = schema5;
47780
48186
  this.nestedIndex = nestedIndex;
47781
48187
  }
@@ -47783,7 +48189,7 @@ var init_session4 = __esm({
47783
48189
  throw new TransactionRollbackError();
47784
48190
  }
47785
48191
  };
47786
- __publicField(SingleStoreTransaction, _a455, "SingleStoreTransaction");
48192
+ __publicField(SingleStoreTransaction, _a459, "SingleStoreTransaction");
47787
48193
  }
47788
48194
  });
47789
48195