linkgress-orm 0.0.1

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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +196 -0
  3. package/dist/database/database-client.interface.d.ts +45 -0
  4. package/dist/database/database-client.interface.d.ts.map +1 -0
  5. package/dist/database/database-client.interface.js +20 -0
  6. package/dist/database/database-client.interface.js.map +1 -0
  7. package/dist/database/index.d.ts +5 -0
  8. package/dist/database/index.d.ts.map +1 -0
  9. package/dist/database/index.js +10 -0
  10. package/dist/database/index.js.map +1 -0
  11. package/dist/database/pg-client.d.ts +30 -0
  12. package/dist/database/pg-client.d.ts.map +1 -0
  13. package/dist/database/pg-client.js +76 -0
  14. package/dist/database/pg-client.js.map +1 -0
  15. package/dist/database/postgres-client.d.ts +44 -0
  16. package/dist/database/postgres-client.d.ts.map +1 -0
  17. package/dist/database/postgres-client.js +111 -0
  18. package/dist/database/postgres-client.js.map +1 -0
  19. package/dist/database/types.d.ts +200 -0
  20. package/dist/database/types.d.ts.map +1 -0
  21. package/dist/database/types.js +8 -0
  22. package/dist/database/types.js.map +1 -0
  23. package/dist/entity/base-entity.d.ts +21 -0
  24. package/dist/entity/base-entity.d.ts.map +1 -0
  25. package/dist/entity/base-entity.js +27 -0
  26. package/dist/entity/base-entity.js.map +1 -0
  27. package/dist/entity/db-column.d.ts +61 -0
  28. package/dist/entity/db-column.d.ts.map +1 -0
  29. package/dist/entity/db-column.js +35 -0
  30. package/dist/entity/db-column.js.map +1 -0
  31. package/dist/entity/db-context.d.ts +665 -0
  32. package/dist/entity/db-context.d.ts.map +1 -0
  33. package/dist/entity/db-context.js +1463 -0
  34. package/dist/entity/db-context.js.map +1 -0
  35. package/dist/entity/entity-base.d.ts +76 -0
  36. package/dist/entity/entity-base.d.ts.map +1 -0
  37. package/dist/entity/entity-base.js +42 -0
  38. package/dist/entity/entity-base.js.map +1 -0
  39. package/dist/entity/entity-builder.d.ts +171 -0
  40. package/dist/entity/entity-builder.d.ts.map +1 -0
  41. package/dist/entity/entity-builder.js +376 -0
  42. package/dist/entity/entity-builder.js.map +1 -0
  43. package/dist/entity/model-config.d.ts +18 -0
  44. package/dist/entity/model-config.d.ts.map +1 -0
  45. package/dist/entity/model-config.js +157 -0
  46. package/dist/entity/model-config.js.map +1 -0
  47. package/dist/index.d.ts +27 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +142 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/migration/db-schema-manager.d.ts +228 -0
  52. package/dist/migration/db-schema-manager.d.ts.map +1 -0
  53. package/dist/migration/db-schema-manager.js +1055 -0
  54. package/dist/migration/db-schema-manager.js.map +1 -0
  55. package/dist/migration/enum-migrator.d.ts +29 -0
  56. package/dist/migration/enum-migrator.d.ts.map +1 -0
  57. package/dist/migration/enum-migrator.js +137 -0
  58. package/dist/migration/enum-migrator.js.map +1 -0
  59. package/dist/query/collection-strategy.factory.d.ts +16 -0
  60. package/dist/query/collection-strategy.factory.d.ts.map +1 -0
  61. package/dist/query/collection-strategy.factory.js +37 -0
  62. package/dist/query/collection-strategy.factory.js.map +1 -0
  63. package/dist/query/collection-strategy.interface.d.ts +146 -0
  64. package/dist/query/collection-strategy.interface.d.ts.map +1 -0
  65. package/dist/query/collection-strategy.interface.js +3 -0
  66. package/dist/query/collection-strategy.interface.js.map +1 -0
  67. package/dist/query/conditions.d.ts +222 -0
  68. package/dist/query/conditions.d.ts.map +1 -0
  69. package/dist/query/conditions.js +446 -0
  70. package/dist/query/conditions.js.map +1 -0
  71. package/dist/query/cte-builder.d.ts +95 -0
  72. package/dist/query/cte-builder.d.ts.map +1 -0
  73. package/dist/query/cte-builder.js +172 -0
  74. package/dist/query/cte-builder.js.map +1 -0
  75. package/dist/query/grouped-query.d.ts +186 -0
  76. package/dist/query/grouped-query.d.ts.map +1 -0
  77. package/dist/query/grouped-query.js +588 -0
  78. package/dist/query/grouped-query.js.map +1 -0
  79. package/dist/query/join-builder.d.ts +106 -0
  80. package/dist/query/join-builder.d.ts.map +1 -0
  81. package/dist/query/join-builder.js +275 -0
  82. package/dist/query/join-builder.js.map +1 -0
  83. package/dist/query/query-builder.d.ts +543 -0
  84. package/dist/query/query-builder.d.ts.map +1 -0
  85. package/dist/query/query-builder.js +2649 -0
  86. package/dist/query/query-builder.js.map +1 -0
  87. package/dist/query/strategies/jsonb-collection-strategy.d.ts +51 -0
  88. package/dist/query/strategies/jsonb-collection-strategy.d.ts.map +1 -0
  89. package/dist/query/strategies/jsonb-collection-strategy.js +210 -0
  90. package/dist/query/strategies/jsonb-collection-strategy.js.map +1 -0
  91. package/dist/query/strategies/temptable-collection-strategy.d.ts +95 -0
  92. package/dist/query/strategies/temptable-collection-strategy.d.ts.map +1 -0
  93. package/dist/query/strategies/temptable-collection-strategy.js +456 -0
  94. package/dist/query/strategies/temptable-collection-strategy.js.map +1 -0
  95. package/dist/query/subquery.d.ts +152 -0
  96. package/dist/query/subquery.d.ts.map +1 -0
  97. package/dist/query/subquery.js +206 -0
  98. package/dist/query/subquery.js.map +1 -0
  99. package/dist/schema/column-builder.d.ts +127 -0
  100. package/dist/schema/column-builder.d.ts.map +1 -0
  101. package/dist/schema/column-builder.js +184 -0
  102. package/dist/schema/column-builder.js.map +1 -0
  103. package/dist/schema/inference.d.ts +26 -0
  104. package/dist/schema/inference.d.ts.map +1 -0
  105. package/dist/schema/inference.js +3 -0
  106. package/dist/schema/inference.js.map +1 -0
  107. package/dist/schema/navigation.d.ts +215 -0
  108. package/dist/schema/navigation.d.ts.map +1 -0
  109. package/dist/schema/navigation.js +233 -0
  110. package/dist/schema/navigation.js.map +1 -0
  111. package/dist/schema/row-type.d.ts +26 -0
  112. package/dist/schema/row-type.d.ts.map +1 -0
  113. package/dist/schema/row-type.js +3 -0
  114. package/dist/schema/row-type.js.map +1 -0
  115. package/dist/schema/sequence-builder.d.ts +87 -0
  116. package/dist/schema/sequence-builder.d.ts.map +1 -0
  117. package/dist/schema/sequence-builder.js +123 -0
  118. package/dist/schema/sequence-builder.js.map +1 -0
  119. package/dist/schema/table-builder.d.ts +122 -0
  120. package/dist/schema/table-builder.d.ts.map +1 -0
  121. package/dist/schema/table-builder.js +132 -0
  122. package/dist/schema/table-builder.js.map +1 -0
  123. package/dist/schema/typed-schema.d.ts +22 -0
  124. package/dist/schema/typed-schema.d.ts.map +1 -0
  125. package/dist/schema/typed-schema.js +28 -0
  126. package/dist/schema/typed-schema.js.map +1 -0
  127. package/dist/types/column-types.d.ts +20 -0
  128. package/dist/types/column-types.d.ts.map +1 -0
  129. package/dist/types/column-types.js +14 -0
  130. package/dist/types/column-types.js.map +1 -0
  131. package/dist/types/custom-types.d.ts +85 -0
  132. package/dist/types/custom-types.d.ts.map +1 -0
  133. package/dist/types/custom-types.js +132 -0
  134. package/dist/types/custom-types.js.map +1 -0
  135. package/dist/types/enum-builder.d.ts +31 -0
  136. package/dist/types/enum-builder.d.ts.map +1 -0
  137. package/dist/types/enum-builder.js +46 -0
  138. package/dist/types/enum-builder.js.map +1 -0
  139. package/dist/types/metadata.d.ts +67 -0
  140. package/dist/types/metadata.d.ts.map +1 -0
  141. package/dist/types/metadata.js +57 -0
  142. package/dist/types/metadata.js.map +1 -0
  143. package/dist/types/type-mapper.d.ts +49 -0
  144. package/dist/types/type-mapper.d.ts.map +1 -0
  145. package/dist/types/type-mapper.js +49 -0
  146. package/dist/types/type-mapper.js.map +1 -0
  147. package/package.json +77 -0
@@ -0,0 +1,222 @@
1
+ /**
2
+ * SQL condition types
3
+ */
4
+ export type ConditionOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'in' | 'notIn' | 'isNull' | 'isNotNull' | 'between';
5
+ /**
6
+ * Field reference - wraps a database column name with type information
7
+ * TName: The property name (e.g., 'isActive')
8
+ * TValueType: The TypeScript type of the column value (e.g., boolean)
9
+ */
10
+ export interface FieldRef<TName extends string = string, TValueType = any> {
11
+ readonly __fieldName: TName;
12
+ readonly __dbColumnName: string;
13
+ readonly __valueType?: TValueType;
14
+ }
15
+ /**
16
+ * Extract the field name from a FieldRef or string
17
+ */
18
+ export type ExtractFieldName<T> = T extends FieldRef<infer N, any> ? N : T extends string ? T : never;
19
+ /**
20
+ * Extract the value type from a FieldRef
21
+ */
22
+ export type ExtractValueType<T> = T extends FieldRef<any, infer V> ? V : any;
23
+ /**
24
+ * Context for building SQL with parameter tracking
25
+ */
26
+ export interface SqlBuildContext {
27
+ paramCounter: number;
28
+ params: any[];
29
+ }
30
+ /**
31
+ * Base class for all WHERE conditions with helper methods
32
+ */
33
+ export declare abstract class WhereConditionBase {
34
+ /**
35
+ * Build the SQL for this condition
36
+ */
37
+ abstract buildSql(context: SqlBuildContext): string;
38
+ /**
39
+ * Helper to check if a value is a FieldRef
40
+ */
41
+ protected isFieldRef<V>(value: any): value is FieldRef<any, V>;
42
+ /**
43
+ * Helper to extract database column name from field reference
44
+ * Returns the fully qualified column name (with table alias if present)
45
+ */
46
+ protected getDbColumnName<T extends string, V = any>(field: FieldRef<T, V> | T): string;
47
+ /**
48
+ * Helper to extract value from a FieldRef or constant
49
+ */
50
+ protected extractValue<V>(value: FieldRef<any, V> | V): any;
51
+ /**
52
+ * Helper to get the right-hand side of a comparison
53
+ * Returns either a column reference or a parameter placeholder
54
+ */
55
+ protected getRightSide<V>(value: FieldRef<any, V> | V, context: SqlBuildContext): string;
56
+ }
57
+ /**
58
+ * Base class for comparison operations (eq, gt, like, etc.)
59
+ */
60
+ export declare abstract class WhereComparisonBase<V = any> extends WhereConditionBase {
61
+ protected field: FieldRef<any, V> | string;
62
+ protected value?: (FieldRef<any, V> | V) | undefined;
63
+ constructor(field: FieldRef<any, V> | string, value?: (FieldRef<any, V> | V) | undefined);
64
+ /**
65
+ * Get the comparison operator (e.g., '=', '>', 'LIKE')
66
+ */
67
+ protected abstract getOperator(): string;
68
+ /**
69
+ * Build the comparison SQL
70
+ * Can be overridden for custom behavior
71
+ */
72
+ buildSql(context: SqlBuildContext): string;
73
+ }
74
+ /**
75
+ * Logical condition (AND, OR, NOT)
76
+ */
77
+ export declare class LogicalCondition extends WhereConditionBase {
78
+ private operator;
79
+ private conditions;
80
+ constructor(operator: 'and' | 'or' | 'not', conditions: WhereConditionBase[]);
81
+ buildSql(context: SqlBuildContext): string;
82
+ }
83
+ /**
84
+ * Raw SQL condition
85
+ */
86
+ export declare class RawSqlCondition extends WhereConditionBase {
87
+ private sql;
88
+ private sqlParams;
89
+ constructor(sql: string, sqlParams?: any[]);
90
+ buildSql(context: SqlBuildContext): string;
91
+ }
92
+ export declare class EqComparison<V = any> extends WhereComparisonBase<V> {
93
+ protected getOperator(): string;
94
+ }
95
+ export declare class NeComparison<V = any> extends WhereComparisonBase<V> {
96
+ protected getOperator(): string;
97
+ }
98
+ export declare class GtComparison<V = any> extends WhereComparisonBase<V> {
99
+ protected getOperator(): string;
100
+ }
101
+ export declare class GteComparison<V = any> extends WhereComparisonBase<V> {
102
+ protected getOperator(): string;
103
+ }
104
+ export declare class LtComparison<V = any> extends WhereComparisonBase<V> {
105
+ protected getOperator(): string;
106
+ }
107
+ export declare class LteComparison<V = any> extends WhereComparisonBase<V> {
108
+ protected getOperator(): string;
109
+ }
110
+ export declare class LikeComparison extends WhereComparisonBase<string> {
111
+ protected getOperator(): string;
112
+ }
113
+ export declare class ILikeComparison extends WhereComparisonBase<string> {
114
+ protected getOperator(): string;
115
+ }
116
+ export declare class IsNullComparison<V = any> extends WhereComparisonBase<V> {
117
+ constructor(field: FieldRef<any, V> | string);
118
+ protected getOperator(): string;
119
+ }
120
+ export declare class IsNotNullComparison<V = any> extends WhereComparisonBase<V> {
121
+ constructor(field: FieldRef<any, V> | string);
122
+ protected getOperator(): string;
123
+ }
124
+ /**
125
+ * IN comparison - handles array of values
126
+ */
127
+ export declare class InComparison<V = any> extends WhereComparisonBase<V> {
128
+ private values;
129
+ constructor(field: FieldRef<any, V> | string, values: V[]);
130
+ buildSql(context: SqlBuildContext): string;
131
+ protected getOperator(): string;
132
+ }
133
+ /**
134
+ * NOT IN comparison
135
+ */
136
+ export declare class NotInComparison<V = any> extends WhereComparisonBase<V> {
137
+ private values;
138
+ constructor(field: FieldRef<any, V> | string, values: V[]);
139
+ buildSql(context: SqlBuildContext): string;
140
+ protected getOperator(): string;
141
+ }
142
+ /**
143
+ * BETWEEN comparison
144
+ */
145
+ export declare class BetweenComparison<V = any> extends WhereComparisonBase<V> {
146
+ private min;
147
+ private max;
148
+ constructor(field: FieldRef<any, V> | string, min: FieldRef<any, V> | V, max: FieldRef<any, V> | V);
149
+ buildSql(context: SqlBuildContext): string;
150
+ protected getOperator(): string;
151
+ }
152
+ /**
153
+ * Condition type - can be any WHERE condition
154
+ */
155
+ export type Condition = WhereConditionBase;
156
+ export declare function eq<T extends string, V>(field: FieldRef<T, V> | T, value: FieldRef<any, V> | V): Condition;
157
+ export declare function ne<T extends string, V>(field: FieldRef<T, V> | T, value: FieldRef<any, V> | V): Condition;
158
+ export declare function gt<T extends string, V>(field: FieldRef<T, V> | T, value: FieldRef<any, V> | V): Condition;
159
+ export declare function gte<T extends string, V>(field: FieldRef<T, V> | T, value: FieldRef<any, V> | V): Condition;
160
+ export declare function lt<T extends string, V>(field: FieldRef<T, V> | T, value: FieldRef<any, V> | V): Condition;
161
+ export declare function lte<T extends string, V>(field: FieldRef<T, V> | T, value: FieldRef<any, V> | V): Condition;
162
+ export declare function like<T extends string>(field: FieldRef<T, string> | T, value: FieldRef<any, string> | string): Condition;
163
+ export declare function ilike<T extends string>(field: FieldRef<T, string> | T, value: FieldRef<any, string> | string): Condition;
164
+ export declare function inArray<T extends string, V>(field: FieldRef<T, V> | T, values: V[]): Condition;
165
+ export declare function notInArray<T extends string, V>(field: FieldRef<T, V> | T, values: V[]): Condition;
166
+ export declare function isNull<T extends string, V>(field: FieldRef<T, V> | T): Condition;
167
+ export declare function isNotNull<T extends string, V>(field: FieldRef<T, V> | T): Condition;
168
+ export declare function between<T extends string, V>(field: FieldRef<T, V> | T, min: FieldRef<any, V> | V, max: FieldRef<any, V> | V): Condition;
169
+ export declare function and(...conditions: Condition[]): Condition;
170
+ export declare function or(...conditions: Condition[]): Condition;
171
+ export declare function not(condition: Condition): Condition;
172
+ /**
173
+ * SQL Fragment - represents a raw SQL expression that can be used in SELECT or WHERE
174
+ * Supports embedding FieldRef objects
175
+ * Extends WhereConditionBase so it can be used directly in WHERE clauses
176
+ */
177
+ export declare class SqlFragment<TValueType = any> extends WhereConditionBase {
178
+ private sqlParts;
179
+ private values;
180
+ private mapper?;
181
+ private alias?;
182
+ constructor(parts: string[], values: any[], mapper?: any, alias?: string);
183
+ /**
184
+ * Set custom type mapper for bidirectional transformation
185
+ * Can accept either:
186
+ * - A function (value: TDriver) => TData for inline transformations
187
+ * - A CustomTypeBuilder with full toDriver/fromDriver methods
188
+ */
189
+ mapWith<TData = TValueType, TDriver = any>(mapper: ((value: TDriver) => TData) | any): SqlFragment<TData>;
190
+ /**
191
+ * Set column alias for SELECT clause
192
+ */
193
+ as(alias: string): SqlFragment<TValueType>;
194
+ /**
195
+ * Get the type mapper (internal use)
196
+ */
197
+ getMapper(): any | undefined;
198
+ /**
199
+ * Get the alias (internal use)
200
+ */
201
+ getAlias(): string | undefined;
202
+ /**
203
+ * Build the SQL string with proper parameter placeholders
204
+ */
205
+ buildSql(context: SqlBuildContext): string;
206
+ /**
207
+ * Get the SQL string with parameters (for debugging)
208
+ */
209
+ toString(): string;
210
+ }
211
+ /**
212
+ * Tagged template literal for creating SQL fragments
213
+ * Usage: sql`lower(${field})` or sql`${field} = ${value}`
214
+ */
215
+ export declare function sql<TValueType = any>(strings: TemplateStringsArray, ...values: any[]): SqlFragment<TValueType>;
216
+ export declare class ConditionBuilder {
217
+ build(condition: Condition, startParam?: number): {
218
+ sql: string;
219
+ params: any[];
220
+ };
221
+ }
222
+ //# sourceMappingURL=conditions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditions.d.ts","sourceRoot":"","sources":["../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ACH,wBAAgB,GAAG,CAAC,UAAU,GAAG,GAAG,EAClC,OAAO,EAAE,oBAAoB,EAC7B,GAAG,MAAM,EAAE,GAAG,EAAE,GACf,WAAW,CAAC,UAAU,CAAC,CAEzB;AAMD,qBAAa,gBAAgB;IAC3B,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,GAAE,MAAU,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,EAAE,CAAA;KAAE;CASpF"}
@@ -0,0 +1,446 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConditionBuilder = exports.SqlFragment = exports.BetweenComparison = exports.NotInComparison = exports.InComparison = exports.IsNotNullComparison = exports.IsNullComparison = exports.ILikeComparison = exports.LikeComparison = exports.LteComparison = exports.LtComparison = exports.GteComparison = exports.GtComparison = exports.NeComparison = exports.EqComparison = exports.RawSqlCondition = exports.LogicalCondition = exports.WhereComparisonBase = exports.WhereConditionBase = void 0;
4
+ exports.eq = eq;
5
+ exports.ne = ne;
6
+ exports.gt = gt;
7
+ exports.gte = gte;
8
+ exports.lt = lt;
9
+ exports.lte = lte;
10
+ exports.like = like;
11
+ exports.ilike = ilike;
12
+ exports.inArray = inArray;
13
+ exports.notInArray = notInArray;
14
+ exports.isNull = isNull;
15
+ exports.isNotNull = isNotNull;
16
+ exports.between = between;
17
+ exports.and = and;
18
+ exports.or = or;
19
+ exports.not = not;
20
+ exports.sql = sql;
21
+ /**
22
+ * Base class for all WHERE conditions with helper methods
23
+ */
24
+ class WhereConditionBase {
25
+ /**
26
+ * Helper to check if a value is a FieldRef
27
+ */
28
+ isFieldRef(value) {
29
+ return typeof value === 'object' && value !== null && '__dbColumnName' in value;
30
+ }
31
+ /**
32
+ * Helper to extract database column name from field reference
33
+ * Returns the fully qualified column name (with table alias if present)
34
+ */
35
+ getDbColumnName(field) {
36
+ if (typeof field === 'object' && '__dbColumnName' in field) {
37
+ // Check if field has a table alias
38
+ if ('__tableAlias' in field && field.__tableAlias) {
39
+ // Return fully quoted table.column
40
+ return `"${field.__tableAlias}"."${field.__dbColumnName}"`;
41
+ }
42
+ // Return just the quoted column name
43
+ return `"${field.__dbColumnName}"`;
44
+ }
45
+ // For string fields, quote them
46
+ return `"${field}"`;
47
+ }
48
+ /**
49
+ * Helper to extract value from a FieldRef or constant
50
+ */
51
+ extractValue(value) {
52
+ if (this.isFieldRef(value)) {
53
+ return value.__dbColumnName;
54
+ }
55
+ return value;
56
+ }
57
+ /**
58
+ * Helper to get the right-hand side of a comparison
59
+ * Returns either a column reference or a parameter placeholder
60
+ */
61
+ getRightSide(value, context) {
62
+ if (this.isFieldRef(value)) {
63
+ // Value is a field reference, use it with table alias if present
64
+ if ('__tableAlias' in value && value.__tableAlias) {
65
+ return `"${value.__tableAlias}"."${value.__dbColumnName}"`;
66
+ }
67
+ return `"${value.__dbColumnName}"`;
68
+ }
69
+ else {
70
+ // Value is a literal, use a parameter
71
+ context.params.push(value);
72
+ return `$${context.paramCounter++}`;
73
+ }
74
+ }
75
+ }
76
+ exports.WhereConditionBase = WhereConditionBase;
77
+ /**
78
+ * Base class for comparison operations (eq, gt, like, etc.)
79
+ */
80
+ class WhereComparisonBase extends WhereConditionBase {
81
+ constructor(field, value) {
82
+ super();
83
+ this.field = field;
84
+ this.value = value;
85
+ }
86
+ /**
87
+ * Build the comparison SQL
88
+ * Can be overridden for custom behavior
89
+ */
90
+ buildSql(context) {
91
+ const fieldName = this.getDbColumnName(this.field); // Returns already quoted name
92
+ const operator = this.getOperator();
93
+ if (this.value !== undefined) {
94
+ const rightSide = this.getRightSide(this.value, context);
95
+ return `${fieldName} ${operator} ${rightSide}`;
96
+ }
97
+ else {
98
+ // For operators like IS NULL that don't have a value
99
+ return `${fieldName} ${operator}`;
100
+ }
101
+ }
102
+ }
103
+ exports.WhereComparisonBase = WhereComparisonBase;
104
+ /**
105
+ * Logical condition (AND, OR, NOT)
106
+ */
107
+ class LogicalCondition extends WhereConditionBase {
108
+ constructor(operator, conditions) {
109
+ super();
110
+ this.operator = operator;
111
+ this.conditions = conditions;
112
+ }
113
+ buildSql(context) {
114
+ if (this.conditions.length === 0) {
115
+ return '1=1';
116
+ }
117
+ const parts = this.conditions.map(c => c.buildSql(context));
118
+ switch (this.operator) {
119
+ case 'and':
120
+ return parts.length === 1 ? parts[0] : `(${parts.join(' AND ')})`;
121
+ case 'or':
122
+ return parts.length === 1 ? parts[0] : `(${parts.join(' OR ')})`;
123
+ case 'not':
124
+ return `NOT (${parts[0]})`;
125
+ default:
126
+ throw new Error(`Unknown logical operator: ${this.operator}`);
127
+ }
128
+ }
129
+ }
130
+ exports.LogicalCondition = LogicalCondition;
131
+ /**
132
+ * Raw SQL condition
133
+ */
134
+ class RawSqlCondition extends WhereConditionBase {
135
+ constructor(sql, sqlParams = []) {
136
+ super();
137
+ this.sql = sql;
138
+ this.sqlParams = sqlParams;
139
+ }
140
+ buildSql(context) {
141
+ if (this.sqlParams.length > 0) {
142
+ context.params.push(...this.sqlParams);
143
+ }
144
+ return this.sql;
145
+ }
146
+ }
147
+ exports.RawSqlCondition = RawSqlCondition;
148
+ // ============================================================================
149
+ // Specific comparison implementations
150
+ // ============================================================================
151
+ class EqComparison extends WhereComparisonBase {
152
+ getOperator() {
153
+ return '=';
154
+ }
155
+ }
156
+ exports.EqComparison = EqComparison;
157
+ class NeComparison extends WhereComparisonBase {
158
+ getOperator() {
159
+ return '!=';
160
+ }
161
+ }
162
+ exports.NeComparison = NeComparison;
163
+ class GtComparison extends WhereComparisonBase {
164
+ getOperator() {
165
+ return '>';
166
+ }
167
+ }
168
+ exports.GtComparison = GtComparison;
169
+ class GteComparison extends WhereComparisonBase {
170
+ getOperator() {
171
+ return '>=';
172
+ }
173
+ }
174
+ exports.GteComparison = GteComparison;
175
+ class LtComparison extends WhereComparisonBase {
176
+ getOperator() {
177
+ return '<';
178
+ }
179
+ }
180
+ exports.LtComparison = LtComparison;
181
+ class LteComparison extends WhereComparisonBase {
182
+ getOperator() {
183
+ return '<=';
184
+ }
185
+ }
186
+ exports.LteComparison = LteComparison;
187
+ class LikeComparison extends WhereComparisonBase {
188
+ getOperator() {
189
+ return 'LIKE';
190
+ }
191
+ }
192
+ exports.LikeComparison = LikeComparison;
193
+ class ILikeComparison extends WhereComparisonBase {
194
+ getOperator() {
195
+ return 'ILIKE';
196
+ }
197
+ }
198
+ exports.ILikeComparison = ILikeComparison;
199
+ class IsNullComparison extends WhereComparisonBase {
200
+ constructor(field) {
201
+ super(field, undefined);
202
+ }
203
+ getOperator() {
204
+ return 'IS NULL';
205
+ }
206
+ }
207
+ exports.IsNullComparison = IsNullComparison;
208
+ class IsNotNullComparison extends WhereComparisonBase {
209
+ constructor(field) {
210
+ super(field, undefined);
211
+ }
212
+ getOperator() {
213
+ return 'IS NOT NULL';
214
+ }
215
+ }
216
+ exports.IsNotNullComparison = IsNotNullComparison;
217
+ /**
218
+ * IN comparison - handles array of values
219
+ */
220
+ class InComparison extends WhereComparisonBase {
221
+ constructor(field, values) {
222
+ super(field, undefined);
223
+ this.values = values;
224
+ }
225
+ buildSql(context) {
226
+ const fieldName = this.getDbColumnName(this.field); // Returns already quoted name
227
+ if (!Array.isArray(this.values) || this.values.length === 0) {
228
+ return '1=0'; // No matches
229
+ }
230
+ const params = this.values.map(() => `$${context.paramCounter++}`).join(', ');
231
+ context.params.push(...this.values);
232
+ return `${fieldName} IN (${params})`;
233
+ }
234
+ getOperator() {
235
+ return 'IN';
236
+ }
237
+ }
238
+ exports.InComparison = InComparison;
239
+ /**
240
+ * NOT IN comparison
241
+ */
242
+ class NotInComparison extends WhereComparisonBase {
243
+ constructor(field, values) {
244
+ super(field, undefined);
245
+ this.values = values;
246
+ }
247
+ buildSql(context) {
248
+ const fieldName = this.getDbColumnName(this.field); // Returns already quoted name
249
+ if (!Array.isArray(this.values) || this.values.length === 0) {
250
+ return '1=1'; // All match
251
+ }
252
+ const params = this.values.map(() => `$${context.paramCounter++}`).join(', ');
253
+ context.params.push(...this.values);
254
+ return `${fieldName} NOT IN (${params})`;
255
+ }
256
+ getOperator() {
257
+ return 'NOT IN';
258
+ }
259
+ }
260
+ exports.NotInComparison = NotInComparison;
261
+ /**
262
+ * BETWEEN comparison
263
+ */
264
+ class BetweenComparison extends WhereComparisonBase {
265
+ constructor(field, min, max) {
266
+ super(field, undefined);
267
+ this.min = min;
268
+ this.max = max;
269
+ }
270
+ buildSql(context) {
271
+ const fieldName = this.getDbColumnName(this.field); // Returns already quoted name
272
+ const minSide = this.getRightSide(this.min, context);
273
+ const maxSide = this.getRightSide(this.max, context);
274
+ return `${fieldName} BETWEEN ${minSide} AND ${maxSide}`;
275
+ }
276
+ getOperator() {
277
+ return 'BETWEEN';
278
+ }
279
+ }
280
+ exports.BetweenComparison = BetweenComparison;
281
+ // ============================================================================
282
+ // Condition factory functions
283
+ // These are type-safe and return class instances
284
+ // ============================================================================
285
+ function eq(field, value) {
286
+ return new EqComparison(field, value);
287
+ }
288
+ function ne(field, value) {
289
+ return new NeComparison(field, value);
290
+ }
291
+ function gt(field, value) {
292
+ return new GtComparison(field, value);
293
+ }
294
+ function gte(field, value) {
295
+ return new GteComparison(field, value);
296
+ }
297
+ function lt(field, value) {
298
+ return new LtComparison(field, value);
299
+ }
300
+ function lte(field, value) {
301
+ return new LteComparison(field, value);
302
+ }
303
+ function like(field, value) {
304
+ return new LikeComparison(field, value);
305
+ }
306
+ function ilike(field, value) {
307
+ return new ILikeComparison(field, value);
308
+ }
309
+ function inArray(field, values) {
310
+ return new InComparison(field, values);
311
+ }
312
+ function notInArray(field, values) {
313
+ return new NotInComparison(field, values);
314
+ }
315
+ function isNull(field) {
316
+ return new IsNullComparison(field);
317
+ }
318
+ function isNotNull(field) {
319
+ return new IsNotNullComparison(field);
320
+ }
321
+ function between(field, min, max) {
322
+ return new BetweenComparison(field, min, max);
323
+ }
324
+ function and(...conditions) {
325
+ return new LogicalCondition('and', conditions);
326
+ }
327
+ function or(...conditions) {
328
+ return new LogicalCondition('or', conditions);
329
+ }
330
+ function not(condition) {
331
+ return new LogicalCondition('not', [condition]);
332
+ }
333
+ // ============================================================================
334
+ // SQL Fragment - for use in SELECT projections and WHERE conditions
335
+ // ============================================================================
336
+ /**
337
+ * SQL Fragment - represents a raw SQL expression that can be used in SELECT or WHERE
338
+ * Supports embedding FieldRef objects
339
+ * Extends WhereConditionBase so it can be used directly in WHERE clauses
340
+ */
341
+ class SqlFragment extends WhereConditionBase {
342
+ constructor(parts, values, mapper, alias) {
343
+ super();
344
+ this.sqlParts = parts;
345
+ this.values = values;
346
+ this.mapper = mapper;
347
+ this.alias = alias;
348
+ }
349
+ /**
350
+ * Set custom type mapper for bidirectional transformation
351
+ * Can accept either:
352
+ * - A function (value: TDriver) => TData for inline transformations
353
+ * - A CustomTypeBuilder with full toDriver/fromDriver methods
354
+ */
355
+ mapWith(mapper) {
356
+ // If mapper is a function, wrap it in a simple mapper object
357
+ const normalizedMapper = typeof mapper === 'function'
358
+ ? { fromDriver: mapper }
359
+ : mapper;
360
+ return new SqlFragment(this.sqlParts, this.values, normalizedMapper, this.alias);
361
+ }
362
+ /**
363
+ * Set column alias for SELECT clause
364
+ */
365
+ as(alias) {
366
+ return new SqlFragment(this.sqlParts, this.values, this.mapper, alias);
367
+ }
368
+ /**
369
+ * Get the type mapper (internal use)
370
+ */
371
+ getMapper() {
372
+ return this.mapper;
373
+ }
374
+ /**
375
+ * Get the alias (internal use)
376
+ */
377
+ getAlias() {
378
+ return this.alias;
379
+ }
380
+ /**
381
+ * Build the SQL string with proper parameter placeholders
382
+ */
383
+ buildSql(context) {
384
+ let sql = '';
385
+ for (let i = 0; i < this.sqlParts.length; i++) {
386
+ sql += this.sqlParts[i];
387
+ if (i < this.values.length) {
388
+ const value = this.values[i];
389
+ // Check if value is a FieldRef
390
+ if (this.isFieldRef(value)) {
391
+ // It's a field reference - use the database column name with table alias if present
392
+ if ('__tableAlias' in value && value.__tableAlias) {
393
+ sql += `"${value.__tableAlias}"."${value.__dbColumnName}"`;
394
+ }
395
+ else {
396
+ sql += `"${value.__dbColumnName}"`;
397
+ }
398
+ }
399
+ else if (value instanceof SqlFragment) {
400
+ // It's a nested SQL fragment
401
+ sql += value.buildSql(context);
402
+ }
403
+ else if (typeof value === 'object' && value !== null && 'buildSql' in value && typeof value.buildSql === 'function') {
404
+ // It's a Subquery (or any object with buildSql method)
405
+ sql += `(${value.buildSql(context)})`;
406
+ }
407
+ else {
408
+ // It's a literal value - use a parameter
409
+ sql += `$${context.paramCounter++}`;
410
+ context.params.push(value);
411
+ }
412
+ }
413
+ }
414
+ return sql;
415
+ }
416
+ /**
417
+ * Get the SQL string with parameters (for debugging)
418
+ */
419
+ toString() {
420
+ const context = { paramCounter: 1, params: [] };
421
+ return this.buildSql(context);
422
+ }
423
+ }
424
+ exports.SqlFragment = SqlFragment;
425
+ /**
426
+ * Tagged template literal for creating SQL fragments
427
+ * Usage: sql`lower(${field})` or sql`${field} = ${value}`
428
+ */
429
+ function sql(strings, ...values) {
430
+ return new SqlFragment(Array.from(strings), values);
431
+ }
432
+ // ============================================================================
433
+ // SQL builder for conditions
434
+ // ============================================================================
435
+ class ConditionBuilder {
436
+ build(condition, startParam = 1) {
437
+ const context = {
438
+ paramCounter: startParam,
439
+ params: [],
440
+ };
441
+ const sql = condition.buildSql(context);
442
+ return { sql, params: context.params };
443
+ }
444
+ }
445
+ exports.ConditionBuilder = ConditionBuilder;
446
+ //# sourceMappingURL=conditions.js.map