drizzle-orm 0.27.3-e080bed → 0.28.0-5dd9190

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 (120) hide show
  1. package/{alias-5aeeb2f5.cjs → alias-3f5ac719.cjs} +267 -142
  2. package/alias-3f5ac719.cjs.map +1 -0
  3. package/{alias-6eaa2e87.mjs → alias-7164ff43.mjs} +223 -126
  4. package/alias-7164ff43.mjs.map +1 -0
  5. package/aws-data-api/pg/index.cjs +1 -1
  6. package/aws-data-api/pg/index.d.ts +4 -4
  7. package/aws-data-api/pg/index.mjs +2 -2
  8. package/aws-data-api/pg/migrator.d.ts +4 -4
  9. package/better-sqlite3/index.cjs +2 -2
  10. package/better-sqlite3/index.d.ts +5 -5
  11. package/better-sqlite3/index.mjs +2 -2
  12. package/better-sqlite3/migrator.d.ts +5 -5
  13. package/bun-sqlite/index.cjs +2 -2
  14. package/bun-sqlite/index.d.ts +5 -5
  15. package/bun-sqlite/index.mjs +2 -2
  16. package/bun-sqlite/migrator.d.ts +5 -5
  17. package/column.d-9d2f4045.d.ts +1151 -0
  18. package/d1/index.cjs +2 -2
  19. package/d1/index.d.ts +5 -5
  20. package/d1/index.mjs +2 -2
  21. package/d1/migrator.d.ts +5 -5
  22. package/{driver.d-58d095ec.d.ts → driver.d-055d4782.d.ts} +2 -2
  23. package/{driver.d-d2f034d7.d.ts → driver.d-20707624.d.ts} +2 -2
  24. package/{driver.d-7f308b1e.d.ts → driver.d-ab0f126f.d.ts} +2 -2
  25. package/{driver.d-f55c470d.d.ts → driver.d-b8dd753f.d.ts} +2 -2
  26. package/{driver.d-28b0b849.d.ts → driver.d-c4dd56f7.d.ts} +2 -2
  27. package/{driver.d-53ed595e.d.ts → driver.d-eb654ed5.d.ts} +2 -2
  28. package/index.cjs +3 -3
  29. package/index.d.ts +4 -4
  30. package/index.mjs +2 -2
  31. package/knex/index.d.ts +1 -1
  32. package/kysely/index.d.ts +1 -1
  33. package/libsql/index.cjs +2 -2
  34. package/libsql/index.d.ts +5 -5
  35. package/libsql/index.mjs +2 -2
  36. package/libsql/migrator.d.ts +5 -5
  37. package/mysql-core/index.cjs +57 -21
  38. package/mysql-core/index.cjs.map +1 -1
  39. package/mysql-core/index.d.ts +184 -344
  40. package/mysql-core/index.mjs +58 -22
  41. package/mysql-core/index.mjs.map +1 -1
  42. package/mysql2/index.cjs +14 -10
  43. package/mysql2/index.cjs.map +1 -1
  44. package/mysql2/index.d.ts +16 -12
  45. package/mysql2/index.mjs +15 -11
  46. package/mysql2/index.mjs.map +1 -1
  47. package/mysql2/migrator.d.ts +4 -4
  48. package/neon-http/index.cjs +1 -1
  49. package/neon-http/index.d.ts +4 -4
  50. package/neon-http/index.mjs +2 -2
  51. package/neon-http/migrator.cjs +1 -1
  52. package/neon-http/migrator.d.ts +4 -4
  53. package/neon-http/migrator.mjs +1 -1
  54. package/neon-serverless/index.cjs +1 -1
  55. package/neon-serverless/index.d.ts +4 -4
  56. package/neon-serverless/index.mjs +2 -2
  57. package/neon-serverless/migrator.d.ts +4 -4
  58. package/node-postgres/index.cjs +1 -1
  59. package/node-postgres/index.d.ts +4 -4
  60. package/node-postgres/index.mjs +2 -2
  61. package/node-postgres/migrator.d.ts +4 -4
  62. package/package.json +3 -3
  63. package/pg-core/index.cjs +1 -1
  64. package/pg-core/index.cjs.map +1 -1
  65. package/pg-core/index.d.ts +207 -373
  66. package/pg-core/index.mjs +48 -18
  67. package/pg-core/index.mjs.map +1 -1
  68. package/planetscale-serverless/index.cjs +5 -5
  69. package/planetscale-serverless/index.cjs.map +1 -1
  70. package/planetscale-serverless/index.d.ts +5 -5
  71. package/planetscale-serverless/index.mjs +5 -5
  72. package/planetscale-serverless/index.mjs.map +1 -1
  73. package/planetscale-serverless/migrator.d.ts +4 -4
  74. package/postgres-js/index.cjs +1 -1
  75. package/postgres-js/index.d.ts +4 -4
  76. package/postgres-js/index.mjs +2 -2
  77. package/postgres-js/migrator.d.ts +4 -4
  78. package/{query-promise.d-fd15f63a.d.ts → query-promise.d-bc96befc.d.ts} +48 -45
  79. package/{db.d-2e828d8c.d.ts → select.types.d-570dd25a.d.ts} +281 -465
  80. package/{select.types.d-35b6e089.d.ts → select.types.d-73209a67.d.ts} +47 -258
  81. package/{select.types.d-1ea8ee3b.d.ts → select.types.d-a3c4c974.d.ts} +20 -19
  82. package/{db.d-9d586c00.d.ts → select.types.d-d0a10728.d.ts} +471 -731
  83. package/{session-c47f12d9.mjs → session-0c131cde.mjs} +2 -2
  84. package/{session-c47f12d9.mjs.map → session-0c131cde.mjs.map} +1 -1
  85. package/{session-2431f9e1.mjs → session-16f863cd.mjs} +36 -64
  86. package/session-16f863cd.mjs.map +1 -0
  87. package/{session-6bfef963.cjs → session-805d2876.cjs} +64 -131
  88. package/session-805d2876.cjs.map +1 -0
  89. package/{session-fa99bfce.mjs → session-ac71392b.mjs} +67 -134
  90. package/session-ac71392b.mjs.map +1 -0
  91. package/{session-fa9720a5.cjs → session-e9306785.cjs} +61 -71
  92. package/session-e9306785.cjs.map +1 -0
  93. package/sql-js/index.cjs +2 -2
  94. package/sql-js/index.d.ts +5 -5
  95. package/sql-js/index.mjs +2 -2
  96. package/sql-js/migrator.d.ts +5 -5
  97. package/sqlite-core/index.cjs +2 -2
  98. package/sqlite-core/index.d.ts +83 -137
  99. package/sqlite-core/index.mjs +28 -10
  100. package/sqlite-core/index.mjs.map +1 -1
  101. package/sqlite-proxy/index.cjs +2 -2
  102. package/sqlite-proxy/index.d.ts +6 -6
  103. package/sqlite-proxy/index.mjs +2 -2
  104. package/sqlite-proxy/migrator.cjs +1 -1
  105. package/sqlite-proxy/migrator.d.ts +5 -5
  106. package/sqlite-proxy/migrator.mjs +1 -1
  107. package/vercel-postgres/index.cjs +1 -1
  108. package/vercel-postgres/index.d.ts +4 -4
  109. package/vercel-postgres/index.mjs +2 -2
  110. package/vercel-postgres/migrator.d.ts +4 -4
  111. package/version.cjs +1 -1
  112. package/version.d.ts +1 -1
  113. package/version.mjs +1 -1
  114. package/alias-5aeeb2f5.cjs.map +0 -1
  115. package/alias-6eaa2e87.mjs.map +0 -1
  116. package/column.d-9d74a4f3.d.ts +0 -558
  117. package/session-2431f9e1.mjs.map +0 -1
  118. package/session-6bfef963.cjs.map +0 -1
  119. package/session-fa9720a5.cjs.map +0 -1
  120. package/session-fa99bfce.mjs.map +0 -1
@@ -34,6 +34,7 @@ var _a$V;
34
34
  class Column {
35
35
  constructor(table, config) {
36
36
  this.table = table;
37
+ this.enumValues = undefined;
37
38
  this.config = config;
38
39
  this.name = config.name;
39
40
  this.notNull = config.notNull;
@@ -43,6 +44,8 @@ class Column {
43
44
  this.isUnique = config.isUnique;
44
45
  this.uniqueName = config.uniqueName;
45
46
  this.uniqueType = config.uniqueType;
47
+ this.dataType = config.dataType;
48
+ this.columnType = config.columnType;
46
49
  }
47
50
  mapFromDriverValue(value) {
48
51
  return value;
@@ -81,6 +84,9 @@ class Table {
81
84
  this[Schema] = schema;
82
85
  this[BaseName] = baseName;
83
86
  }
87
+ getSQL() {
88
+ return new SQL([this]);
89
+ }
84
90
  }
85
91
  _a$U = entityKind, _b$K = IsAlias, _c$e = ExtraConfigBuilder, _d$7 = IsDrizzleTable;
86
92
  Table[_a$U] = 'Table';
@@ -183,6 +189,9 @@ class View {
183
189
  isAlias: false,
184
190
  };
185
191
  }
192
+ getSQL() {
193
+ return new SQL([this]);
194
+ }
186
195
  }
187
196
  _a$R = entityKind;
188
197
  View[_a$R] = 'View';
@@ -412,6 +421,9 @@ class Subquery {
412
421
  isWith,
413
422
  };
414
423
  }
424
+ getSQL() {
425
+ return new SQL([this]);
426
+ }
415
427
  }
416
428
  _a$M = entityKind;
417
429
  Subquery[_a$M] = 'Subquery';
@@ -991,12 +1003,9 @@ class PgDialect {
991
1003
  return sql `${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;
992
1004
  }
993
1005
  buildInsertQuery({ table, values, onConflict, returning }) {
994
- const isSingleValue = values.length === 1;
995
1006
  const valuesSqlList = [];
996
1007
  const columns = table[Table.Symbol.Columns];
997
- const colEntries = isSingleValue
998
- ? Object.keys(values[0]).map((fieldName) => [fieldName, columns[fieldName]])
999
- : Object.entries(columns);
1008
+ const colEntries = Object.entries(columns);
1000
1009
  const insertOrder = colEntries.map(([, column]) => sql.identifier(column.name));
1001
1010
  for (const [valueIndex, value] of values.entries()) {
1002
1011
  const valueList = [];
@@ -1555,10 +1564,10 @@ class PgDialect {
1555
1564
  }
1556
1565
  else {
1557
1566
  const aliasedColumns = Object.fromEntries(Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]));
1558
- const aliasedRelations = Object.fromEntries(Object.entries(tableConfig.relations).map(([key, value]) => [key, aliasedRelation(value, tableAlias)]));
1559
- const aliasedFields = Object.assign({}, aliasedColumns, aliasedRelations);
1560
1567
  if (config.where) {
1561
- const whereSql = typeof config.where === 'function' ? config.where(aliasedFields, operators) : config.where;
1568
+ const whereSql = typeof config.where === 'function'
1569
+ ? config.where(aliasedColumns, getOperators())
1570
+ : config.where;
1562
1571
  where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
1563
1572
  }
1564
1573
  const fieldsSelection = [];
@@ -1602,7 +1611,7 @@ class PgDialect {
1602
1611
  // Figure out which extras to select
1603
1612
  if (config.extras) {
1604
1613
  extras = typeof config.extras === 'function'
1605
- ? config.extras(aliasedFields, { sql })
1614
+ ? config.extras(aliasedColumns, { sql })
1606
1615
  : config.extras;
1607
1616
  for (const [tsKey, value] of Object.entries(extras)) {
1608
1617
  fieldsSelection.push({
@@ -1624,7 +1633,7 @@ class PgDialect {
1624
1633
  });
1625
1634
  }
1626
1635
  let orderByOrig = typeof config.orderBy === 'function'
1627
- ? config.orderBy(aliasedFields, orderByOperators)
1636
+ ? config.orderBy(aliasedColumns, getOrderByOperators())
1628
1637
  : config.orderBy ?? [];
1629
1638
  if (!Array.isArray(orderByOrig)) {
1630
1639
  orderByOrig = [orderByOrig];
@@ -1650,7 +1659,11 @@ class PgDialect {
1650
1659
  tableNamesMap,
1651
1660
  table: fullSchema[relationTableTsName],
1652
1661
  tableConfig: schema[relationTableTsName],
1653
- queryConfig: selectedRelationConfigValue,
1662
+ queryConfig: is(relation, One)
1663
+ ? (selectedRelationConfigValue === true
1664
+ ? { limit: 1 }
1665
+ : { ...selectedRelationConfigValue, limit: 1 })
1666
+ : selectedRelationConfigValue,
1654
1667
  tableAlias: relationTableAlias,
1655
1668
  joinOn,
1656
1669
  nestedQueryRelation: relation,
@@ -1677,7 +1690,6 @@ class PgDialect {
1677
1690
  throw new DrizzleError(`No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")`);
1678
1691
  }
1679
1692
  let result;
1680
- const needsSubquery = where || limit !== undefined || offset !== undefined || orderBy.length > 0;
1681
1693
  where = and(joinOn, where);
1682
1694
  if (nestedQueryRelation) {
1683
1695
  let field = sql `json_build_array(${sql.join(selection.map(({ field, tsKey, isJson }) => isJson
@@ -1697,6 +1709,7 @@ class PgDialect {
1697
1709
  relationTableTsKey: tableConfig.tsName,
1698
1710
  selection,
1699
1711
  }];
1712
+ const needsSubquery = limit !== undefined || offset !== undefined || orderBy.length > 0;
1700
1713
  if (needsSubquery) {
1701
1714
  result = this.buildSelectQuery({
1702
1715
  table: aliasedTable(table, tableAlias),
@@ -1733,57 +1746,19 @@ class PgDialect {
1733
1746
  });
1734
1747
  }
1735
1748
  else {
1736
- if (needsSubquery) {
1737
- const nestedSelection = selection.filter(({ field }) => !is(field, Column));
1738
- nestedSelection.splice(0, 0, {
1739
- dbKey: '*',
1740
- tsKey: '*',
1741
- field: sql `${sql.identifier(tableAlias)}.*`,
1742
- isJson: false,
1743
- relationTableTsKey: tableConfig.tsName,
1744
- selection: [],
1745
- });
1746
- result = this.buildSelectQuery({
1747
- table: aliasedTable(table, tableAlias),
1748
- fields: {},
1749
- fieldsFlat: nestedSelection.map(({ field }) => ({
1750
- path: [],
1751
- field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
1752
- })),
1753
- joins,
1754
- });
1755
- result = this.buildSelectQuery({
1756
- table: new Subquery(result, {}, tableAlias),
1757
- fields: {},
1758
- fieldsFlat: selection.map(({ field }) => ({
1759
- path: [],
1760
- field: is(field, Column)
1761
- ? sql `${sql.identifier(field.name)}`
1762
- : is(field, SQL.Aliased)
1763
- ? sql `${sql.identifier(field.fieldAlias)}`
1764
- : field,
1765
- })),
1766
- where,
1767
- limit,
1768
- offset,
1769
- orderBy,
1770
- });
1771
- }
1772
- else {
1773
- result = this.buildSelectQuery({
1774
- table: aliasedTable(table, tableAlias),
1775
- fields: {},
1776
- fieldsFlat: selection.map(({ field }) => ({
1777
- path: [],
1778
- field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
1779
- })),
1780
- joins,
1781
- where,
1782
- limit,
1783
- offset,
1784
- orderBy,
1785
- });
1786
- }
1749
+ result = this.buildSelectQuery({
1750
+ table: aliasedTable(table, tableAlias),
1751
+ fields: {},
1752
+ fieldsFlat: selection.map(({ field }) => ({
1753
+ path: [],
1754
+ field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,
1755
+ })),
1756
+ joins,
1757
+ where,
1758
+ limit,
1759
+ offset,
1760
+ orderBy,
1761
+ });
1787
1762
  }
1788
1763
  return {
1789
1764
  tableTsKey: tableConfig.tsName,
@@ -2634,12 +2609,18 @@ function makePgArray(array) {
2634
2609
  var _a$A;
2635
2610
  // To understand how to use `ColumnBuilder` and `AnyColumnBuilder`, see `Column` and `AnyColumn` documentation.
2636
2611
  class ColumnBuilder {
2637
- constructor(name) {
2612
+ constructor(name, dataType, columnType) {
2638
2613
  this.config = {
2639
2614
  name,
2640
2615
  notNull: false,
2641
2616
  default: undefined,
2617
+ hasDefault: false,
2642
2618
  primaryKey: false,
2619
+ isUnique: false,
2620
+ uniqueName: undefined,
2621
+ uniqueType: undefined,
2622
+ dataType,
2623
+ columnType,
2643
2624
  };
2644
2625
  }
2645
2626
  $type() {
@@ -2685,7 +2666,7 @@ class PgColumnBuilder extends ColumnBuilder {
2685
2666
  /** @internal */
2686
2667
  buildForeignKeys(column, table) {
2687
2668
  return this.foreignKeyConfigs.map(({ ref, actions }) => {
2688
- return ((ref, actions) => {
2669
+ return iife((ref, actions) => {
2689
2670
  const builder = new ForeignKeyBuilder(() => {
2690
2671
  const foreignColumn = ref();
2691
2672
  return { columns: [column], foreignColumns: [foreignColumn] };
@@ -2697,7 +2678,7 @@ class PgColumnBuilder extends ColumnBuilder {
2697
2678
  builder.onDelete(actions.onDelete);
2698
2679
  }
2699
2680
  return builder.build(table);
2700
- })(ref, actions);
2681
+ }, ref, actions);
2701
2682
  });
2702
2683
  }
2703
2684
  }
@@ -2719,7 +2700,7 @@ PgColumn[_b$w] = 'PgColumn';
2719
2700
  var _a$y, _b$v;
2720
2701
  class PgArrayBuilder extends PgColumnBuilder {
2721
2702
  constructor(name, baseBuilder, size) {
2722
- super(name);
2703
+ super(name, 'array', 'PgArray');
2723
2704
  this.config.baseBuilder = baseBuilder;
2724
2705
  this.config.size = size;
2725
2706
  }
@@ -2764,6 +2745,9 @@ PgArray[_b$v] = 'PgArray';
2764
2745
 
2765
2746
  var _a$x, _b$u, _c$7, _d$5;
2766
2747
  class PgBigInt53Builder extends PgColumnBuilder {
2748
+ constructor(name) {
2749
+ super(name, 'number', 'PgBigInt53');
2750
+ }
2767
2751
  /** @internal */
2768
2752
  build(table) {
2769
2753
  return new PgBigInt53(table, this.config);
@@ -2785,6 +2769,9 @@ class PgBigInt53 extends PgColumn {
2785
2769
  _b$u = entityKind;
2786
2770
  PgBigInt53[_b$u] = 'PgBigInt53';
2787
2771
  class PgBigInt64Builder extends PgColumnBuilder {
2772
+ constructor(name) {
2773
+ super(name, 'bigint', 'PgBigInt64');
2774
+ }
2788
2775
  /** @internal */
2789
2776
  build(table) {
2790
2777
  return new PgBigInt64(table, this.config);
@@ -2813,7 +2800,7 @@ function bigint(name, config) {
2813
2800
  var _a$w, _b$t, _c$6, _d$4;
2814
2801
  class PgBigSerial53Builder extends PgColumnBuilder {
2815
2802
  constructor(name) {
2816
- super(name);
2803
+ super(name, 'number', 'PgBigSerial53');
2817
2804
  this.config.hasDefault = true;
2818
2805
  this.config.notNull = true;
2819
2806
  }
@@ -2839,7 +2826,7 @@ _b$t = entityKind;
2839
2826
  PgBigSerial53[_b$t] = 'PgBigSerial53';
2840
2827
  class PgBigSerial64Builder extends PgColumnBuilder {
2841
2828
  constructor(name) {
2842
- super(name);
2829
+ super(name, 'bigint', 'PgBigSerial64');
2843
2830
  this.config.hasDefault = true;
2844
2831
  }
2845
2832
  /** @internal */
@@ -2869,6 +2856,9 @@ function bigserial(name, { mode }) {
2869
2856
 
2870
2857
  var _a$v, _b$s;
2871
2858
  class PgBooleanBuilder extends PgColumnBuilder {
2859
+ constructor(name) {
2860
+ super(name, 'boolean', 'PgBoolean');
2861
+ }
2872
2862
  /** @internal */
2873
2863
  build(table) {
2874
2864
  return new PgBoolean(table, this.config);
@@ -2890,9 +2880,9 @@ function boolean(name) {
2890
2880
  var _a$u, _b$r;
2891
2881
  class PgCharBuilder extends PgColumnBuilder {
2892
2882
  constructor(name, config) {
2893
- super(name);
2883
+ super(name, 'string', 'PgChar');
2894
2884
  this.config.length = config.length;
2895
- this.config.enumValues = (config.enum ?? []);
2885
+ this.config.enumValues = config.enum;
2896
2886
  }
2897
2887
  /** @internal */
2898
2888
  build(table) {
@@ -2919,6 +2909,9 @@ function char(name, config = {}) {
2919
2909
 
2920
2910
  var _a$t, _b$q;
2921
2911
  class PgCidrBuilder extends PgColumnBuilder {
2912
+ constructor(name) {
2913
+ super(name, 'string', 'PgCidr');
2914
+ }
2922
2915
  /** @internal */
2923
2916
  build(table) {
2924
2917
  return new PgCidr(table, this.config);
@@ -2940,7 +2933,7 @@ function cidr(name) {
2940
2933
  var _a$s, _b$p;
2941
2934
  class PgCustomColumnBuilder extends PgColumnBuilder {
2942
2935
  constructor(name, fieldConfig, customTypeParams) {
2943
- super(name);
2936
+ super(name, 'custom', 'PgCustomColumn');
2944
2937
  this.config.fieldConfig = fieldConfig;
2945
2938
  this.config.customTypeParams = customTypeParams;
2946
2939
  }
@@ -2990,6 +2983,9 @@ PgDateColumnBaseBuilder[_a$r] = 'PgDateColumnBaseBuilder';
2990
2983
 
2991
2984
  var _a$q, _b$o, _c$5, _d$3;
2992
2985
  class PgDateBuilder extends PgDateColumnBaseBuilder {
2986
+ constructor(name) {
2987
+ super(name, 'date', 'PgDate');
2988
+ }
2993
2989
  /** @internal */
2994
2990
  build(table) {
2995
2991
  return new PgDate(table, this.config);
@@ -3011,6 +3007,9 @@ class PgDate extends PgColumn {
3011
3007
  _b$o = entityKind;
3012
3008
  PgDate[_b$o] = 'PgDate';
3013
3009
  class PgDateStringBuilder extends PgDateColumnBaseBuilder {
3010
+ constructor(name) {
3011
+ super(name, 'string', 'PgDateString');
3012
+ }
3014
3013
  /** @internal */
3015
3014
  build(table) {
3016
3015
  return new PgDateString(table, this.config);
@@ -3034,6 +3033,9 @@ function date(name, config) {
3034
3033
 
3035
3034
  var _a$p, _b$n;
3036
3035
  class PgDoublePrecisionBuilder extends PgColumnBuilder {
3036
+ constructor(name) {
3037
+ super(name, 'number', 'PgDoublePrecision');
3038
+ }
3037
3039
  /** @internal */
3038
3040
  build(table) {
3039
3041
  return new PgDoublePrecision(table, this.config);
@@ -3061,11 +3063,11 @@ function doublePrecision(name) {
3061
3063
  var _a$o, _b$m;
3062
3064
  const isPgEnumSym = Symbol.for('drizzle:isPgEnum');
3063
3065
  function isPgEnum(obj) {
3064
- return !!obj && typeof obj === 'function' && isPgEnumSym in obj;
3066
+ return !!obj && typeof obj === 'function' && isPgEnumSym in obj && obj[isPgEnumSym] === true;
3065
3067
  }
3066
3068
  class PgEnumColumnBuilder extends PgColumnBuilder {
3067
3069
  constructor(name, enumInstance) {
3068
- super(name);
3070
+ super(name, 'string', 'PgEnumColumn');
3069
3071
  this.config.enum = enumInstance;
3070
3072
  }
3071
3073
  /** @internal */
@@ -3100,6 +3102,9 @@ function pgEnum(enumName, values) {
3100
3102
 
3101
3103
  var _a$n, _b$l;
3102
3104
  class PgInetBuilder extends PgColumnBuilder {
3105
+ constructor(name) {
3106
+ super(name, 'string', 'PgInet');
3107
+ }
3103
3108
  /** @internal */
3104
3109
  build(table) {
3105
3110
  return new PgInet(table, this.config);
@@ -3120,6 +3125,9 @@ function inet(name) {
3120
3125
 
3121
3126
  var _a$m, _b$k;
3122
3127
  class PgIntegerBuilder extends PgColumnBuilder {
3128
+ constructor(name) {
3129
+ super(name, 'number', 'PgInteger');
3130
+ }
3123
3131
  /** @internal */
3124
3132
  build(table) {
3125
3133
  return new PgInteger(table, this.config);
@@ -3147,7 +3155,7 @@ function integer(name) {
3147
3155
  var _a$l, _b$j;
3148
3156
  class PgIntervalBuilder extends PgColumnBuilder {
3149
3157
  constructor(name, intervalConfig) {
3150
- super(name);
3158
+ super(name, 'string', 'PgInterval');
3151
3159
  this.config.intervalConfig = intervalConfig;
3152
3160
  }
3153
3161
  /** @internal */
@@ -3177,6 +3185,9 @@ function interval(name, config = {}) {
3177
3185
 
3178
3186
  var _a$k, _b$i;
3179
3187
  class PgJsonBuilder extends PgColumnBuilder {
3188
+ constructor(name) {
3189
+ super(name, 'json', 'PgJson');
3190
+ }
3180
3191
  /** @internal */
3181
3192
  build(table) {
3182
3193
  return new PgJson(table, this.config);
@@ -3214,6 +3225,9 @@ function json(name) {
3214
3225
 
3215
3226
  var _a$j, _b$h;
3216
3227
  class PgJsonbBuilder extends PgColumnBuilder {
3228
+ constructor(name) {
3229
+ super(name, 'json', 'PgJsonb');
3230
+ }
3217
3231
  /** @internal */
3218
3232
  build(table) {
3219
3233
  return new PgJsonb(table, this.config);
@@ -3251,6 +3265,9 @@ function jsonb(name) {
3251
3265
 
3252
3266
  var _a$i, _b$g;
3253
3267
  class PgMacaddrBuilder extends PgColumnBuilder {
3268
+ constructor(name) {
3269
+ super(name, 'string', 'PgMacaddr');
3270
+ }
3254
3271
  /** @internal */
3255
3272
  build(table) {
3256
3273
  return new PgMacaddr(table, this.config);
@@ -3271,6 +3288,9 @@ function macaddr(name) {
3271
3288
 
3272
3289
  var _a$h, _b$f;
3273
3290
  class PgMacaddr8Builder extends PgColumnBuilder {
3291
+ constructor(name) {
3292
+ super(name, 'string', 'PgMacaddr8');
3293
+ }
3274
3294
  /** @internal */
3275
3295
  build(table) {
3276
3296
  return new PgMacaddr8(table, this.config);
@@ -3292,7 +3312,7 @@ function macaddr8(name) {
3292
3312
  var _a$g, _b$e;
3293
3313
  class PgNumericBuilder extends PgColumnBuilder {
3294
3314
  constructor(name, precision, scale) {
3295
- super(name);
3315
+ super(name, 'string', 'PgNumeric');
3296
3316
  this.config.precision = precision;
3297
3317
  this.config.scale = scale;
3298
3318
  }
@@ -3331,7 +3351,7 @@ const decimal = numeric;
3331
3351
  var _a$f, _b$d;
3332
3352
  class PgRealBuilder extends PgColumnBuilder {
3333
3353
  constructor(name, length) {
3334
- super(name);
3354
+ super(name, 'number', 'PgReal');
3335
3355
  this.config.length = length;
3336
3356
  }
3337
3357
  /** @internal */
@@ -3364,7 +3384,7 @@ function real(name) {
3364
3384
  var _a$e, _b$c;
3365
3385
  class PgSerialBuilder extends PgColumnBuilder {
3366
3386
  constructor(name) {
3367
- super(name);
3387
+ super(name, 'number', 'PgSerial');
3368
3388
  this.config.hasDefault = true;
3369
3389
  this.config.notNull = true;
3370
3390
  }
@@ -3388,6 +3408,9 @@ function serial(name) {
3388
3408
 
3389
3409
  var _a$d, _b$b;
3390
3410
  class PgSmallIntBuilder extends PgColumnBuilder {
3411
+ constructor(name) {
3412
+ super(name, 'number', 'PgSmallInt');
3413
+ }
3391
3414
  /** @internal */
3392
3415
  build(table) {
3393
3416
  return new PgSmallInt(table, this.config);
@@ -3418,7 +3441,7 @@ function smallint(name) {
3418
3441
  var _a$c, _b$a;
3419
3442
  class PgSmallSerialBuilder extends PgColumnBuilder {
3420
3443
  constructor(name) {
3421
- super(name);
3444
+ super(name, 'number', 'PgSmallSerial');
3422
3445
  this.config.hasDefault = true;
3423
3446
  this.config.notNull = true;
3424
3447
  }
@@ -3443,8 +3466,8 @@ function smallserial(name) {
3443
3466
  var _a$b, _b$9;
3444
3467
  class PgTextBuilder extends PgColumnBuilder {
3445
3468
  constructor(name, config) {
3446
- super(name);
3447
- this.config.enumValues = (config.enum ?? []);
3469
+ super(name, 'string', 'PgText');
3470
+ this.config.enumValues = config.enum;
3448
3471
  }
3449
3472
  /** @internal */
3450
3473
  build(table) {
@@ -3471,7 +3494,7 @@ function text(name, config = {}) {
3471
3494
  var _a$a, _b$8;
3472
3495
  class PgTimeBuilder extends PgDateColumnBaseBuilder {
3473
3496
  constructor(name, withTimezone, precision) {
3474
- super(name);
3497
+ super(name, 'string', 'PgTime');
3475
3498
  this.withTimezone = withTimezone;
3476
3499
  this.precision = precision;
3477
3500
  this.config.withTimezone = withTimezone;
@@ -3504,7 +3527,7 @@ function time(name, config = {}) {
3504
3527
  var _a$9, _b$7, _c$4, _d$2;
3505
3528
  class PgTimestampBuilder extends PgDateColumnBaseBuilder {
3506
3529
  constructor(name, withTimezone, precision) {
3507
- super(name);
3530
+ super(name, 'date', 'PgTimestamp');
3508
3531
  this.config.withTimezone = withTimezone;
3509
3532
  this.config.precision = precision;
3510
3533
  }
@@ -3536,7 +3559,7 @@ _b$7 = entityKind;
3536
3559
  PgTimestamp[_b$7] = 'PgTimestamp';
3537
3560
  class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {
3538
3561
  constructor(name, withTimezone, precision) {
3539
- super(name);
3562
+ super(name, 'string', 'PgTimestampString');
3540
3563
  this.config.withTimezone = withTimezone;
3541
3564
  this.config.precision = precision;
3542
3565
  }
@@ -3569,6 +3592,9 @@ function timestamp(name, config = {}) {
3569
3592
 
3570
3593
  var _a$8, _b$6;
3571
3594
  class PgUUIDBuilder extends PgColumnBuilder {
3595
+ constructor(name) {
3596
+ super(name, 'string', 'PgUUID');
3597
+ }
3572
3598
  /**
3573
3599
  * Adds `default gen_random_uuid()` to the column definition.
3574
3600
  */
@@ -3596,9 +3622,9 @@ function uuid(name) {
3596
3622
  var _a$7, _b$5;
3597
3623
  class PgVarcharBuilder extends PgColumnBuilder {
3598
3624
  constructor(name, config) {
3599
- super(name);
3625
+ super(name, 'string', 'PgVarchar');
3600
3626
  this.config.length = config.length;
3601
- this.config.enumValues = (config.enum ?? []);
3627
+ this.config.enumValues = config.enum;
3602
3628
  }
3603
3629
  /** @internal */
3604
3630
  build(table) {
@@ -3921,17 +3947,21 @@ class Many extends Relation {
3921
3947
  }
3922
3948
  _d$1 = entityKind;
3923
3949
  Many[_d$1] = 'Many';
3924
- const operators = {
3925
- sql,
3926
- eq,
3927
- and,
3928
- or,
3929
- };
3930
- const orderByOperators = {
3931
- sql,
3932
- asc,
3933
- desc,
3934
- };
3950
+ function getOperators() {
3951
+ return {
3952
+ sql,
3953
+ eq,
3954
+ and,
3955
+ or,
3956
+ };
3957
+ }
3958
+ function getOrderByOperators() {
3959
+ return {
3960
+ sql,
3961
+ asc,
3962
+ desc,
3963
+ };
3964
+ }
3935
3965
  function extractTablesRelationalConfig(schema, configHelpers) {
3936
3966
  if (Object.keys(schema).length === 1 && 'default' in schema && !is(schema['default'], Table)) {
3937
3967
  schema = schema['default'];
@@ -4017,8 +4047,8 @@ function normalizeRelation(schema, tableNamesMap, relation) {
4017
4047
  if (!referencedTableTsName) {
4018
4048
  throw new Error(`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`);
4019
4049
  }
4020
- const referencedTableFields = schema[referencedTableTsName];
4021
- if (!referencedTableFields) {
4050
+ const referencedTableConfig = schema[referencedTableTsName];
4051
+ if (!referencedTableConfig) {
4022
4052
  throw new Error(`Table "${referencedTableTsName}" not found in schema`);
4023
4053
  }
4024
4054
  const sourceTable = relation.sourceTable;
@@ -4027,7 +4057,7 @@ function normalizeRelation(schema, tableNamesMap, relation) {
4027
4057
  throw new Error(`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`);
4028
4058
  }
4029
4059
  const reverseRelations = [];
4030
- for (const referencedTableRelation of Object.values(referencedTableFields.relations)) {
4060
+ for (const referencedTableRelation of Object.values(referencedTableConfig.relations)) {
4031
4061
  if ((relation.relationName && relation !== referencedTableRelation
4032
4062
  && referencedTableRelation.relationName === relation.relationName)
4033
4063
  || (!relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable)) {
@@ -4091,31 +4121,57 @@ function bindIfParam(value, column) {
4091
4121
  }
4092
4122
  return value;
4093
4123
  }
4094
- function eq(left, right) {
4124
+ /**
4125
+ * Test that two values are equal.
4126
+ *
4127
+ * Remember that the SQL standard dictates that
4128
+ * two NULL values are not equal, so if you want to test
4129
+ * whether a value is null, you may want to use
4130
+ * `isNull` instead.
4131
+ *
4132
+ * ## Examples
4133
+ *
4134
+ * ```ts
4135
+ * // Select cars made by Ford
4136
+ * db.select().from(cars)
4137
+ * .where(eq(cars.make, 'Ford'))
4138
+ * ```
4139
+ *
4140
+ * @see isNull for a way to test equality to NULL.
4141
+ */
4142
+ const eq = (left, right) => {
4095
4143
  return sql `${left} = ${bindIfParam(right, left)}`;
4096
- }
4097
- function ne(left, right) {
4144
+ };
4145
+ /**
4146
+ * Test that two values are not equal.
4147
+ *
4148
+ * Remember that the SQL standard dictates that
4149
+ * two NULL values are not equal, so if you want to test
4150
+ * whether a value is not null, you may want to use
4151
+ * `isNotNull` instead.
4152
+ *
4153
+ * ## Examples
4154
+ *
4155
+ * ```ts
4156
+ * // Select cars not made by Ford
4157
+ * db.select().from(cars)
4158
+ * .where(ne(cars.make, 'Ford'))
4159
+ * ```
4160
+ *
4161
+ * @see isNotNull for a way to test whether a value is not null.
4162
+ */
4163
+ const ne = (left, right) => {
4098
4164
  return sql `${left} <> ${bindIfParam(right, left)}`;
4099
- }
4165
+ };
4100
4166
  function and(...unfilteredConditions) {
4101
4167
  const conditions = unfilteredConditions.filter((c) => c !== undefined);
4102
4168
  if (conditions.length === 0) {
4103
4169
  return undefined;
4104
4170
  }
4105
4171
  if (conditions.length === 1) {
4106
- return conditions[0];
4107
- }
4108
- const chunks = [sql.raw('(')];
4109
- for (const [index, condition] of conditions.entries()) {
4110
- if (index === 0) {
4111
- chunks.push(condition);
4112
- }
4113
- else {
4114
- chunks.push(sql ` and `, condition);
4115
- }
4172
+ return new SQL(conditions);
4116
4173
  }
4117
- chunks.push(sql `)`);
4118
- return sql.join(chunks);
4174
+ return new SQL([new StringChunk('('), sql.join(conditions, new StringChunk(' and ')), new StringChunk(')')]);
4119
4175
  }
4120
4176
  function or(...unfilteredConditions) {
4121
4177
  const conditions = unfilteredConditions.filter((c) => c !== undefined);
@@ -4123,19 +4179,9 @@ function or(...unfilteredConditions) {
4123
4179
  return undefined;
4124
4180
  }
4125
4181
  if (conditions.length === 1) {
4126
- return conditions[0];
4182
+ return new SQL(conditions);
4127
4183
  }
4128
- const chunks = [sql.raw('(')];
4129
- for (const [index, condition] of conditions.entries()) {
4130
- if (index === 0) {
4131
- chunks.push(condition);
4132
- }
4133
- else {
4134
- chunks.push(sql ` or `, condition);
4135
- }
4136
- }
4137
- chunks.push(sql `)`);
4138
- return sql.join(chunks);
4184
+ return new SQL([new StringChunk('('), sql.join(conditions, new StringChunk(' or ')), new StringChunk(')')]);
4139
4185
  }
4140
4186
  /**
4141
4187
  * Negate the meaning of an expression using the `not` keyword.
@@ -4151,18 +4197,76 @@ function or(...unfilteredConditions) {
4151
4197
  function not(condition) {
4152
4198
  return sql `not ${condition}`;
4153
4199
  }
4154
- function gt(left, right) {
4200
+ /**
4201
+ * Test that the first expression passed is greater than
4202
+ * the second expression.
4203
+ *
4204
+ * ## Examples
4205
+ *
4206
+ * ```ts
4207
+ * // Select cars made after 2000.
4208
+ * db.select().from(cars)
4209
+ * .where(gt(cars.year, 2000))
4210
+ * ```
4211
+ *
4212
+ * @see gte for greater-than-or-equal
4213
+ */
4214
+ const gt = (left, right) => {
4155
4215
  return sql `${left} > ${bindIfParam(right, left)}`;
4156
- }
4157
- function gte(left, right) {
4216
+ };
4217
+ /**
4218
+ * Test that the first expression passed is greater than
4219
+ * or equal to the second expression. Use `gt` to
4220
+ * test whether an expression is strictly greater
4221
+ * than another.
4222
+ *
4223
+ * ## Examples
4224
+ *
4225
+ * ```ts
4226
+ * // Select cars made on or after 2000.
4227
+ * db.select().from(cars)
4228
+ * .where(gte(cars.year, 2000))
4229
+ * ```
4230
+ *
4231
+ * @see gt for a strictly greater-than condition
4232
+ */
4233
+ const gte = (left, right) => {
4158
4234
  return sql `${left} >= ${bindIfParam(right, left)}`;
4159
- }
4160
- function lt(left, right) {
4235
+ };
4236
+ /**
4237
+ * Test that the first expression passed is less than
4238
+ * the second expression.
4239
+ *
4240
+ * ## Examples
4241
+ *
4242
+ * ```ts
4243
+ * // Select cars made before 2000.
4244
+ * db.select().from(cars)
4245
+ * .where(lt(cars.year, 2000))
4246
+ * ```
4247
+ *
4248
+ * @see lte for greater-than-or-equal
4249
+ */
4250
+ const lt = (left, right) => {
4161
4251
  return sql `${left} < ${bindIfParam(right, left)}`;
4162
- }
4163
- function lte(left, right) {
4252
+ };
4253
+ /**
4254
+ * Test that the first expression passed is less than
4255
+ * or equal to the second expression.
4256
+ *
4257
+ * ## Examples
4258
+ *
4259
+ * ```ts
4260
+ * // Select cars made before 2000.
4261
+ * db.select().from(cars)
4262
+ * .where(lte(cars.year, 2000))
4263
+ * ```
4264
+ *
4265
+ * @see lt for a strictly less-than condition
4266
+ */
4267
+ const lte = (left, right) => {
4164
4268
  return sql `${left} <= ${bindIfParam(right, left)}`;
4165
- }
4269
+ };
4166
4270
  function inArray(column, values) {
4167
4271
  if (Array.isArray(values)) {
4168
4272
  if (values.length === 0) {
@@ -4200,8 +4304,8 @@ function notInArray(column, values) {
4200
4304
  *
4201
4305
  * @see isNotNull for the inverse of this test
4202
4306
  */
4203
- function isNull(column) {
4204
- return sql `${column} is null`;
4307
+ function isNull(value) {
4308
+ return sql `${value} is null`;
4205
4309
  }
4206
4310
  /**
4207
4311
  * Test whether an expression is not NULL. By the SQL standard,
@@ -4219,8 +4323,8 @@ function isNull(column) {
4219
4323
  *
4220
4324
  * @see isNull for the inverse of this test
4221
4325
  */
4222
- function isNotNull(column) {
4223
- return sql `${column} is not null`;
4326
+ function isNotNull(value) {
4327
+ return sql `${value} is not null`;
4224
4328
  }
4225
4329
  /**
4226
4330
  * Test whether a subquery evaluates to have any rows.
@@ -4430,6 +4534,9 @@ class StringChunk {
4430
4534
  constructor(value) {
4431
4535
  this.value = Array.isArray(value) ? value : [value];
4432
4536
  }
4537
+ getSQL() {
4538
+ return new SQL([this]);
4539
+ }
4433
4540
  }
4434
4541
  _b$1 = entityKind;
4435
4542
  StringChunk[_b$1] = 'StringChunk';
@@ -4524,6 +4631,9 @@ class SQL {
4524
4631
  }
4525
4632
  return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
4526
4633
  }
4634
+ if (is(chunk, Placeholder)) {
4635
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
4636
+ }
4527
4637
  if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
4528
4638
  return { sql: escapeName(chunk.fieldAlias), params: [] };
4529
4639
  }
@@ -4538,6 +4648,8 @@ class SQL {
4538
4648
  new Name(chunk[SubqueryConfig].alias),
4539
4649
  ], config);
4540
4650
  }
4651
+ // if (is(chunk, Placeholder)) {
4652
+ // return {sql: escapeParam}
4541
4653
  if (isSQLWrapper(chunk)) {
4542
4654
  return this.buildQueryFromSourceParams([
4543
4655
  new StringChunk('('),
@@ -4605,6 +4717,9 @@ class Name {
4605
4717
  constructor(value) {
4606
4718
  this.value = value;
4607
4719
  }
4720
+ getSQL() {
4721
+ return new SQL([this]);
4722
+ }
4608
4723
  }
4609
4724
  _d = entityKind;
4610
4725
  Name[_d] = 'Name';
@@ -4639,6 +4754,9 @@ class Param {
4639
4754
  this.value = value;
4640
4755
  this.encoder = encoder;
4641
4756
  }
4757
+ getSQL() {
4758
+ return new SQL([this]);
4759
+ }
4642
4760
  }
4643
4761
  _e = entityKind;
4644
4762
  Param[_e] = 'Param';
@@ -4746,6 +4864,9 @@ class Placeholder {
4746
4864
  constructor(name) {
4747
4865
  this.name = name;
4748
4866
  }
4867
+ getSQL() {
4868
+ return new SQL([this]);
4869
+ }
4749
4870
  }
4750
4871
  _f = entityKind;
4751
4872
  Placeholder[_f] = 'Placeholder';
@@ -4763,6 +4884,10 @@ function fillPlaceholders(params, values) {
4763
4884
  return p;
4764
4885
  });
4765
4886
  }
4887
+ // Defined separately from the Column class to resolve circular dependency
4888
+ Column.prototype.getSQL = function () {
4889
+ return new SQL([this]);
4890
+ };
4766
4891
 
4767
4892
  var _a, _b, _c;
4768
4893
  class ColumnAliasProxyHandler {
@@ -5027,6 +5152,8 @@ exports.extractTablesRelationalConfig = extractTablesRelationalConfig;
5027
5152
  exports.fillPlaceholders = fillPlaceholders;
5028
5153
  exports.foreignKey = foreignKey;
5029
5154
  exports.getMaterializedViewConfig = getMaterializedViewConfig;
5155
+ exports.getOperators = getOperators;
5156
+ exports.getOrderByOperators = getOrderByOperators;
5030
5157
  exports.getTableColumns = getTableColumns;
5031
5158
  exports.getTableConfig = getTableConfig;
5032
5159
  exports.getTableLikeName = getTableLikeName;
@@ -5076,9 +5203,7 @@ exports.notIlike = notIlike;
5076
5203
  exports.notInArray = notInArray;
5077
5204
  exports.notLike = notLike;
5078
5205
  exports.numeric = numeric;
5079
- exports.operators = operators;
5080
5206
  exports.or = or;
5081
- exports.orderByOperators = orderByOperators;
5082
5207
  exports.orderSelectedFields = orderSelectedFields;
5083
5208
  exports.param = param;
5084
5209
  exports.parsePgArray = parsePgArray;
@@ -5109,4 +5234,4 @@ exports.uniqueIndex = uniqueIndex;
5109
5234
  exports.uniqueKeyName = uniqueKeyName;
5110
5235
  exports.uuid = uuid;
5111
5236
  exports.varchar = varchar;
5112
- //# sourceMappingURL=alias-5aeeb2f5.cjs.map
5237
+ //# sourceMappingURL=alias-3f5ac719.cjs.map