pqb 0.56.5 → 0.56.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1512,6 +1512,8 @@ interface OperatorsJson extends Base<unknown> {
1512
1512
  * ```ts
1513
1513
  * await db.table.find(id).update({
1514
1514
  * data: (q) => q.get('data').jsonSet(['path', 'to', 'value'], 'new value'),
1515
+ * // supports sql for the value
1516
+ * data: (q) => q.get('data').jsonSet(['path', 'to', 'value'], sql`'new value'`),
1515
1517
  * });
1516
1518
  * ```
1517
1519
  *
@@ -1530,6 +1532,9 @@ interface OperatorsJson extends Base<unknown> {
1530
1532
  * await db.table.find(id).update({
1531
1533
  * // data.path.to.value will be updated only if it already was defined
1532
1534
  * data: (q) => q.get('data').jsonReplace(['path', 'to', 'value'], 'new value'),
1535
+ * // supports sql for the value
1536
+ * data: (q) =>
1537
+ * q.get('data').jsonReplace(['path', 'to', 'value'], sql`'new value'`),
1533
1538
  * });
1534
1539
  * ```
1535
1540
  *
@@ -1556,6 +1561,8 @@ interface OperatorsJson extends Base<unknown> {
1556
1561
  * // update the record with data { tags: ['two'] } to have data { tags: ['one', 'two'] }
1557
1562
  * await db.table.find(id).update({
1558
1563
  * data: (q) => q.get('data').jsonInsert(['tags', 0], 'one'),
1564
+ * // supports sql for the value
1565
+ * data: (q) => q.get('data').jsonInsert(['tags', 0], sql`'one'`),
1559
1566
  * });
1560
1567
  *
1561
1568
  * // add 'three' after 'two'
@@ -2656,7 +2663,6 @@ declare namespace TableData {
2656
2663
  }
2657
2664
  export interface ColumnIndex {
2658
2665
  options: Index.ColumnArg & Index.Options;
2659
- name?: string;
2660
2666
  }
2661
2667
  export interface ColumnExclude extends ColumnIndex {
2662
2668
  with: string;
@@ -2664,12 +2670,10 @@ declare namespace TableData {
2664
2670
  export interface Index {
2665
2671
  columns: Index.ColumnOrExpressionOptions[];
2666
2672
  options: Index.Options;
2667
- name?: string;
2668
2673
  }
2669
2674
  export interface Exclude {
2670
2675
  columns: Exclude.ColumnOrExpressionOptions[];
2671
2676
  options: Exclude.Options;
2672
- name?: string;
2673
2677
  }
2674
2678
  export interface Constraint {
2675
2679
  name?: string;
@@ -2709,7 +2713,8 @@ declare namespace TableData {
2709
2713
  order?: string;
2710
2714
  weight?: SearchWeight;
2711
2715
  }
2712
- export interface UniqueOptionsArg {
2716
+ export interface UniqueOptionsArg<Name extends string = string> {
2717
+ name?: Name;
2713
2718
  nullsNotDistinct?: boolean;
2714
2719
  using?: string;
2715
2720
  include?: MaybeArray<string>;
@@ -2724,7 +2729,7 @@ declare namespace TableData {
2724
2729
  export interface TsVectorArg extends OptionsArg, TsVectorOptions {
2725
2730
  }
2726
2731
  export type Options = TsVectorArg;
2727
- export interface UniqueColumnArg extends ColumnOptions, UniqueOptionsArg {
2732
+ export interface UniqueColumnArg<Name extends string = string> extends ColumnOptions, UniqueOptionsArg<Name> {
2728
2733
  expression?: string;
2729
2734
  }
2730
2735
  export interface ColumnArg extends UniqueColumnArg {
@@ -2748,6 +2753,7 @@ declare namespace TableData {
2748
2753
  }
2749
2754
  export namespace Exclude {
2750
2755
  export interface Options {
2756
+ name?: string;
2751
2757
  using?: string;
2752
2758
  include?: MaybeArray<string>;
2753
2759
  with?: string;
@@ -2829,15 +2835,15 @@ interface TableDataMethods<Key extends PropertyKey> {
2829
2835
  unique<Columns extends [
2830
2836
  Key | TableData.Index.ColumnOrExpressionOptions<Key>,
2831
2837
  ...(Key | TableData.Index.ColumnOrExpressionOptions<Key>)[]
2832
- ], Name extends string>(columns: Columns, ...args: [options?: TableData.Index.UniqueOptionsArg] | [name?: Name, options?: TableData.Index.UniqueOptionsArg]): {
2838
+ ], Name extends string>(columns: Columns, options?: TableData.Index.UniqueOptionsArg<Name>): {
2833
2839
  tableDataItem: true;
2834
2840
  columns: Columns extends (Key | TableData.Index.ColumnOptionsForColumn<Key>)[] ? {
2835
2841
  [I in keyof Columns]: 'column' extends keyof Columns[I] ? Columns[I]['column'] : Columns[I];
2836
2842
  } : never;
2837
2843
  name: string extends Name ? never : Name;
2838
2844
  };
2839
- index(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], ...args: [options?: TableData.Index.OptionsArg] | [name?: string, options?: TableData.Index.OptionsArg]): NonUniqDataItem;
2840
- searchIndex(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], ...args: [options?: TableData.Index.TsVectorArg] | [name?: string, options?: TableData.Index.TsVectorArg]): NonUniqDataItem;
2845
+ index(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], options?: TableData.Index.OptionsArg): NonUniqDataItem;
2846
+ searchIndex(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], options?: TableData.Index.TsVectorArg): NonUniqDataItem;
2841
2847
  /**
2842
2848
  * Defines an `EXCLUDE` constraint for multiple columns.
2843
2849
  *
@@ -2907,7 +2913,7 @@ interface TableDataMethods<Key extends PropertyKey> {
2907
2913
  * });
2908
2914
  * ```
2909
2915
  */
2910
- exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<Key>[], ...args: [options?: TableData.Exclude.Options] | [name?: string, options?: TableData.Exclude.Options]): NonUniqDataItem;
2916
+ exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<Key>[], options?: TableData.Exclude.Options): NonUniqDataItem;
2911
2917
  foreignKey<ForeignTable extends (() => ForeignKeyTable) | string, ForeignColumns extends ForeignTable extends () => ForeignKeyTable ? [
2912
2918
  ColumnNameOfTable<ReturnType<ForeignTable>>,
2913
2919
  ...ColumnNameOfTable<ReturnType<ForeignTable>>[]
@@ -3565,7 +3571,9 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Que
3565
3571
  queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryArraysResult<R>>;
3566
3572
  }
3567
3573
  interface DbTableConstructor<ColumnTypes> {
3568
- <Table extends string, Shape extends QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>>;
3574
+ <Table extends string, Shape extends QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>> & {
3575
+ ko: Shape;
3576
+ };
3569
3577
  }
3570
3578
  type MapTableScopesOption<T> = T extends {
3571
3579
  scopes: RecordUnknown;
@@ -8270,9 +8278,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
8270
8278
  * // options are described below:
8271
8279
  * name: t.text().index({ ...options }),
8272
8280
  * // with a database-level name:
8273
- * name: t.text().index('custom_index_name'),
8274
- * // with name and options:
8275
- * name: t.text().index('custom_index_name', { ...options }),
8281
+ * name: t.text().index({ name: 'custom_index_name', ...indexOptions }),
8276
8282
  * }));
8277
8283
  * });
8278
8284
  * ```
@@ -8281,6 +8287,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
8281
8287
  *
8282
8288
  * ```ts
8283
8289
  * type IndexOptions = {
8290
+ * name?: string,
8284
8291
  * // NULLS NOT DISTINCT: availabe in Postgres 15+, makes sense only for unique index
8285
8292
  * nullsNotDistinct?: true;
8286
8293
  * // index algorithm to use such as GIST, GIN
@@ -8306,7 +8313,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
8306
8313
  *
8307
8314
  * @param args
8308
8315
  */
8309
- index<T extends PickColumnData>(this: T, ...args: [options?: TableData.Index.ColumnArg] | [name: string, options?: TableData.Index.ColumnArg]): T;
8316
+ index<T extends PickColumnData>(this: T, ...args: [options?: TableData.Index.ColumnArg]): T;
8310
8317
  /**
8311
8318
  * `searchIndex` is designed for [full text search](/guide/text-search).
8312
8319
  *
@@ -8412,8 +8419,8 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
8412
8419
  searchIndex<T extends {
8413
8420
  data: ColumnType['data'];
8414
8421
  dataType: string;
8415
- }>(this: T, ...args: [options?: TableData.Index.TsVectorColumnArg] | [name: string, options?: TableData.Index.TsVectorColumnArg]): T;
8416
- unique<T extends PickColumnData, Name extends string>(this: T, ...args: [options?: TableData.Index.UniqueColumnArg] | [name: Name, options?: TableData.Index.UniqueColumnArg]): UniqueColumn<T, Name>;
8422
+ }>(this: T, ...args: [options?: TableData.Index.TsVectorColumnArg]): T;
8423
+ unique<T extends PickColumnData, const Options extends TableData.Index.ColumnArg>(this: T, ...args: [options?: Options]): UniqueColumn<T, Options['name'] & string>;
8417
8424
  /**
8418
8425
  * Add [EXCLUDE constraint](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE) to the column.
8419
8426
  *
@@ -8459,7 +8466,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
8459
8466
  * }
8460
8467
  * ```
8461
8468
  */
8462
- exclude<T extends PickColumnData>(this: T, ...args: [op: string, options?: TableData.Exclude.ColumnArg] | [op: string, name: string, options?: TableData.Exclude.ColumnArg]): T;
8469
+ exclude<T extends PickColumnData>(this: T, op: string, ...args: [options?: TableData.Exclude.ColumnArg]): T;
8463
8470
  comment<T extends PickColumnData>(this: T, comment: string): T;
8464
8471
  compression<T extends PickColumnData>(this: T, compression: string): T;
8465
8472
  collate<T extends PickColumnData>(this: T, collate: string): T;
package/dist/index.js CHANGED
@@ -169,9 +169,7 @@ class ColumnType extends orchidCore.ColumnTypeBase {
169
169
  * // options are described below:
170
170
  * name: t.text().index({ ...options }),
171
171
  * // with a database-level name:
172
- * name: t.text().index('custom_index_name'),
173
- * // with name and options:
174
- * name: t.text().index('custom_index_name', { ...options }),
172
+ * name: t.text().index({ name: 'custom_index_name', ...indexOptions }),
175
173
  * }));
176
174
  * });
177
175
  * ```
@@ -180,6 +178,7 @@ class ColumnType extends orchidCore.ColumnTypeBase {
180
178
  *
181
179
  * ```ts
182
180
  * type IndexOptions = {
181
+ * name?: string,
183
182
  * // NULLS NOT DISTINCT: availabe in Postgres 15+, makes sense only for unique index
184
183
  * nullsNotDistinct?: true;
185
184
  * // index algorithm to use such as GIST, GIN
@@ -206,9 +205,9 @@ class ColumnType extends orchidCore.ColumnTypeBase {
206
205
  * @param args
207
206
  */
208
207
  index(...args) {
208
+ const a = args;
209
209
  return orchidCore.pushColumnData(this, "indexes", {
210
- options: (typeof args[0] === "string" ? args[1] : args[0]) ?? orchidCore.emptyObject,
211
- name: typeof args[0] === "string" ? args[0] : void 0
210
+ options: (typeof a[0] === "string" ? { ...a[1], name: a[0] } : a[0]) ?? orchidCore.emptyObject
212
211
  });
213
212
  }
214
213
  /**
@@ -314,21 +313,21 @@ class ColumnType extends orchidCore.ColumnTypeBase {
314
313
  * @param options - index options
315
314
  */
316
315
  searchIndex(...args) {
316
+ const a = args;
317
317
  return orchidCore.pushColumnData(this, "indexes", {
318
318
  options: {
319
- ...typeof args[0] === "string" ? args[1] : args[0],
319
+ ...typeof a[0] === "string" ? { ...a[1], name: a[0] } : a[0],
320
320
  ...this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }
321
- },
322
- name: typeof args[0] === "string" ? args[0] : void 0
321
+ }
323
322
  });
324
323
  }
325
324
  unique(...args) {
325
+ const a = args;
326
326
  return orchidCore.pushColumnData(this, "indexes", {
327
327
  options: {
328
- ...typeof args[0] === "string" ? args[1] : args[0],
328
+ ...typeof a[0] === "string" ? { ...a[1], name: a[0] } : a[0],
329
329
  unique: true
330
- },
331
- name: typeof args[0] === "string" ? args[0] : void 0
330
+ }
332
331
  });
333
332
  }
334
333
  /**
@@ -376,11 +375,11 @@ class ColumnType extends orchidCore.ColumnTypeBase {
376
375
  * }
377
376
  * ```
378
377
  */
379
- exclude(...args) {
378
+ exclude(op, ...args) {
379
+ const a = args;
380
380
  return orchidCore.pushColumnData(this, "excludes", {
381
- with: args[0],
382
- options: (typeof args[1] === "string" ? args[2] : args[1]) ?? orchidCore.emptyObject,
383
- name: typeof args[1] === "string" ? args[1] : void 0
381
+ with: op,
382
+ options: (typeof a[0] === "string" ? { ...a[1], name: a[0] } : a[0]) ?? orchidCore.emptyObject
384
383
  });
385
384
  }
386
385
  comment(comment) {
@@ -541,6 +540,7 @@ const indexInnerToCode = (index, t) => {
541
540
  const columnOptions = ["collate", "opclass", "order", "weight"];
542
541
  const indexOptionsKeys = [
543
542
  index.options.tsVector ? "unique" : void 0,
543
+ "name",
544
544
  "using",
545
545
  "nullsNotDistinct",
546
546
  "include",
@@ -586,18 +586,12 @@ const indexInnerToCode = (index, t) => {
586
586
  objects.push("{", props, "},");
587
587
  }
588
588
  }
589
- code.push(["[", objects, hasOptions || index.name ? "]," : "]"]);
590
- if (index.name) {
591
- orchidCore.addCode(code, ` ${orchidCore.singleQuote(index.name)},`);
592
- }
589
+ code.push(["[", objects, hasOptions ? "]," : "]"]);
593
590
  } else {
594
591
  orchidCore.addCode(
595
592
  code,
596
593
  `[${index.columns.map((it) => orchidCore.singleQuote(it.column)).join(", ")}]`
597
594
  );
598
- if (index.name) {
599
- orchidCore.addCode(code, `, ${orchidCore.singleQuote(index.name)}`);
600
- }
601
595
  }
602
596
  if (hasOptions) {
603
597
  if (columnsMultiline) {
@@ -633,6 +627,7 @@ const excludeInnerToCode = (item, t) => {
633
627
  const code = [`${t}.exclude(`];
634
628
  const columnOptions = ["collate", "opclass", "order", "with"];
635
629
  const optionsKeys = [
630
+ "name",
636
631
  "using",
637
632
  "include",
638
633
  "with",
@@ -657,10 +652,7 @@ const excludeInnerToCode = (item, t) => {
657
652
  }
658
653
  objects.push("{", props, "},");
659
654
  }
660
- code.push(["[", objects, hasOptions || item.name ? "]," : "]"]);
661
- if (item.name) {
662
- orchidCore.addCode(code, ` ${orchidCore.singleQuote(item.name)},`);
663
- }
655
+ code.push(["[", objects, hasOptions ? "]," : "]"]);
664
656
  if (hasOptions) {
665
657
  code.push(["{"]);
666
658
  const options = [];
@@ -768,12 +760,10 @@ const foreignKeyArgumentToCode = ({
768
760
  };
769
761
  const columnIndexesToCode = (items) => {
770
762
  const code = [];
771
- for (const { options, name } of items) {
772
- orchidCore.addCode(
773
- code,
774
- `.${options.unique ? "unique" : "index"}(${name ? `${orchidCore.singleQuote(name)}` : ""}`
775
- );
763
+ for (const { options } of items) {
764
+ orchidCore.addCode(code, `.${options.unique ? "unique" : "index"}(`);
776
765
  const arr = [
766
+ options.name && `name: ${orchidCore.singleQuote(options.name)},`,
777
767
  options.collate && `collate: ${orchidCore.singleQuote(options.collate)},`,
778
768
  options.opclass && `opclass: ${orchidCore.singleQuote(options.opclass)},`,
779
769
  options.order && `order: ${orchidCore.singleQuote(options.order)},`,
@@ -785,7 +775,7 @@ const columnIndexesToCode = (items) => {
785
775
  options.where && `where: ${orchidCore.singleQuote(options.where)},`
786
776
  ].filter((x) => !!x);
787
777
  if (arr.length) {
788
- orchidCore.addCode(code, name ? `, {` : "{");
778
+ orchidCore.addCode(code, "{");
789
779
  orchidCore.addCode(code, arr);
790
780
  orchidCore.addCode(code, "}");
791
781
  }
@@ -795,13 +785,13 @@ const columnIndexesToCode = (items) => {
795
785
  };
796
786
  const columnExcludesToCode = (items) => {
797
787
  const code = [];
798
- for (const { options, name, with: w } of items) {
788
+ for (const { options, with: w } of items) {
799
789
  orchidCore.addCode(code, `.exclude('${w}'`);
800
790
  const arr = [
791
+ options.name && `name: ${orchidCore.singleQuote(options.name)},`,
801
792
  options.collate && `collate: ${orchidCore.singleQuote(options.collate)},`,
802
793
  options.opclass && `opclass: ${orchidCore.singleQuote(options.opclass)},`,
803
794
  options.order && `order: ${orchidCore.singleQuote(options.order)},`,
804
- name && `name: ${orchidCore.singleQuote(name)},`,
805
795
  options.using && `using: ${orchidCore.singleQuote(options.using)},`,
806
796
  options.include && `include: ${typeof options.include === "string" ? orchidCore.singleQuote(options.include) : `[${options.include.map(orchidCore.singleQuote).join(", ")}]`},`,
807
797
  options.with && `with: ${orchidCore.singleQuote(options.with)},`,
@@ -880,7 +870,9 @@ const columnCode = (type, ctx, key, code) => {
880
870
  }
881
871
  if (data.explicitSelect) orchidCore.addCode(code, ".select(false)");
882
872
  if (data.isNullable) orchidCore.addCode(code, ".nullable()");
883
- if (data.as) orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
873
+ if (data.as && !ctx.migration) {
874
+ orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
875
+ }
884
876
  if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
885
877
  orchidCore.addCode(
886
878
  code,
@@ -1189,6 +1181,17 @@ const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
1189
1181
  }
1190
1182
  return orchidCore.addValue(ctx.values, JSON.stringify(arg)) + "::jsonb";
1191
1183
  };
1184
+ const serializeJsonValue = (arg, ctx, quotedAs) => {
1185
+ if (arg && typeof arg === "object") {
1186
+ if (orchidCore.isExpression(arg)) {
1187
+ return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
1188
+ }
1189
+ if ("toSQL" in arg) {
1190
+ return `to_jsonb((${getSqlText(arg.toSQL(ctx))}))`;
1191
+ }
1192
+ }
1193
+ return orchidCore.addValue(ctx.values, JSON.stringify(arg));
1194
+ };
1192
1195
  const json = {
1193
1196
  equals: make(
1194
1197
  (key, value, ctx, quotedAs) => value === null ? `nullif(${key}, 'null'::jsonb) IS NULL` : `${key} = ${quoteJsonValue(value, ctx, quotedAs)}`
@@ -1231,21 +1234,24 @@ const json = {
1231
1234
  (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs)}`
1232
1235
  ),
1233
1236
  jsonSet: makeVarArg(
1234
- (key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${orchidCore.addValue(
1235
- ctx.values,
1236
- JSON.stringify(value)
1237
+ (key, [path, value], ctx, quotedAs) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${serializeJsonValue(
1238
+ value,
1239
+ ctx,
1240
+ quotedAs
1237
1241
  )})`
1238
1242
  ),
1239
1243
  jsonReplace: makeVarArg(
1240
- (key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${orchidCore.addValue(
1241
- ctx.values,
1242
- JSON.stringify(value)
1244
+ (key, [path, value], ctx, quotedAs) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${serializeJsonValue(
1245
+ value,
1246
+ ctx,
1247
+ quotedAs
1243
1248
  )}, false)`
1244
1249
  ),
1245
1250
  jsonInsert: makeVarArg(
1246
- (key, [path, value, options], ctx) => `jsonb_insert(${key}, ${encodeJsonPath(ctx, path)}, ${orchidCore.addValue(
1247
- ctx.values,
1248
- JSON.stringify(value)
1251
+ (key, [path, value, options], ctx, quotedAs) => `jsonb_insert(${key}, ${encodeJsonPath(ctx, path)}, ${serializeJsonValue(
1252
+ value,
1253
+ ctx,
1254
+ quotedAs
1249
1255
  )}${options?.after ? ", true" : ""})`
1250
1256
  ),
1251
1257
  jsonRemove: makeVarArg(
@@ -12819,9 +12825,9 @@ orchidCore.applyMixins(QueryMethods, [
12819
12825
 
12820
12826
  const makeIndex = (columns, first, second) => {
12821
12827
  if (typeof first === "string") {
12822
- const options = second ?? {};
12828
+ const options = { ...second, name: first };
12823
12829
  return {
12824
- index: { columns, options, name: first }
12830
+ index: { columns, options }
12825
12831
  };
12826
12832
  } else {
12827
12833
  const options = first ?? {};
@@ -12834,24 +12840,27 @@ const tableDataMethods = {
12834
12840
  primaryKey(columns, name) {
12835
12841
  return { primaryKey: { columns, name } };
12836
12842
  },
12837
- unique(columns, ...[first, second]) {
12843
+ unique(columns, ...args) {
12844
+ const [first, second] = args;
12838
12845
  const input = makeIndex(columns, first, second);
12839
12846
  input.index.options.unique = true;
12840
12847
  return input;
12841
12848
  },
12842
12849
  index: makeIndex,
12843
- searchIndex(columns, ...[first, second]) {
12850
+ searchIndex(columns, ...args) {
12844
12851
  var _a;
12852
+ const [first, second] = args;
12845
12853
  const input = makeIndex(columns, first, second);
12846
12854
  (_a = input.index.options).using ?? (_a.using = "gin");
12847
12855
  input.index.options.tsVector = true;
12848
12856
  return input;
12849
12857
  },
12850
- exclude(columns, ...[first, second]) {
12858
+ exclude(columns, ...args) {
12859
+ const [first, second] = args;
12851
12860
  if (typeof first === "string") {
12852
12861
  const options = second ?? {};
12853
12862
  return {
12854
- exclude: { columns, options, name: first }
12863
+ exclude: { columns, options: { ...options, name: first } }
12855
12864
  };
12856
12865
  } else {
12857
12866
  const options = first ?? {};