drizzle-orm 0.31.2-5b29cb4 → 0.31.2-aaea9bd
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/expo-sqlite/index.cjs +2 -0
- package/expo-sqlite/index.cjs.map +1 -1
- package/expo-sqlite/index.d.cts +1 -0
- package/expo-sqlite/index.d.ts +1 -0
- package/expo-sqlite/index.js +1 -0
- package/expo-sqlite/index.js.map +1 -1
- package/expo-sqlite/query.cjs +69 -0
- package/expo-sqlite/query.cjs.map +1 -0
- package/expo-sqlite/query.d.cts +7 -0
- package/expo-sqlite/query.d.ts +7 -0
- package/expo-sqlite/query.js +45 -0
- package/expo-sqlite/query.js.map +1 -0
- package/package.json +25 -1
- package/sql/functions/full-text-search.cjs +75 -0
- package/sql/functions/full-text-search.cjs.map +1 -0
- package/sql/functions/full-text-search.d.cts +235 -0
- package/sql/functions/full-text-search.d.ts +235 -0
- package/sql/functions/full-text-search.js +44 -0
- package/sql/functions/full-text-search.js.map +1 -0
- package/sql/functions/index.cjs +2 -0
- package/sql/functions/index.cjs.map +1 -1
- package/sql/functions/index.d.cts +1 -0
- package/sql/functions/index.d.ts +1 -0
- package/sql/functions/index.js +1 -0
- package/sql/functions/index.js.map +1 -1
- package/sqlite-core/columns/text.cjs +30 -1
- package/sqlite-core/columns/text.cjs.map +1 -1
- package/sqlite-core/columns/text.d.cts +23 -2
- package/sqlite-core/columns/text.d.ts +23 -2
- package/sqlite-core/columns/text.js +28 -1
- package/sqlite-core/columns/text.js.map +1 -1
- package/sqlite-core/query-builders/query.cjs.map +1 -1
- package/sqlite-core/query-builders/query.d.cts +3 -2
- package/sqlite-core/query-builders/query.d.ts +3 -2
- package/sqlite-core/query-builders/query.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { AnyPgColumn } from "../../pg-core/index.js";
|
|
2
|
+
import { type SQL } from "../sql.js";
|
|
3
|
+
type Configuration = 'simple' | 'arabic' | 'armenian' | 'basque' | 'catalan' | 'danish' | 'dutch' | 'english' | 'finnish' | 'french' | 'german' | 'greek' | 'hindi' | 'hungarian' | 'indonesian' | 'irish' | 'italian' | 'lithuanian' | 'nepali' | 'norwegian' | 'portuguese' | 'romanian' | 'serbian' | 'spanish' | 'swedish' | 'tamil' | 'turkish' | 'yiddish';
|
|
4
|
+
type Weight = 'A' | 'B' | 'C' | 'D';
|
|
5
|
+
/**
|
|
6
|
+
* Converts a document to the `tsvector` data type.
|
|
7
|
+
*
|
|
8
|
+
* @param {AnyPgColumn | string} document - The document to be converted into `tsvector`.
|
|
9
|
+
* @returns {SQL}
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* await db.select({ value: to_tsvector(posts.title) }).from(posts);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function to_tsvector(document: AnyPgColumn | string): SQL;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a document to the `tsvector` data type.
|
|
19
|
+
*
|
|
20
|
+
* @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').
|
|
21
|
+
* @param {AnyPgColumn | string} document - The document to be converted into `tsvector`.
|
|
22
|
+
* @returns {SQL}
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* await db.select({ value: to_tsvector('english', posts.title) }).from(posts);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function to_tsvector(configuration: Configuration | string & {}, document: AnyPgColumn | string): SQL;
|
|
30
|
+
/**
|
|
31
|
+
* Converts a query to the `tsquery` data type.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
34
|
+
* @returns {SQL}
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${to_tsquery('Drizzle')}`);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function to_tsquery(query: string): SQL;
|
|
42
|
+
/**
|
|
43
|
+
* Converts a query to the `tsquery` data type.
|
|
44
|
+
*
|
|
45
|
+
* @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').
|
|
46
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
47
|
+
* @returns {SQL}
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${to_tsquery('english', 'Drizzle')}`);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function to_tsquery(configuration: Configuration | string & {}, query: string): SQL;
|
|
55
|
+
/**
|
|
56
|
+
* Converts a query to the `tsquery` data type.
|
|
57
|
+
*
|
|
58
|
+
* The text is parsed and normalized much as for `to_tsvector`, then the `&` (AND) tsquery operator is inserted between surviving words.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
61
|
+
* @returns {SQL}
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${plainto_tsquery('PostgreSQL MySQL SQLite')}`);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function plainto_tsquery(query: string): SQL;
|
|
69
|
+
/**
|
|
70
|
+
* Converts a query to the `tsquery` data type.
|
|
71
|
+
*
|
|
72
|
+
* The text is parsed and normalized much as for `to_tsvector`, then the `&` (AND) tsquery operator is inserted between surviving words.
|
|
73
|
+
*
|
|
74
|
+
* @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').
|
|
75
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
76
|
+
* @returns {SQL}
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${plainto_tsquery('english', 'PostgreSQL MySQL SQLite')}`);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function plainto_tsquery(configuration: Configuration | string & {}, query: string): SQL;
|
|
84
|
+
/**
|
|
85
|
+
* Converts a query to the `tsquery` data type.
|
|
86
|
+
*
|
|
87
|
+
* `phraseto_tsquery` behaves much like `plainto_tsquery`, except that it inserts the `<->` (FOLLOWED BY) operator between surviving words instead of the `&` (AND) operator.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
90
|
+
* @returns {SQL}
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${phraseto_tsquery('Drizzle best practice')}`);
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function phraseto_tsquery(query: string): SQL;
|
|
98
|
+
/**
|
|
99
|
+
* Converts a query to the `tsquery` data type.
|
|
100
|
+
*
|
|
101
|
+
* `phraseto_tsquery` behaves much like `plainto_tsquery`, except that it inserts the `<->` (FOLLOWED BY) operator between surviving words instead of the `&` (AND) operator.
|
|
102
|
+
*
|
|
103
|
+
* @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').
|
|
104
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
105
|
+
* @returns {SQL}
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${phraseto_tsquery('english', 'Drizzle best practice')}`);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function phraseto_tsquery(configuration: Configuration | string & {}, query: string): SQL;
|
|
113
|
+
/**
|
|
114
|
+
* Converts a query to the `tsquery` data type.
|
|
115
|
+
*
|
|
116
|
+
* `websearch_to_tsquery` creates a `tsquery` value from querytext using an alternative syntax in which simple unformatted text is a valid query. Unlike `plainto_tsquery` and `phraseto_tsquery`, it also recognizes certain operators. Moreover, this function will never raise syntax errors, which makes it possible to use raw user-supplied input for search.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
119
|
+
* @returns {SQL}
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${websearch_to_tsquery('tips or updates Drizzle')}`);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function websearch_to_tsquery(query: string): SQL;
|
|
127
|
+
/**
|
|
128
|
+
* Converts a query to the `tsquery` data type.
|
|
129
|
+
*
|
|
130
|
+
* `websearch_to_tsquery` creates a `tsquery` value from querytext using an alternative syntax in which simple unformatted text is a valid query. Unlike `plainto_tsquery` and `phraseto_tsquery`, it also recognizes certain operators. Moreover, this function will never raise syntax errors, which makes it possible to use raw user-supplied input for search.
|
|
131
|
+
*
|
|
132
|
+
* @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').
|
|
133
|
+
* @param {string} query - The text to be converted into `tsquery`.
|
|
134
|
+
* @returns {SQL}
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${websearch_to_tsquery('english', 'tips or updates Drizzle')}`);
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function websearch_to_tsquery(configuration: Configuration | string & {}, query: string): SQL;
|
|
142
|
+
/**
|
|
143
|
+
* Calculates the text search rank of a document represented by a `tsvector` against a `tsquery`.
|
|
144
|
+
*
|
|
145
|
+
* @param {SQL} vector - The `tsvector` representation of the document.
|
|
146
|
+
* @param {SQL} query - The `tsquery` to compare against the vector.
|
|
147
|
+
* @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.
|
|
148
|
+
* @returns {SQL}
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const vector = to_tsvector('english', posts.title);
|
|
153
|
+
* const query = to_tsquery('english', 'Drizzle');
|
|
154
|
+
* const rank = ts_rank(vector, query);
|
|
155
|
+
*
|
|
156
|
+
* await db.select({ post: posts, rank }).from(posts).where(gt(rank, 0));
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export declare function ts_rank(vector: SQL, query: SQL, normalization?: number): SQL;
|
|
160
|
+
/**
|
|
161
|
+
* Calculates the text search rank of a document represented by a `tsvector` against a `tsquery`, using weights.
|
|
162
|
+
*
|
|
163
|
+
* @param {number[]} weights - Array of weights applied to the document's components.
|
|
164
|
+
* @param {SQL} vector - The `tsvector` representation of the document.
|
|
165
|
+
* @param {SQL} query - The `tsquery` to compare against the vector.
|
|
166
|
+
* @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.
|
|
167
|
+
* @returns {SQL}
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const weights = [0.1, 0.2, 0.4, 0.3];
|
|
172
|
+
* const vector = to_tsvector('english', posts.title);
|
|
173
|
+
* const query = to_tsquery('english', 'Drizzle');
|
|
174
|
+
* const rank = ts_rank(weights, vector, query);
|
|
175
|
+
*
|
|
176
|
+
* await db.select({ post: posts, rank }).from(posts).where(gt(rank, 0));
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function ts_rank(weights: number[], vector: SQL, query: SQL, normalization?: number): SQL;
|
|
180
|
+
/**
|
|
181
|
+
* Calculates the text search rank of a document with cover density ranking, represented by a `tsvector` against a `tsquery`.
|
|
182
|
+
*
|
|
183
|
+
* @param {SQL} vector - The `tsvector` representation of the document.
|
|
184
|
+
* @param {SQL} query - The `tsquery` to compare against the vector.
|
|
185
|
+
* @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.
|
|
186
|
+
* @returns {SQL}
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const vector = to_tsvector('english', posts.title);
|
|
191
|
+
* const query = to_tsquery('english', 'Drizzle');
|
|
192
|
+
* const rankCd = ts_rank_cd(vector, query);
|
|
193
|
+
*
|
|
194
|
+
* await db.select({ post: posts, rankCd }).from(posts).where(gt(rankCd, 0));
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
export declare function ts_rank_cd(vector: SQL, query: SQL, normalization?: number): SQL;
|
|
198
|
+
/**
|
|
199
|
+
* Calculates the text search rank of a document represented by a `tsvector` against a `tsquery`, using weights.
|
|
200
|
+
*
|
|
201
|
+
* @param {number[]} weights - Array of weights applied to the document's components.
|
|
202
|
+
* @param {SQL} vector - The `tsvector` representation of the document.
|
|
203
|
+
* @param {SQL} query - The `tsquery` to compare against the vector.
|
|
204
|
+
* @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.
|
|
205
|
+
* @returns {SQL}
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* const weights = [0.1, 0.2, 0.4, 0.3];
|
|
210
|
+
* const vector = to_tsvector('english', posts.title);
|
|
211
|
+
* const query = to_tsquery('english', 'Drizzle');
|
|
212
|
+
* const rankCd = ts_rank_cd(weights, vector, query);
|
|
213
|
+
*
|
|
214
|
+
* await db.select({ post: posts, rankCd }).from(posts).where(gt(rankCd, 0));
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare function ts_rank_cd(weights: number[], vector: SQL, query: SQL, normalization?: number): SQL;
|
|
218
|
+
/**
|
|
219
|
+
* Used to label the entries of a `tsvector` with a given weight, where a weight is one of the letters A, B, C, or D.
|
|
220
|
+
*
|
|
221
|
+
* @param {SQL} vector - The `tsvector` representation of the document.
|
|
222
|
+
* @param {Weight} weight - The weight to be assigned to the elements of the vector.
|
|
223
|
+
* @returns {SQL}
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* const weightedVectorTitle = setweight(to_tsvector('english', posts.title), 'A');
|
|
228
|
+
* const weightedVectorDescription = setweight(to_tsvector('english', posts.description), 'B');
|
|
229
|
+
* const query = to_tsquery('english', 'Drizzle');
|
|
230
|
+
*
|
|
231
|
+
* await db.select().from(posts).where(sql`(${weightedVectorTitle} || ${weightedVectorDescription}) @@ ${query}`);
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare function setweight(vector: SQL, weight: Weight | string & {}): SQL;
|
|
235
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { sql } from "../sql.js";
|
|
2
|
+
function to_tsvector(arg1, arg2) {
|
|
3
|
+
return arg2 ? sql`to_tsvector(${arg1}, ${arg2})` : sql`to_tsvector(${arg1})`;
|
|
4
|
+
}
|
|
5
|
+
function to_tsquery(arg1, arg2) {
|
|
6
|
+
return arg2 ? sql`to_tsquery(${arg1}, ${arg2})` : sql`to_tsquery(${arg1})`;
|
|
7
|
+
}
|
|
8
|
+
function plainto_tsquery(arg1, arg2) {
|
|
9
|
+
return arg2 ? sql`plainto_tsquery(${arg1}, ${arg2})` : sql`plainto_tsquery(${arg1})`;
|
|
10
|
+
}
|
|
11
|
+
function phraseto_tsquery(arg1, arg2) {
|
|
12
|
+
return arg2 ? sql`phraseto_tsquery(${arg1}, ${arg2})` : sql`phraseto_tsquery(${arg1})`;
|
|
13
|
+
}
|
|
14
|
+
function websearch_to_tsquery(arg1, arg2) {
|
|
15
|
+
return arg2 ? sql`websearch_to_tsquery(${arg1}, ${arg2})` : sql`websearch_to_tsquery(${arg1})`;
|
|
16
|
+
}
|
|
17
|
+
function ts_rank(arg1, arg2, arg3, arg4) {
|
|
18
|
+
if (Array.isArray(arg1) && typeof arg2 !== "number" && arg3 !== void 0) {
|
|
19
|
+
return arg4 ? sql`ts_rank(string_to_array(${arg1.join(",")}, ',')::float4[], ${arg2}, ${arg3}, ${arg4})` : sql`ts_rank(string_to_array(${arg1.join(",")}, ',')::float4[], ${arg2}, ${arg3})`;
|
|
20
|
+
} else {
|
|
21
|
+
return arg3 ? sql`ts_rank(${arg1}, ${arg2}, ${arg3})` : sql`ts_rank(${arg1}, ${arg2})`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function ts_rank_cd(arg1, arg2, arg3, arg4) {
|
|
25
|
+
if (Array.isArray(arg1) && typeof arg2 !== "number" && arg3 !== void 0) {
|
|
26
|
+
return arg4 ? sql`ts_rank_cd(string_to_array(${arg1.join(",")}, ',')::float4[], ${arg2}, ${arg3}, ${arg4})` : sql`ts_rank_cd(string_to_array(${arg1.join(",")}, ',')::float4[], ${arg2}, ${arg3})`;
|
|
27
|
+
} else {
|
|
28
|
+
return arg3 ? sql`ts_rank_cd(${arg1}, ${arg2}, ${arg3})` : sql`ts_rank_cd(${arg1}, ${arg2})`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function setweight(vector, weight) {
|
|
32
|
+
return sql`setweight(${vector}, ${weight})`;
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
phraseto_tsquery,
|
|
36
|
+
plainto_tsquery,
|
|
37
|
+
setweight,
|
|
38
|
+
to_tsquery,
|
|
39
|
+
to_tsvector,
|
|
40
|
+
ts_rank,
|
|
41
|
+
ts_rank_cd,
|
|
42
|
+
websearch_to_tsquery
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=full-text-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/sql/functions/full-text-search.ts"],"sourcesContent":["import type { AnyPgColumn } from '~/pg-core/index.ts';\nimport { type SQL, sql } from '../sql.ts';\n\ntype Configuration =\n\t| 'simple'\n\t| 'arabic'\n\t| 'armenian'\n\t| 'basque'\n\t| 'catalan'\n\t| 'danish'\n\t| 'dutch'\n\t| 'english'\n\t| 'finnish'\n\t| 'french'\n\t| 'german'\n\t| 'greek'\n\t| 'hindi'\n\t| 'hungarian'\n\t| 'indonesian'\n\t| 'irish'\n\t| 'italian'\n\t| 'lithuanian'\n\t| 'nepali'\n\t| 'norwegian'\n\t| 'portuguese'\n\t| 'romanian'\n\t| 'serbian'\n\t| 'spanish'\n\t| 'swedish'\n\t| 'tamil'\n\t| 'turkish'\n\t| 'yiddish';\n\ntype Weight = 'A' | 'B' | 'C' | 'D';\n\n/**\n * Converts a document to the `tsvector` data type.\n *\n * @param {AnyPgColumn | string} document - The document to be converted into `tsvector`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select({ value: to_tsvector(posts.title) }).from(posts);\n * ```\n */\nexport function to_tsvector(document: AnyPgColumn | string): SQL;\n/**\n * Converts a document to the `tsvector` data type.\n *\n * @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').\n * @param {AnyPgColumn | string} document - The document to be converted into `tsvector`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select({ value: to_tsvector('english', posts.title) }).from(posts);\n * ```\n */\nexport function to_tsvector(configuration: Configuration | string & {}, document: AnyPgColumn | string): SQL;\nexport function to_tsvector(arg1: Configuration | AnyPgColumn | string & {}, arg2?: AnyPgColumn | string): SQL {\n\treturn arg2 ? sql`to_tsvector(${arg1}, ${arg2})` : sql`to_tsvector(${arg1})`;\n}\n\n/**\n * Converts a query to the `tsquery` data type.\n *\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${to_tsquery('Drizzle')}`);\n * ```\n */\nexport function to_tsquery(query: string): SQL;\n/**\n * Converts a query to the `tsquery` data type.\n *\n * @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${to_tsquery('english', 'Drizzle')}`);\n * ```\n */\nexport function to_tsquery(configuration: Configuration | string & {}, query: string): SQL;\nexport function to_tsquery(arg1: Configuration | string & {}, arg2?: string): SQL {\n\treturn arg2 ? sql`to_tsquery(${arg1}, ${arg2})` : sql`to_tsquery(${arg1})`;\n}\n\n/**\n * Converts a query to the `tsquery` data type.\n *\n * The text is parsed and normalized much as for `to_tsvector`, then the `&` (AND) tsquery operator is inserted between surviving words.\n *\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${plainto_tsquery('PostgreSQL MySQL SQLite')}`);\n * ```\n */\nexport function plainto_tsquery(query: string): SQL;\n/**\n * Converts a query to the `tsquery` data type.\n *\n * The text is parsed and normalized much as for `to_tsvector`, then the `&` (AND) tsquery operator is inserted between surviving words.\n *\n * @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${plainto_tsquery('english', 'PostgreSQL MySQL SQLite')}`);\n * ```\n */\nexport function plainto_tsquery(configuration: Configuration | string & {}, query: string): SQL;\nexport function plainto_tsquery(arg1: Configuration | string & {}, arg2?: string): SQL {\n\treturn arg2 ? sql`plainto_tsquery(${arg1}, ${arg2})` : sql`plainto_tsquery(${arg1})`;\n}\n\n/**\n * Converts a query to the `tsquery` data type.\n *\n * `phraseto_tsquery` behaves much like `plainto_tsquery`, except that it inserts the `<->` (FOLLOWED BY) operator between surviving words instead of the `&` (AND) operator.\n *\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${phraseto_tsquery('Drizzle best practice')}`);\n * ```\n */\nexport function phraseto_tsquery(query: string): SQL;\n/**\n * Converts a query to the `tsquery` data type.\n *\n * `phraseto_tsquery` behaves much like `plainto_tsquery`, except that it inserts the `<->` (FOLLOWED BY) operator between surviving words instead of the `&` (AND) operator.\n *\n * @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${phraseto_tsquery('english', 'Drizzle best practice')}`);\n * ```\n */\nexport function phraseto_tsquery(configuration: Configuration | string & {}, query: string): SQL;\nexport function phraseto_tsquery(arg1: Configuration | string & {}, arg2?: string): SQL {\n\treturn arg2 ? sql`phraseto_tsquery(${arg1}, ${arg2})` : sql`phraseto_tsquery(${arg1})`;\n}\n\n/**\n * Converts a query to the `tsquery` data type.\n *\n * `websearch_to_tsquery` creates a `tsquery` value from querytext using an alternative syntax in which simple unformatted text is a valid query. Unlike `plainto_tsquery` and `phraseto_tsquery`, it also recognizes certain operators. Moreover, this function will never raise syntax errors, which makes it possible to use raw user-supplied input for search.\n *\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector(posts.title)} @@ ${websearch_to_tsquery('tips or updates Drizzle')}`);\n * ```\n */\nexport function websearch_to_tsquery(query: string): SQL;\n/**\n * Converts a query to the `tsquery` data type.\n *\n * `websearch_to_tsquery` creates a `tsquery` value from querytext using an alternative syntax in which simple unformatted text is a valid query. Unlike `plainto_tsquery` and `phraseto_tsquery`, it also recognizes certain operators. Moreover, this function will never raise syntax errors, which makes it possible to use raw user-supplied input for search.\n *\n * @param {Configuration | string} configuration - Text search configuration (e.g., 'english', 'simple').\n * @param {string} query - The text to be converted into `tsquery`.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * await db.select().from(posts).where(sql`${to_tsvector('english', posts.title)} @@ ${websearch_to_tsquery('english', 'tips or updates Drizzle')}`);\n * ```\n */\nexport function websearch_to_tsquery(configuration: Configuration | string & {}, query: string): SQL;\nexport function websearch_to_tsquery(arg1: Configuration | string & {}, arg2?: string): SQL {\n\treturn arg2 ? sql`websearch_to_tsquery(${arg1}, ${arg2})` : sql`websearch_to_tsquery(${arg1})`;\n}\n\n/**\n * Calculates the text search rank of a document represented by a `tsvector` against a `tsquery`.\n *\n * @param {SQL} vector - The `tsvector` representation of the document.\n * @param {SQL} query - The `tsquery` to compare against the vector.\n * @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * const vector = to_tsvector('english', posts.title);\n * const query = to_tsquery('english', 'Drizzle');\n * const rank = ts_rank(vector, query);\n *\n * await db.select({ post: posts, rank }).from(posts).where(gt(rank, 0));\n * ```\n */\nexport function ts_rank(vector: SQL, query: SQL, normalization?: number): SQL;\n/**\n * Calculates the text search rank of a document represented by a `tsvector` against a `tsquery`, using weights.\n *\n * @param {number[]} weights - Array of weights applied to the document's components.\n * @param {SQL} vector - The `tsvector` representation of the document.\n * @param {SQL} query - The `tsquery` to compare against the vector.\n * @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * const weights = [0.1, 0.2, 0.4, 0.3];\n * const vector = to_tsvector('english', posts.title);\n * const query = to_tsquery('english', 'Drizzle');\n * const rank = ts_rank(weights, vector, query);\n *\n * await db.select({ post: posts, rank }).from(posts).where(gt(rank, 0));\n * ```\n */\nexport function ts_rank(weights: number[], vector: SQL, query: SQL, normalization?: number): SQL;\nexport function ts_rank(arg1: number[] | SQL, arg2: SQL | number, arg3?: SQL | number, arg4?: number): SQL {\n\tif (Array.isArray(arg1) && typeof arg2 !== 'number' && arg3 !== undefined) {\n\t\treturn arg4\n\t\t\t? sql`ts_rank(string_to_array(${arg1.join(',')}, ',')::float4[], ${arg2}, ${arg3}, ${arg4})`\n\t\t\t: sql`ts_rank(string_to_array(${arg1.join(',')}, ',')::float4[], ${arg2}, ${arg3})`;\n\t} else {\n\t\treturn arg3 ? sql`ts_rank(${arg1}, ${arg2}, ${arg3})` : sql`ts_rank(${arg1}, ${arg2})`;\n\t}\n}\n\n/**\n * Calculates the text search rank of a document with cover density ranking, represented by a `tsvector` against a `tsquery`.\n *\n * @param {SQL} vector - The `tsvector` representation of the document.\n * @param {SQL} query - The `tsquery` to compare against the vector.\n * @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * const vector = to_tsvector('english', posts.title);\n * const query = to_tsquery('english', 'Drizzle');\n * const rankCd = ts_rank_cd(vector, query);\n *\n * await db.select({ post: posts, rankCd }).from(posts).where(gt(rankCd, 0));\n * ```\n */\nexport function ts_rank_cd(vector: SQL, query: SQL, normalization?: number): SQL;\n/**\n * Calculates the text search rank of a document represented by a `tsvector` against a `tsquery`, using weights.\n *\n * @param {number[]} weights - Array of weights applied to the document's components.\n * @param {SQL} vector - The `tsvector` representation of the document.\n * @param {SQL} query - The `tsquery` to compare against the vector.\n * @param {number} [normalization] - Optional normalization parameter. Specifies whether and how a document's length should impact its rank.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * const weights = [0.1, 0.2, 0.4, 0.3];\n * const vector = to_tsvector('english', posts.title);\n * const query = to_tsquery('english', 'Drizzle');\n * const rankCd = ts_rank_cd(weights, vector, query);\n *\n * await db.select({ post: posts, rankCd }).from(posts).where(gt(rankCd, 0));\n * ```\n */\nexport function ts_rank_cd(weights: number[], vector: SQL, query: SQL, normalization?: number): SQL;\nexport function ts_rank_cd(arg1: number[] | SQL, arg2: SQL | number, arg3?: SQL | number, arg4?: number): SQL {\n\tif (Array.isArray(arg1) && typeof arg2 !== 'number' && arg3 !== undefined) {\n\t\treturn arg4\n\t\t\t? sql`ts_rank_cd(string_to_array(${arg1.join(',')}, ',')::float4[], ${arg2}, ${arg3}, ${arg4})`\n\t\t\t: sql`ts_rank_cd(string_to_array(${arg1.join(',')}, ',')::float4[], ${arg2}, ${arg3})`;\n\t} else {\n\t\treturn arg3 ? sql`ts_rank_cd(${arg1}, ${arg2}, ${arg3})` : sql`ts_rank_cd(${arg1}, ${arg2})`;\n\t}\n}\n\n/**\n * Used to label the entries of a `tsvector` with a given weight, where a weight is one of the letters A, B, C, or D.\n *\n * @param {SQL} vector - The `tsvector` representation of the document.\n * @param {Weight} weight - The weight to be assigned to the elements of the vector.\n * @returns {SQL}\n *\n * @example\n * ```ts\n * const weightedVectorTitle = setweight(to_tsvector('english', posts.title), 'A');\n * const weightedVectorDescription = setweight(to_tsvector('english', posts.description), 'B');\n * const query = to_tsquery('english', 'Drizzle');\n *\n * await db.select().from(posts).where(sql`(${weightedVectorTitle} || ${weightedVectorDescription}) @@ ${query}`);\n * ```\n */\nexport function setweight(vector: SQL, weight: Weight | string & {}): SQL {\n\treturn sql`setweight(${vector}, ${weight})`;\n}\n"],"mappings":"AACA,SAAmB,WAAW;AA2DvB,SAAS,YAAY,MAAiD,MAAkC;AAC9G,SAAO,OAAO,kBAAkB,IAAI,KAAK,IAAI,MAAM,kBAAkB,IAAI;AAC1E;AA2BO,SAAS,WAAW,MAAmC,MAAoB;AACjF,SAAO,OAAO,iBAAiB,IAAI,KAAK,IAAI,MAAM,iBAAiB,IAAI;AACxE;AA+BO,SAAS,gBAAgB,MAAmC,MAAoB;AACtF,SAAO,OAAO,sBAAsB,IAAI,KAAK,IAAI,MAAM,sBAAsB,IAAI;AAClF;AA+BO,SAAS,iBAAiB,MAAmC,MAAoB;AACvF,SAAO,OAAO,uBAAuB,IAAI,KAAK,IAAI,MAAM,uBAAuB,IAAI;AACpF;AA+BO,SAAS,qBAAqB,MAAmC,MAAoB;AAC3F,SAAO,OAAO,2BAA2B,IAAI,KAAK,IAAI,MAAM,2BAA2B,IAAI;AAC5F;AAwCO,SAAS,QAAQ,MAAsB,MAAoB,MAAqB,MAAoB;AAC1G,MAAI,MAAM,QAAQ,IAAI,KAAK,OAAO,SAAS,YAAY,SAAS,QAAW;AAC1E,WAAO,OACJ,8BAA8B,KAAK,KAAK,GAAG,CAAC,qBAAqB,IAAI,KAAK,IAAI,KAAK,IAAI,MACvF,8BAA8B,KAAK,KAAK,GAAG,CAAC,qBAAqB,IAAI,KAAK,IAAI;AAAA,EAClF,OAAO;AACN,WAAO,OAAO,cAAc,IAAI,KAAK,IAAI,KAAK,IAAI,MAAM,cAAc,IAAI,KAAK,IAAI;AAAA,EACpF;AACD;AAwCO,SAAS,WAAW,MAAsB,MAAoB,MAAqB,MAAoB;AAC7G,MAAI,MAAM,QAAQ,IAAI,KAAK,OAAO,SAAS,YAAY,SAAS,QAAW;AAC1E,WAAO,OACJ,iCAAiC,KAAK,KAAK,GAAG,CAAC,qBAAqB,IAAI,KAAK,IAAI,KAAK,IAAI,MAC1F,iCAAiC,KAAK,KAAK,GAAG,CAAC,qBAAqB,IAAI,KAAK,IAAI;AAAA,EACrF,OAAO;AACN,WAAO,OAAO,iBAAiB,IAAI,KAAK,IAAI,KAAK,IAAI,MAAM,iBAAiB,IAAI,KAAK,IAAI;AAAA,EAC1F;AACD;AAkBO,SAAS,UAAU,QAAa,QAAmC;AACzE,SAAO,gBAAgB,MAAM,KAAK,MAAM;AACzC;","names":[]}
|
package/sql/functions/index.cjs
CHANGED
|
@@ -16,10 +16,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var functions_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(functions_exports);
|
|
18
18
|
__reExport(functions_exports, require("./aggregate.cjs"), module.exports);
|
|
19
|
+
__reExport(functions_exports, require("./full-text-search.cjs"), module.exports);
|
|
19
20
|
__reExport(functions_exports, require("./vector.cjs"), module.exports);
|
|
20
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
22
|
0 && (module.exports = {
|
|
22
23
|
...require("./aggregate.cjs"),
|
|
24
|
+
...require("./full-text-search.cjs"),
|
|
23
25
|
...require("./vector.cjs")
|
|
24
26
|
});
|
|
25
27
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\nexport * from './vector.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,2BAAd;AACA,8BAAc,
|
|
1
|
+
{"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\nexport * from './full-text-search.ts';\nexport * from './vector.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,2BAAd;AACA,8BAAc,kCADd;AAEA,8BAAc,wBAFd;","names":[]}
|
package/sql/functions/index.d.ts
CHANGED
package/sql/functions/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\nexport * from './vector.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\nexport * from './full-text-search.ts';\nexport * from './vector.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -20,6 +20,8 @@ var text_exports = {};
|
|
|
20
20
|
__export(text_exports, {
|
|
21
21
|
SQLiteText: () => SQLiteText,
|
|
22
22
|
SQLiteTextBuilder: () => SQLiteTextBuilder,
|
|
23
|
+
SQLiteTextDate: () => SQLiteTextDate,
|
|
24
|
+
SQLiteTextDateBuilder: () => SQLiteTextDateBuilder,
|
|
23
25
|
SQLiteTextJson: () => SQLiteTextJson,
|
|
24
26
|
SQLiteTextJsonBuilder: () => SQLiteTextJsonBuilder,
|
|
25
27
|
text: () => text
|
|
@@ -50,6 +52,31 @@ class SQLiteText extends import_common.SQLiteColumn {
|
|
|
50
52
|
return `text${this.config.length ? `(${this.config.length})` : ""}`;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
55
|
+
class SQLiteTextDateBuilder extends import_common.SQLiteColumnBuilder {
|
|
56
|
+
static [import_entity.entityKind] = "SQLiteTextDateBuilder";
|
|
57
|
+
constructor(name) {
|
|
58
|
+
super(name, "date", "SQLiteTextDate");
|
|
59
|
+
}
|
|
60
|
+
/** @internal */
|
|
61
|
+
build(table) {
|
|
62
|
+
return new SQLiteTextDate(
|
|
63
|
+
table,
|
|
64
|
+
this.config
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class SQLiteTextDate extends import_common.SQLiteColumn {
|
|
69
|
+
static [import_entity.entityKind] = "SQLiteTextDate";
|
|
70
|
+
getSQLType() {
|
|
71
|
+
return "text";
|
|
72
|
+
}
|
|
73
|
+
mapFromDriverValue(value) {
|
|
74
|
+
return new Date(value);
|
|
75
|
+
}
|
|
76
|
+
mapToDriverValue(value) {
|
|
77
|
+
return value.toISOString();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
53
80
|
class SQLiteTextJsonBuilder extends import_common.SQLiteColumnBuilder {
|
|
54
81
|
static [import_entity.entityKind] = "SQLiteTextJsonBuilder";
|
|
55
82
|
constructor(name) {
|
|
@@ -76,12 +103,14 @@ class SQLiteTextJson extends import_common.SQLiteColumn {
|
|
|
76
103
|
}
|
|
77
104
|
}
|
|
78
105
|
function text(name, config = {}) {
|
|
79
|
-
return config.mode === "json" ? new SQLiteTextJsonBuilder(name) : new SQLiteTextBuilder(name, config);
|
|
106
|
+
return config.mode === "json" ? new SQLiteTextJsonBuilder(name) : config.mode === "date" ? new SQLiteTextDateBuilder(name) : new SQLiteTextBuilder(name, config);
|
|
80
107
|
}
|
|
81
108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
109
|
0 && (module.exports = {
|
|
83
110
|
SQLiteText,
|
|
84
111
|
SQLiteTextBuilder,
|
|
112
|
+
SQLiteTextDate,
|
|
113
|
+
SQLiteTextDateBuilder,
|
|
85
114
|
SQLiteTextJson,
|
|
86
115
|
SQLiteTextJsonBuilder,
|
|
87
116
|
text
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/columns/text.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Equal, Writable } from '~/utils.ts';\nimport { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';\n\nexport type SQLiteTextBuilderInitial<TName extends string, TEnum extends [string, ...string[]]> = SQLiteTextBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SQLiteText';\n\tdata: TEnum[number];\n\tdriverParam: string;\n\tenumValues: TEnum;\n}>;\n\nexport class SQLiteTextBuilder<T extends ColumnBuilderBaseConfig<'string', 'SQLiteText'>> extends SQLiteColumnBuilder<\n\tT,\n\t{ length: number | undefined; enumValues: T['enumValues'] }\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteTextBuilder';\n\n\tconstructor(name: T['name'], config: SQLiteTextConfig<'text', T['enumValues']>) {\n\t\tsuper(name, 'string', 'SQLiteText');\n\t\tthis.config.enumValues = config.enum;\n\t\tthis.config.length = config.length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteText<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteText<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class SQLiteText<T extends ColumnBaseConfig<'string', 'SQLiteText'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteText';\n\n\toverride readonly enumValues = this.config.enumValues;\n\n\treadonly length: number | undefined = this.config.length;\n\n\tconstructor(\n\t\ttable: AnySQLiteTable<{ name: T['tableName'] }>,\n\t\tconfig: SQLiteTextBuilder<T>['config'],\n\t) {\n\t\tsuper(table, config);\n\t}\n\n\tgetSQLType(): string {\n\t\treturn `text${this.config.length ? `(${this.config.length})` : ''}`;\n\t}\n}\n\nexport type SQLiteTextJsonBuilderInitial<TName extends string> = SQLiteTextJsonBuilder<{\n\tname: TName;\n\tdataType: 'json';\n\tcolumnType: 'SQLiteTextJson';\n\tdata: unknown;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class SQLiteTextJsonBuilder<T extends ColumnBuilderBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumnBuilder<T>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJsonBuilder';\n\n\tconstructor(name: T['name']) {\n\t\tsuper(name, 'json', 'SQLiteTextJson');\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteTextJson<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteTextJson<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteTextJson<T extends ColumnBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJson';\n\n\tgetSQLType(): string {\n\t\treturn 'text';\n\t}\n\n\toverride mapFromDriverValue(value: string): T['data'] {\n\t\treturn JSON.parse(value);\n\t}\n\n\toverride mapToDriverValue(value: T['data']): string {\n\t\treturn JSON.stringify(value);\n\t}\n}\n\nexport type SQLiteTextConfig<\n\tTMode extends 'text' | 'json',\n\tTEnum extends readonly string[] | string[] | undefined,\n> = TMode extends 'text' ? {\n\t\tmode?: TMode;\n\t\tlength?: number;\n\t\tenum?: TEnum;\n\t}\n\t: {\n\t\tmode?: TMode;\n\t};\n\nexport function text<\n\tTName extends string,\n\tU extends string,\n\tT extends Readonly<[U, ...U[]]>,\n\tTMode extends 'text' | 'json' = 'text' | 'json',\n>(\n\tname: TName,\n\tconfig: SQLiteTextConfig<TMode, T | Writable<T>> = {} as SQLiteTextConfig<TMode, T | Writable<T>>,\n): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName>\n\t: SQLiteTextBuilderInitial<TName, Writable<T>>\n{\n\treturn (config.mode === 'json'\n\t\t? new SQLiteTextJsonBuilder(name)\n\t\t: new SQLiteTextBuilder(name, config as SQLiteTextConfig<'text', Writable<T>>)) as Equal<TMode, 'json'> extends true\n\t\t\t? SQLiteTextJsonBuilderInitial<TName>\n\t\t\t: SQLiteTextBuilderInitial<TName, Writable<T>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAG3B,oBAAkD;AAW3C,MAAM,0BAAqF,kCAGhG;AAAA,EACD,QAAiB,wBAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB,QAAmD;AAC/E,UAAM,MAAM,UAAU,YAAY;AAClC,SAAK,OAAO,aAAa,OAAO;AAChC,SAAK,OAAO,SAAS,OAAO;AAAA,EAC7B;AAAA;AAAA,EAGS,MACR,OAC8C;AAC9C,WAAO,IAAI,WAA4C,OAAO,KAAK,MAA8C;AAAA,EAClH;AACD;AAEO,MAAM,mBACJ,2BACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAErB,aAAa,KAAK,OAAO;AAAA,EAElC,SAA6B,KAAK,OAAO;AAAA,EAElD,YACC,OACA,QACC;AACD,UAAM,OAAO,MAAM;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,WAAO,OAAO,KAAK,OAAO,SAAS,IAAI,KAAK,OAAO,MAAM,MAAM,EAAE;AAAA,EAClE;AACD;AAWO,MAAM,8BACJ,kCACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AAAA,EACrC;AAAA;AAAA,EAGS,MACR,OACkD;AAClD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,uBACJ,2BACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAEvC,aAAqB;AACpB,WAAO;AAAA,EACR;AAAA,EAES,mBAAmB,OAA0B;AACrD,WAAO,KAAK,MAAM,KAAK;AAAA,EACxB;AAAA,EAES,iBAAiB,OAA0B;AACnD,WAAO,KAAK,UAAU,KAAK;AAAA,EAC5B;AACD;AAcO,SAAS,KAMf,MACA,SAAmD,CAAC,
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/columns/text.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Equal, Writable } from '~/utils.ts';\nimport { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';\n\nexport type SQLiteTextBuilderInitial<TName extends string, TEnum extends [string, ...string[]]> = SQLiteTextBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SQLiteText';\n\tdata: TEnum[number];\n\tdriverParam: string;\n\tenumValues: TEnum;\n}>;\n\nexport class SQLiteTextBuilder<T extends ColumnBuilderBaseConfig<'string', 'SQLiteText'>> extends SQLiteColumnBuilder<\n\tT,\n\t{ length: number | undefined; enumValues: T['enumValues'] }\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteTextBuilder';\n\n\tconstructor(name: T['name'], config: SQLiteTextConfig<'text', T['enumValues']>) {\n\t\tsuper(name, 'string', 'SQLiteText');\n\t\tthis.config.enumValues = config.enum;\n\t\tthis.config.length = config.length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteText<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteText<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class SQLiteText<T extends ColumnBaseConfig<'string', 'SQLiteText'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteText';\n\n\toverride readonly enumValues = this.config.enumValues;\n\n\treadonly length: number | undefined = this.config.length;\n\n\tconstructor(\n\t\ttable: AnySQLiteTable<{ name: T['tableName'] }>,\n\t\tconfig: SQLiteTextBuilder<T>['config'],\n\t) {\n\t\tsuper(table, config);\n\t}\n\n\tgetSQLType(): string {\n\t\treturn `text${this.config.length ? `(${this.config.length})` : ''}`;\n\t}\n}\n\nexport type SQLiteTextDateBuilderInitial<TName extends string> = SQLiteTextDateBuilder<{\n\tname: TName;\n\tdataType: 'date';\n\tcolumnType: 'SQLiteTextDate';\n\tdata: Date;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class SQLiteTextDateBuilder<T extends ColumnBuilderBaseConfig<'date', 'SQLiteTextDate'>>\n\textends SQLiteColumnBuilder<T>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextDateBuilder';\n\n\tconstructor(name: T['name']) {\n\t\tsuper(name, 'date', 'SQLiteTextDate');\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteTextDate<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteTextDate<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteTextDate<T extends ColumnBaseConfig<'date', 'SQLiteTextDate'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextDate';\n\n\tgetSQLType(): string {\n\t\treturn 'text';\n\t}\n\n\toverride mapFromDriverValue(value: string): Date {\n\t\treturn new Date(value);\n\t}\n\n\toverride mapToDriverValue(value: Date): string {\n\t\treturn value.toISOString();\n\t}\n}\n\nexport type SQLiteTextJsonBuilderInitial<TName extends string> = SQLiteTextJsonBuilder<{\n\tname: TName;\n\tdataType: 'json';\n\tcolumnType: 'SQLiteTextJson';\n\tdata: unknown;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class SQLiteTextJsonBuilder<T extends ColumnBuilderBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumnBuilder<T>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJsonBuilder';\n\n\tconstructor(name: T['name']) {\n\t\tsuper(name, 'json', 'SQLiteTextJson');\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteTextJson<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteTextJson<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteTextJson<T extends ColumnBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJson';\n\n\tgetSQLType(): string {\n\t\treturn 'text';\n\t}\n\n\toverride mapFromDriverValue(value: string): T['data'] {\n\t\treturn JSON.parse(value);\n\t}\n\n\toverride mapToDriverValue(value: T['data']): string {\n\t\treturn JSON.stringify(value);\n\t}\n}\n\nexport type SQLiteTextConfig<\n\tTMode extends 'text' | 'json' | 'date',\n\tTEnum extends readonly string[] | string[] | undefined,\n> = TMode extends 'text' ? {\n\t\tmode?: TMode;\n\t\tlength?: number;\n\t\tenum?: TEnum;\n\t}\n\t: {\n\t\tmode?: TMode;\n\t};\n\nexport function text<\n\tTName extends string,\n\tU extends string,\n\tT extends Readonly<[U, ...U[]]>,\n\tTMode extends 'text' | 'json' | 'date' = 'text' | 'json' | 'date',\n>(\n\tname: TName,\n\tconfig: SQLiteTextConfig<TMode, T | Writable<T>> = {} as SQLiteTextConfig<TMode, T | Writable<T>>,\n): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName>\n\t: Equal<TMode, 'date'> extends true ? SQLiteTextDateBuilderInitial<TName>\n\t: SQLiteTextBuilderInitial<TName, Writable<T>>\n{\n\treturn (config.mode === 'json'\n\t\t? new SQLiteTextJsonBuilder(name)\n\t\t: config.mode === 'date'\n\t\t? new SQLiteTextDateBuilder(name)\n\t\t: new SQLiteTextBuilder(name, config as SQLiteTextConfig<'text', Writable<T>>)) as Equal<TMode, 'json'> extends true\n\t\t\t? SQLiteTextJsonBuilderInitial<TName>\n\t\t\t: Equal<TMode, 'date'> extends true ? SQLiteTextDateBuilderInitial<TName>\n\t\t\t: SQLiteTextBuilderInitial<TName, Writable<T>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAG3B,oBAAkD;AAW3C,MAAM,0BAAqF,kCAGhG;AAAA,EACD,QAAiB,wBAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB,QAAmD;AAC/E,UAAM,MAAM,UAAU,YAAY;AAClC,SAAK,OAAO,aAAa,OAAO;AAChC,SAAK,OAAO,SAAS,OAAO;AAAA,EAC7B;AAAA;AAAA,EAGS,MACR,OAC8C;AAC9C,WAAO,IAAI,WAA4C,OAAO,KAAK,MAA8C;AAAA,EAClH;AACD;AAEO,MAAM,mBACJ,2BACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAErB,aAAa,KAAK,OAAO;AAAA,EAElC,SAA6B,KAAK,OAAO;AAAA,EAElD,YACC,OACA,QACC;AACD,UAAM,OAAO,MAAM;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,WAAO,OAAO,KAAK,OAAO,SAAS,IAAI,KAAK,OAAO,MAAM,MAAM,EAAE;AAAA,EAClE;AACD;AAWO,MAAM,8BACJ,kCACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AAAA,EACrC;AAAA;AAAA,EAGS,MACR,OACkD;AAClD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,uBACJ,2BACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAEvC,aAAqB;AACpB,WAAO;AAAA,EACR;AAAA,EAES,mBAAmB,OAAqB;AAChD,WAAO,IAAI,KAAK,KAAK;AAAA,EACtB;AAAA,EAES,iBAAiB,OAAqB;AAC9C,WAAO,MAAM,YAAY;AAAA,EAC1B;AACD;AAWO,MAAM,8BACJ,kCACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AAAA,EACrC;AAAA;AAAA,EAGS,MACR,OACkD;AAClD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,uBACJ,2BACT;AAAA,EACC,QAAiB,wBAAU,IAAY;AAAA,EAEvC,aAAqB;AACpB,WAAO;AAAA,EACR;AAAA,EAES,mBAAmB,OAA0B;AACrD,WAAO,KAAK,MAAM,KAAK;AAAA,EACxB;AAAA,EAES,iBAAiB,OAA0B;AACnD,WAAO,KAAK,UAAU,KAAK;AAAA,EAC5B;AACD;AAcO,SAAS,KAMf,MACA,SAAmD,CAAC,GAIrD;AACC,SAAQ,OAAO,SAAS,SACrB,IAAI,sBAAsB,IAAI,IAC9B,OAAO,SAAS,SAChB,IAAI,sBAAsB,IAAI,IAC9B,IAAI,kBAAkB,MAAM,MAA+C;AAI/E;","names":[]}
|
|
@@ -31,6 +31,27 @@ export declare class SQLiteText<T extends ColumnBaseConfig<'string', 'SQLiteText
|
|
|
31
31
|
}>, config: SQLiteTextBuilder<T>['config']);
|
|
32
32
|
getSQLType(): string;
|
|
33
33
|
}
|
|
34
|
+
export type SQLiteTextDateBuilderInitial<TName extends string> = SQLiteTextDateBuilder<{
|
|
35
|
+
name: TName;
|
|
36
|
+
dataType: 'date';
|
|
37
|
+
columnType: 'SQLiteTextDate';
|
|
38
|
+
data: Date;
|
|
39
|
+
driverParam: string;
|
|
40
|
+
enumValues: undefined;
|
|
41
|
+
}>;
|
|
42
|
+
export declare class SQLiteTextDateBuilder<T extends ColumnBuilderBaseConfig<'date', 'SQLiteTextDate'>> extends SQLiteColumnBuilder<T> {
|
|
43
|
+
static readonly [entityKind]: string;
|
|
44
|
+
constructor(name: T['name']);
|
|
45
|
+
}
|
|
46
|
+
export declare class SQLiteTextDate<T extends ColumnBaseConfig<'date', 'SQLiteTextDate'>> extends SQLiteColumn<T, {
|
|
47
|
+
length: number | undefined;
|
|
48
|
+
enumValues: T['enumValues'];
|
|
49
|
+
}> {
|
|
50
|
+
static readonly [entityKind]: string;
|
|
51
|
+
getSQLType(): string;
|
|
52
|
+
mapFromDriverValue(value: string): Date;
|
|
53
|
+
mapToDriverValue(value: Date): string;
|
|
54
|
+
}
|
|
34
55
|
export type SQLiteTextJsonBuilderInitial<TName extends string> = SQLiteTextJsonBuilder<{
|
|
35
56
|
name: TName;
|
|
36
57
|
dataType: 'json';
|
|
@@ -52,11 +73,11 @@ export declare class SQLiteTextJson<T extends ColumnBaseConfig<'json', 'SQLiteTe
|
|
|
52
73
|
mapFromDriverValue(value: string): T['data'];
|
|
53
74
|
mapToDriverValue(value: T['data']): string;
|
|
54
75
|
}
|
|
55
|
-
export type SQLiteTextConfig<TMode extends 'text' | 'json', TEnum extends readonly string[] | string[] | undefined> = TMode extends 'text' ? {
|
|
76
|
+
export type SQLiteTextConfig<TMode extends 'text' | 'json' | 'date', TEnum extends readonly string[] | string[] | undefined> = TMode extends 'text' ? {
|
|
56
77
|
mode?: TMode;
|
|
57
78
|
length?: number;
|
|
58
79
|
enum?: TEnum;
|
|
59
80
|
} : {
|
|
60
81
|
mode?: TMode;
|
|
61
82
|
};
|
|
62
|
-
export declare function text<TName extends string, U extends string, T extends Readonly<[U, ...U[]]>, TMode extends 'text' | 'json' = 'text' | 'json'>(name: TName, config?: SQLiteTextConfig<TMode, T | Writable<T>>): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName> : SQLiteTextBuilderInitial<TName, Writable<T>>;
|
|
83
|
+
export declare function text<TName extends string, U extends string, T extends Readonly<[U, ...U[]]>, TMode extends 'text' | 'json' | 'date' = 'text' | 'json' | 'date'>(name: TName, config?: SQLiteTextConfig<TMode, T | Writable<T>>): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName> : Equal<TMode, 'date'> extends true ? SQLiteTextDateBuilderInitial<TName> : SQLiteTextBuilderInitial<TName, Writable<T>>;
|
|
@@ -31,6 +31,27 @@ export declare class SQLiteText<T extends ColumnBaseConfig<'string', 'SQLiteText
|
|
|
31
31
|
}>, config: SQLiteTextBuilder<T>['config']);
|
|
32
32
|
getSQLType(): string;
|
|
33
33
|
}
|
|
34
|
+
export type SQLiteTextDateBuilderInitial<TName extends string> = SQLiteTextDateBuilder<{
|
|
35
|
+
name: TName;
|
|
36
|
+
dataType: 'date';
|
|
37
|
+
columnType: 'SQLiteTextDate';
|
|
38
|
+
data: Date;
|
|
39
|
+
driverParam: string;
|
|
40
|
+
enumValues: undefined;
|
|
41
|
+
}>;
|
|
42
|
+
export declare class SQLiteTextDateBuilder<T extends ColumnBuilderBaseConfig<'date', 'SQLiteTextDate'>> extends SQLiteColumnBuilder<T> {
|
|
43
|
+
static readonly [entityKind]: string;
|
|
44
|
+
constructor(name: T['name']);
|
|
45
|
+
}
|
|
46
|
+
export declare class SQLiteTextDate<T extends ColumnBaseConfig<'date', 'SQLiteTextDate'>> extends SQLiteColumn<T, {
|
|
47
|
+
length: number | undefined;
|
|
48
|
+
enumValues: T['enumValues'];
|
|
49
|
+
}> {
|
|
50
|
+
static readonly [entityKind]: string;
|
|
51
|
+
getSQLType(): string;
|
|
52
|
+
mapFromDriverValue(value: string): Date;
|
|
53
|
+
mapToDriverValue(value: Date): string;
|
|
54
|
+
}
|
|
34
55
|
export type SQLiteTextJsonBuilderInitial<TName extends string> = SQLiteTextJsonBuilder<{
|
|
35
56
|
name: TName;
|
|
36
57
|
dataType: 'json';
|
|
@@ -52,11 +73,11 @@ export declare class SQLiteTextJson<T extends ColumnBaseConfig<'json', 'SQLiteTe
|
|
|
52
73
|
mapFromDriverValue(value: string): T['data'];
|
|
53
74
|
mapToDriverValue(value: T['data']): string;
|
|
54
75
|
}
|
|
55
|
-
export type SQLiteTextConfig<TMode extends 'text' | 'json', TEnum extends readonly string[] | string[] | undefined> = TMode extends 'text' ? {
|
|
76
|
+
export type SQLiteTextConfig<TMode extends 'text' | 'json' | 'date', TEnum extends readonly string[] | string[] | undefined> = TMode extends 'text' ? {
|
|
56
77
|
mode?: TMode;
|
|
57
78
|
length?: number;
|
|
58
79
|
enum?: TEnum;
|
|
59
80
|
} : {
|
|
60
81
|
mode?: TMode;
|
|
61
82
|
};
|
|
62
|
-
export declare function text<TName extends string, U extends string, T extends Readonly<[U, ...U[]]>, TMode extends 'text' | 'json' = 'text' | 'json'>(name: TName, config?: SQLiteTextConfig<TMode, T | Writable<T>>): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName> : SQLiteTextBuilderInitial<TName, Writable<T>>;
|
|
83
|
+
export declare function text<TName extends string, U extends string, T extends Readonly<[U, ...U[]]>, TMode extends 'text' | 'json' | 'date' = 'text' | 'json' | 'date'>(name: TName, config?: SQLiteTextConfig<TMode, T | Writable<T>>): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName> : Equal<TMode, 'date'> extends true ? SQLiteTextDateBuilderInitial<TName> : SQLiteTextBuilderInitial<TName, Writable<T>>;
|
|
@@ -23,6 +23,31 @@ class SQLiteText extends SQLiteColumn {
|
|
|
23
23
|
return `text${this.config.length ? `(${this.config.length})` : ""}`;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
class SQLiteTextDateBuilder extends SQLiteColumnBuilder {
|
|
27
|
+
static [entityKind] = "SQLiteTextDateBuilder";
|
|
28
|
+
constructor(name) {
|
|
29
|
+
super(name, "date", "SQLiteTextDate");
|
|
30
|
+
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
build(table) {
|
|
33
|
+
return new SQLiteTextDate(
|
|
34
|
+
table,
|
|
35
|
+
this.config
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class SQLiteTextDate extends SQLiteColumn {
|
|
40
|
+
static [entityKind] = "SQLiteTextDate";
|
|
41
|
+
getSQLType() {
|
|
42
|
+
return "text";
|
|
43
|
+
}
|
|
44
|
+
mapFromDriverValue(value) {
|
|
45
|
+
return new Date(value);
|
|
46
|
+
}
|
|
47
|
+
mapToDriverValue(value) {
|
|
48
|
+
return value.toISOString();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
26
51
|
class SQLiteTextJsonBuilder extends SQLiteColumnBuilder {
|
|
27
52
|
static [entityKind] = "SQLiteTextJsonBuilder";
|
|
28
53
|
constructor(name) {
|
|
@@ -49,11 +74,13 @@ class SQLiteTextJson extends SQLiteColumn {
|
|
|
49
74
|
}
|
|
50
75
|
}
|
|
51
76
|
function text(name, config = {}) {
|
|
52
|
-
return config.mode === "json" ? new SQLiteTextJsonBuilder(name) : new SQLiteTextBuilder(name, config);
|
|
77
|
+
return config.mode === "json" ? new SQLiteTextJsonBuilder(name) : config.mode === "date" ? new SQLiteTextDateBuilder(name) : new SQLiteTextBuilder(name, config);
|
|
53
78
|
}
|
|
54
79
|
export {
|
|
55
80
|
SQLiteText,
|
|
56
81
|
SQLiteTextBuilder,
|
|
82
|
+
SQLiteTextDate,
|
|
83
|
+
SQLiteTextDateBuilder,
|
|
57
84
|
SQLiteTextJson,
|
|
58
85
|
SQLiteTextJsonBuilder,
|
|
59
86
|
text
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/columns/text.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Equal, Writable } from '~/utils.ts';\nimport { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';\n\nexport type SQLiteTextBuilderInitial<TName extends string, TEnum extends [string, ...string[]]> = SQLiteTextBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SQLiteText';\n\tdata: TEnum[number];\n\tdriverParam: string;\n\tenumValues: TEnum;\n}>;\n\nexport class SQLiteTextBuilder<T extends ColumnBuilderBaseConfig<'string', 'SQLiteText'>> extends SQLiteColumnBuilder<\n\tT,\n\t{ length: number | undefined; enumValues: T['enumValues'] }\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteTextBuilder';\n\n\tconstructor(name: T['name'], config: SQLiteTextConfig<'text', T['enumValues']>) {\n\t\tsuper(name, 'string', 'SQLiteText');\n\t\tthis.config.enumValues = config.enum;\n\t\tthis.config.length = config.length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteText<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteText<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class SQLiteText<T extends ColumnBaseConfig<'string', 'SQLiteText'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteText';\n\n\toverride readonly enumValues = this.config.enumValues;\n\n\treadonly length: number | undefined = this.config.length;\n\n\tconstructor(\n\t\ttable: AnySQLiteTable<{ name: T['tableName'] }>,\n\t\tconfig: SQLiteTextBuilder<T>['config'],\n\t) {\n\t\tsuper(table, config);\n\t}\n\n\tgetSQLType(): string {\n\t\treturn `text${this.config.length ? `(${this.config.length})` : ''}`;\n\t}\n}\n\nexport type SQLiteTextJsonBuilderInitial<TName extends string> = SQLiteTextJsonBuilder<{\n\tname: TName;\n\tdataType: 'json';\n\tcolumnType: 'SQLiteTextJson';\n\tdata: unknown;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class SQLiteTextJsonBuilder<T extends ColumnBuilderBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumnBuilder<T>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJsonBuilder';\n\n\tconstructor(name: T['name']) {\n\t\tsuper(name, 'json', 'SQLiteTextJson');\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteTextJson<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteTextJson<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteTextJson<T extends ColumnBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJson';\n\n\tgetSQLType(): string {\n\t\treturn 'text';\n\t}\n\n\toverride mapFromDriverValue(value: string): T['data'] {\n\t\treturn JSON.parse(value);\n\t}\n\n\toverride mapToDriverValue(value: T['data']): string {\n\t\treturn JSON.stringify(value);\n\t}\n}\n\nexport type SQLiteTextConfig<\n\tTMode extends 'text' | 'json',\n\tTEnum extends readonly string[] | string[] | undefined,\n> = TMode extends 'text' ? {\n\t\tmode?: TMode;\n\t\tlength?: number;\n\t\tenum?: TEnum;\n\t}\n\t: {\n\t\tmode?: TMode;\n\t};\n\nexport function text<\n\tTName extends string,\n\tU extends string,\n\tT extends Readonly<[U, ...U[]]>,\n\tTMode extends 'text' | 'json' = 'text' | 'json',\n>(\n\tname: TName,\n\tconfig: SQLiteTextConfig<TMode, T | Writable<T>> = {} as SQLiteTextConfig<TMode, T | Writable<T>>,\n): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName>\n\t: SQLiteTextBuilderInitial<TName, Writable<T>>\n{\n\treturn (config.mode === 'json'\n\t\t? new SQLiteTextJsonBuilder(name)\n\t\t: new SQLiteTextBuilder(name, config as SQLiteTextConfig<'text', Writable<T>>)) as Equal<TMode, 'json'> extends true\n\t\t\t? SQLiteTextJsonBuilderInitial<TName>\n\t\t\t: SQLiteTextBuilderInitial<TName, Writable<T>>;\n}\n"],"mappings":"AAEA,SAAS,kBAAkB;AAG3B,SAAS,cAAc,2BAA2B;AAW3C,MAAM,0BAAqF,oBAGhG;AAAA,EACD,QAAiB,UAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB,QAAmD;AAC/E,UAAM,MAAM,UAAU,YAAY;AAClC,SAAK,OAAO,aAAa,OAAO;AAChC,SAAK,OAAO,SAAS,OAAO;AAAA,EAC7B;AAAA;AAAA,EAGS,MACR,OAC8C;AAC9C,WAAO,IAAI,WAA4C,OAAO,KAAK,MAA8C;AAAA,EAClH;AACD;AAEO,MAAM,mBACJ,aACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAErB,aAAa,KAAK,OAAO;AAAA,EAElC,SAA6B,KAAK,OAAO;AAAA,EAElD,YACC,OACA,QACC;AACD,UAAM,OAAO,MAAM;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,WAAO,OAAO,KAAK,OAAO,SAAS,IAAI,KAAK,OAAO,MAAM,MAAM,EAAE;AAAA,EAClE;AACD;AAWO,MAAM,8BACJ,oBACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AAAA,EACrC;AAAA;AAAA,EAGS,MACR,OACkD;AAClD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,uBACJ,aACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAEvC,aAAqB;AACpB,WAAO;AAAA,EACR;AAAA,EAES,mBAAmB,OAA0B;AACrD,WAAO,KAAK,MAAM,KAAK;AAAA,EACxB;AAAA,EAES,iBAAiB,OAA0B;AACnD,WAAO,KAAK,UAAU,KAAK;AAAA,EAC5B;AACD;AAcO,SAAS,KAMf,MACA,SAAmD,CAAC,
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/columns/text.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnySQLiteTable } from '~/sqlite-core/table.ts';\nimport type { Equal, Writable } from '~/utils.ts';\nimport { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';\n\nexport type SQLiteTextBuilderInitial<TName extends string, TEnum extends [string, ...string[]]> = SQLiteTextBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'SQLiteText';\n\tdata: TEnum[number];\n\tdriverParam: string;\n\tenumValues: TEnum;\n}>;\n\nexport class SQLiteTextBuilder<T extends ColumnBuilderBaseConfig<'string', 'SQLiteText'>> extends SQLiteColumnBuilder<\n\tT,\n\t{ length: number | undefined; enumValues: T['enumValues'] }\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteTextBuilder';\n\n\tconstructor(name: T['name'], config: SQLiteTextConfig<'text', T['enumValues']>) {\n\t\tsuper(name, 'string', 'SQLiteText');\n\t\tthis.config.enumValues = config.enum;\n\t\tthis.config.length = config.length;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteText<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteText<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class SQLiteText<T extends ColumnBaseConfig<'string', 'SQLiteText'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteText';\n\n\toverride readonly enumValues = this.config.enumValues;\n\n\treadonly length: number | undefined = this.config.length;\n\n\tconstructor(\n\t\ttable: AnySQLiteTable<{ name: T['tableName'] }>,\n\t\tconfig: SQLiteTextBuilder<T>['config'],\n\t) {\n\t\tsuper(table, config);\n\t}\n\n\tgetSQLType(): string {\n\t\treturn `text${this.config.length ? `(${this.config.length})` : ''}`;\n\t}\n}\n\nexport type SQLiteTextDateBuilderInitial<TName extends string> = SQLiteTextDateBuilder<{\n\tname: TName;\n\tdataType: 'date';\n\tcolumnType: 'SQLiteTextDate';\n\tdata: Date;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class SQLiteTextDateBuilder<T extends ColumnBuilderBaseConfig<'date', 'SQLiteTextDate'>>\n\textends SQLiteColumnBuilder<T>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextDateBuilder';\n\n\tconstructor(name: T['name']) {\n\t\tsuper(name, 'date', 'SQLiteTextDate');\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteTextDate<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteTextDate<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteTextDate<T extends ColumnBaseConfig<'date', 'SQLiteTextDate'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextDate';\n\n\tgetSQLType(): string {\n\t\treturn 'text';\n\t}\n\n\toverride mapFromDriverValue(value: string): Date {\n\t\treturn new Date(value);\n\t}\n\n\toverride mapToDriverValue(value: Date): string {\n\t\treturn value.toISOString();\n\t}\n}\n\nexport type SQLiteTextJsonBuilderInitial<TName extends string> = SQLiteTextJsonBuilder<{\n\tname: TName;\n\tdataType: 'json';\n\tcolumnType: 'SQLiteTextJson';\n\tdata: unknown;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class SQLiteTextJsonBuilder<T extends ColumnBuilderBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumnBuilder<T>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJsonBuilder';\n\n\tconstructor(name: T['name']) {\n\t\tsuper(name, 'json', 'SQLiteTextJson');\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnySQLiteTable<{ name: TTableName }>,\n\t): SQLiteTextJson<MakeColumnConfig<T, TTableName>> {\n\t\treturn new SQLiteTextJson<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class SQLiteTextJson<T extends ColumnBaseConfig<'json', 'SQLiteTextJson'>>\n\textends SQLiteColumn<T, { length: number | undefined; enumValues: T['enumValues'] }>\n{\n\tstatic readonly [entityKind]: string = 'SQLiteTextJson';\n\n\tgetSQLType(): string {\n\t\treturn 'text';\n\t}\n\n\toverride mapFromDriverValue(value: string): T['data'] {\n\t\treturn JSON.parse(value);\n\t}\n\n\toverride mapToDriverValue(value: T['data']): string {\n\t\treturn JSON.stringify(value);\n\t}\n}\n\nexport type SQLiteTextConfig<\n\tTMode extends 'text' | 'json' | 'date',\n\tTEnum extends readonly string[] | string[] | undefined,\n> = TMode extends 'text' ? {\n\t\tmode?: TMode;\n\t\tlength?: number;\n\t\tenum?: TEnum;\n\t}\n\t: {\n\t\tmode?: TMode;\n\t};\n\nexport function text<\n\tTName extends string,\n\tU extends string,\n\tT extends Readonly<[U, ...U[]]>,\n\tTMode extends 'text' | 'json' | 'date' = 'text' | 'json' | 'date',\n>(\n\tname: TName,\n\tconfig: SQLiteTextConfig<TMode, T | Writable<T>> = {} as SQLiteTextConfig<TMode, T | Writable<T>>,\n): Equal<TMode, 'json'> extends true ? SQLiteTextJsonBuilderInitial<TName>\n\t: Equal<TMode, 'date'> extends true ? SQLiteTextDateBuilderInitial<TName>\n\t: SQLiteTextBuilderInitial<TName, Writable<T>>\n{\n\treturn (config.mode === 'json'\n\t\t? new SQLiteTextJsonBuilder(name)\n\t\t: config.mode === 'date'\n\t\t? new SQLiteTextDateBuilder(name)\n\t\t: new SQLiteTextBuilder(name, config as SQLiteTextConfig<'text', Writable<T>>)) as Equal<TMode, 'json'> extends true\n\t\t\t? SQLiteTextJsonBuilderInitial<TName>\n\t\t\t: Equal<TMode, 'date'> extends true ? SQLiteTextDateBuilderInitial<TName>\n\t\t\t: SQLiteTextBuilderInitial<TName, Writable<T>>;\n}\n"],"mappings":"AAEA,SAAS,kBAAkB;AAG3B,SAAS,cAAc,2BAA2B;AAW3C,MAAM,0BAAqF,oBAGhG;AAAA,EACD,QAAiB,UAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB,QAAmD;AAC/E,UAAM,MAAM,UAAU,YAAY;AAClC,SAAK,OAAO,aAAa,OAAO;AAChC,SAAK,OAAO,SAAS,OAAO;AAAA,EAC7B;AAAA;AAAA,EAGS,MACR,OAC8C;AAC9C,WAAO,IAAI,WAA4C,OAAO,KAAK,MAA8C;AAAA,EAClH;AACD;AAEO,MAAM,mBACJ,aACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAErB,aAAa,KAAK,OAAO;AAAA,EAElC,SAA6B,KAAK,OAAO;AAAA,EAElD,YACC,OACA,QACC;AACD,UAAM,OAAO,MAAM;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,WAAO,OAAO,KAAK,OAAO,SAAS,IAAI,KAAK,OAAO,MAAM,MAAM,EAAE;AAAA,EAClE;AACD;AAWO,MAAM,8BACJ,oBACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AAAA,EACrC;AAAA;AAAA,EAGS,MACR,OACkD;AAClD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,uBACJ,aACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAEvC,aAAqB;AACpB,WAAO;AAAA,EACR;AAAA,EAES,mBAAmB,OAAqB;AAChD,WAAO,IAAI,KAAK,KAAK;AAAA,EACtB;AAAA,EAES,iBAAiB,OAAqB;AAC9C,WAAO,MAAM,YAAY;AAAA,EAC1B;AACD;AAWO,MAAM,8BACJ,oBACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAEvC,YAAY,MAAiB;AAC5B,UAAM,MAAM,QAAQ,gBAAgB;AAAA,EACrC;AAAA;AAAA,EAGS,MACR,OACkD;AAClD,WAAO,IAAI;AAAA,MACV;AAAA,MACA,KAAK;AAAA,IACN;AAAA,EACD;AACD;AAEO,MAAM,uBACJ,aACT;AAAA,EACC,QAAiB,UAAU,IAAY;AAAA,EAEvC,aAAqB;AACpB,WAAO;AAAA,EACR;AAAA,EAES,mBAAmB,OAA0B;AACrD,WAAO,KAAK,MAAM,KAAK;AAAA,EACxB;AAAA,EAES,iBAAiB,OAA0B;AACnD,WAAO,KAAK,UAAU,KAAK;AAAA,EAC5B;AACD;AAcO,SAAS,KAMf,MACA,SAAmD,CAAC,GAIrD;AACC,SAAQ,OAAO,SAAS,SACrB,IAAI,sBAAsB,IAAI,IAC9B,OAAO,SAAS,SAChB,IAAI,sBAAsB,IAAI,IAC9B,IAAI,kBAAkB,MAAM,MAA+C;AAI/E;","names":[]}
|