@tstdl/base 0.93.21 → 0.93.23
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/application/application.js +3 -3
- package/authentication/server/module.d.ts +1 -1
- package/authentication/server/module.js +1 -6
- package/document-management/api/document-management.api.d.ts +0 -4
- package/document-management/service-models/document.service-model.d.ts +0 -2
- package/injector/injector.js +22 -22
- package/injector/resolve-chain.d.ts +7 -5
- package/injector/resolve-chain.js +16 -14
- package/logger/manager.js +3 -3
- package/orm/data-types/bytea.d.ts +4 -14
- package/orm/data-types/bytea.js +2 -2
- package/orm/data-types/common.d.ts +18 -0
- package/orm/data-types/common.js +11 -0
- package/orm/data-types/index.d.ts +1 -0
- package/orm/data-types/index.js +1 -0
- package/orm/data-types/numeric-date.d.ts +4 -15
- package/orm/data-types/numeric-date.js +2 -2
- package/orm/data-types/timestamp.d.ts +4 -15
- package/orm/data-types/timestamp.js +2 -2
- package/orm/data-types/tsvector.d.ts +3 -13
- package/orm/data-types/tsvector.js +2 -2
- package/orm/decorators.d.ts +16 -54
- package/orm/decorators.js +24 -37
- package/orm/entity.d.ts +6 -9
- package/orm/entity.js +1 -2
- package/orm/query.d.ts +199 -61
- package/orm/query.js +2 -2
- package/orm/repository.types.d.ts +38 -9
- package/orm/server/drizzle/schema-converter.js +40 -118
- package/orm/server/query-converter.d.ts +21 -7
- package/orm/server/query-converter.js +194 -38
- package/orm/server/repository.d.ts +39 -22
- package/orm/server/repository.js +141 -71
- package/orm/server/types.d.ts +10 -2
- package/orm/sqls.d.ts +14 -16
- package/orm/sqls.js +34 -17
- package/package.json +2 -2
- package/test/drizzle/0000_nervous_iron_monger.sql +9 -0
- package/test/drizzle/meta/0000_snapshot.json +27 -7
- package/test/drizzle/meta/_journal.json +2 -44
- package/test/test.model.js +2 -6
- package/test1.js +18 -5
- package/test6.js +23 -35
- package/types/types.d.ts +8 -5
- package/utils/equals.js +2 -2
- package/utils/format-error.js +2 -2
- package/utils/helpers.js +3 -2
- package/utils/object/object.d.ts +4 -4
- package/test/drizzle/0000_sudden_sphinx.sql +0 -9
- package/test/drizzle/0001_organic_rhodey.sql +0 -2
- package/test/drizzle/0002_nice_squadron_supreme.sql +0 -1
- package/test/drizzle/0003_serious_mockingbird.sql +0 -1
- package/test/drizzle/0004_complete_pixie.sql +0 -1
- package/test/drizzle/0005_bumpy_sabra.sql +0 -1
- package/test/drizzle/0006_overrated_post.sql +0 -6
- package/test/drizzle/meta/0001_snapshot.json +0 -79
- package/test/drizzle/meta/0002_snapshot.json +0 -63
- package/test/drizzle/meta/0003_snapshot.json +0 -73
- package/test/drizzle/meta/0004_snapshot.json +0 -89
- package/test/drizzle/meta/0005_snapshot.json +0 -104
- package/test/drizzle/meta/0006_snapshot.json +0 -104
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Defines types used by ORM repositories for operations like loading, updating, and creating entities.
|
|
4
4
|
* Includes types for ordering, loading options, and entity data structures for create/update operations.
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { Path, Record, SimplifyObject, TypedOmit } from '../types/index.js';
|
|
7
7
|
import type { UntaggedDeep } from '../types/tagged.js';
|
|
8
|
-
import type { SQL, SQLWrapper } from 'drizzle-orm';
|
|
8
|
+
import type { AnyColumn, SQL, SQLWrapper } from 'drizzle-orm';
|
|
9
9
|
import type { PartialDeep } from 'type-fest';
|
|
10
10
|
import type { BaseEntity, Entity, EntityMetadata } from './entity.js';
|
|
11
11
|
import type { FullTextSearchQuery, Query } from './query.js';
|
|
@@ -18,13 +18,13 @@ type WithSql<T> = {
|
|
|
18
18
|
* or a raw Drizzle SQLWrapper for a complex target.
|
|
19
19
|
* @template T - The entity type.
|
|
20
20
|
*/
|
|
21
|
-
export type
|
|
21
|
+
export type TargetColumnPath<T extends BaseEntity = BaseEntity> = Path<UntaggedDeep<T>>;
|
|
22
22
|
/**
|
|
23
23
|
* Specifies the target column (e.g. for ordering, distinct on), which can be a property path within the entity
|
|
24
24
|
* or a raw Drizzle SQLWrapper for a complex target.
|
|
25
25
|
* @template T - The entity type.
|
|
26
26
|
*/
|
|
27
|
-
export type TargetColumn<T extends BaseEntity> =
|
|
27
|
+
export type TargetColumn<T extends BaseEntity = BaseEntity> = TargetColumnPath<T> | SQL | SQL.Aliased | AnyColumn;
|
|
28
28
|
/** Specifies the direction for ordering results ('asc' or 'desc'). */
|
|
29
29
|
export type OrderDirection = 'asc' | 'desc';
|
|
30
30
|
/**
|
|
@@ -78,13 +78,42 @@ export type HighlightOptions<T extends BaseEntity> = {
|
|
|
78
78
|
/**
|
|
79
79
|
* The source to generate the highlight from. Can be one or more property paths or a raw SQL expression.
|
|
80
80
|
*/
|
|
81
|
-
source:
|
|
82
|
-
} & TsHeadlineOptions;
|
|
81
|
+
source: TargetColumnPath<T> | SQL<string>;
|
|
82
|
+
} & (TsHeadlineOptions | ParadeDbHighlightOptions);
|
|
83
|
+
/**
|
|
84
|
+
* Options for highlighting with ParadeDB (`pdb.snippet`).
|
|
85
|
+
*/
|
|
86
|
+
export type ParadeDbHighlightOptions = {
|
|
87
|
+
/**
|
|
88
|
+
* Limits the number of characters in the snippet. Defaults to 150.
|
|
89
|
+
*/
|
|
90
|
+
maxNumChars?: number;
|
|
91
|
+
/**
|
|
92
|
+
* The tag to use for the start of a highlighted term. Defaults to '<b>'.
|
|
93
|
+
*/
|
|
94
|
+
startTag?: string;
|
|
95
|
+
/**
|
|
96
|
+
* The tag to use for the end of a highlighted term. Defaults to '</b>'.
|
|
97
|
+
*/
|
|
98
|
+
endTag?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Limits the number of highlighted terms returned in the snippet.
|
|
101
|
+
*/
|
|
102
|
+
limit?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Ignores the first N highlighted terms.
|
|
105
|
+
*/
|
|
106
|
+
offset?: number;
|
|
107
|
+
};
|
|
83
108
|
/**
|
|
84
109
|
* Options for the `search` method.
|
|
85
110
|
* @template T - The entity type.
|
|
86
111
|
*/
|
|
87
|
-
export type SearchOptions<T extends BaseEntity> = SimplifyObject<
|
|
112
|
+
export type SearchOptions<T extends BaseEntity> = SimplifyObject<TypedOmit<LoadManyOptions<T>, 'order'> & {
|
|
113
|
+
/**
|
|
114
|
+
* The search query to execute.
|
|
115
|
+
*/
|
|
116
|
+
query: FullTextSearchQuery<T>;
|
|
88
117
|
/**
|
|
89
118
|
* An additional filter to apply to the search query.
|
|
90
119
|
*/
|
|
@@ -96,7 +125,7 @@ export type SearchOptions<T extends BaseEntity> = SimplifyObject<FullTextSearchQ
|
|
|
96
125
|
score: SQL | SQL.Aliased<number>;
|
|
97
126
|
}) => Order<T>);
|
|
98
127
|
/**
|
|
99
|
-
* Whether to include a relevance score with each result.
|
|
128
|
+
* Whether to include a relevance score with each result.
|
|
100
129
|
* - If `true`, the default score is included.
|
|
101
130
|
* - If a function is provided, it customizes the score calculation using the original score.
|
|
102
131
|
* - If no order is specified, results are ordered by score descending, when score is enabled.
|
|
@@ -113,7 +142,7 @@ export type SearchOptions<T extends BaseEntity> = SimplifyObject<FullTextSearchQ
|
|
|
113
142
|
/**
|
|
114
143
|
* Enable and configure highlighting of search results.
|
|
115
144
|
*/
|
|
116
|
-
highlight?:
|
|
145
|
+
highlight?: TargetColumnPath<T> | SQL<string> | HighlightOptions<T>;
|
|
117
146
|
}>;
|
|
118
147
|
/**
|
|
119
148
|
* Represents a single result from a full-text search operation.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SQL
|
|
1
|
+
import { SQL } from 'drizzle-orm';
|
|
2
2
|
import { toCamelCase, toSnakeCase } from 'drizzle-orm/casing';
|
|
3
3
|
import { boolean, check, doublePrecision, foreignKey, index, integer, jsonb, pgSchema, primaryKey, text, unique, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { match, P } from 'ts-pattern';
|
|
@@ -6,25 +6,23 @@ import { MultiKeyMap } from '../../../data-structures/multi-key-map.js';
|
|
|
6
6
|
import { tryGetEnumName } from '../../../enumeration/enumeration.js';
|
|
7
7
|
import { NotSupportedError } from '../../../errors/not-supported.error.js';
|
|
8
8
|
import { JsonPath } from '../../../json-path/json-path.js';
|
|
9
|
-
import { setweight, toTsVector } from '../../../orm/sqls.js';
|
|
10
9
|
import { reflectionRegistry } from '../../../reflection/registry.js';
|
|
11
10
|
import { ArraySchema, BooleanSchema, DefaultSchema, EnumerationSchema, getObjectSchema, NullableSchema, NumberSchema, ObjectSchema, OptionalSchema, StringSchema, Uint8ArraySchema } from '../../../schema/index.js';
|
|
12
11
|
import { compareByValueSelectionToOrder, orderRest } from '../../../utils/comparison.js';
|
|
13
12
|
import { decodeText, encodeUtf8 } from '../../../utils/encoding.js';
|
|
14
13
|
import { enumValues } from '../../../utils/enum.js';
|
|
15
14
|
import { memoize, memoizeSingle } from '../../../utils/function/memoize.js';
|
|
16
|
-
import { iif } from '../../../utils/helpers.js';
|
|
17
15
|
import { compileDereferencer } from '../../../utils/object/dereference.js';
|
|
18
16
|
import { fromEntries, objectEntries } from '../../../utils/object/object.js';
|
|
19
17
|
import { assertDefined, assertDefinedPass, isArray, isDefined, isNotNullOrUndefined, isNull, isString, isUndefined } from '../../../utils/type-guards.js';
|
|
20
18
|
import { resolveValueOrProvider } from '../../../utils/value-or-provider.js';
|
|
21
|
-
import { bytea, numericDate, timestamp
|
|
19
|
+
import { bytea, numericDate, timestamp } from '../../data-types/index.js';
|
|
22
20
|
import { JsonSchema } from '../../schemas/json.js';
|
|
23
21
|
import { NumericDateSchema } from '../../schemas/numeric-date.js';
|
|
24
22
|
import { TimestampSchema } from '../../schemas/timestamp.js';
|
|
25
23
|
import { UuidSchema } from '../../schemas/uuid.js';
|
|
26
24
|
import { decryptBytes, encryptBytes } from '../encryption.js';
|
|
27
|
-
import { convertQuery } from '../query-converter.js';
|
|
25
|
+
import { convertQuery, resolveTargetColumn } from '../query-converter.js';
|
|
28
26
|
const getDbSchema = memoizeSingle(pgSchema);
|
|
29
27
|
export const getDrizzleTableFromType = memoize(_getDrizzleTableFromType);
|
|
30
28
|
const columnDefinitionsSymbol = Symbol('columnDefinitions');
|
|
@@ -53,14 +51,18 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
53
51
|
const columnDefinitions = getPostgresColumnEntries(type, dbSchema, tableName);
|
|
54
52
|
const columnDefinitionsMap = new Map(columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
55
53
|
function getColumn(table, propertyName) {
|
|
56
|
-
return
|
|
54
|
+
return resolveTargetColumn(propertyName, table, columnDefinitionsMap);
|
|
57
55
|
}
|
|
58
56
|
function buildIndex(table, data, columnName) {
|
|
59
|
-
const
|
|
57
|
+
const resolvedColumns = resolveValueOrProvider(data.columns ?? [columnName], table);
|
|
58
|
+
const columns = resolvedColumns.map((columnValue) => {
|
|
59
|
+
if (columnValue instanceof SQL) {
|
|
60
|
+
return columnValue;
|
|
61
|
+
}
|
|
60
62
|
assertDefined(columnValue, 'Missing column name for index.');
|
|
61
|
-
const [
|
|
63
|
+
const [columnNameOrConfig, columnOrder] = isArray(columnValue) ? columnValue : [columnValue];
|
|
62
64
|
const order = columnOrder ?? data.order ?? 'asc';
|
|
63
|
-
let column = getColumn(table,
|
|
65
|
+
let column = isString(columnNameOrConfig) ? getColumn(table, columnNameOrConfig) : columnNameOrConfig;
|
|
64
66
|
column = column[order]();
|
|
65
67
|
if (data.options?.nulls == 'first') {
|
|
66
68
|
column = column.nullsFirst();
|
|
@@ -71,15 +73,22 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
71
73
|
return column;
|
|
72
74
|
});
|
|
73
75
|
const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
|
|
76
|
+
console.log({ name: data.options?.name ?? getIndexName(tableName, columns, { naming: data.options?.naming }) });
|
|
74
77
|
let builder = indexFn(data.options?.name ?? getIndexName(tableName, columns, { naming: data.options?.naming })).using(data.options?.using ?? 'btree', ...columns);
|
|
75
78
|
if (isDefined(data.options?.where)) {
|
|
76
79
|
const query = convertQuery(data.options.where(table), table, columnDefinitionsMap);
|
|
77
80
|
builder = builder.where(query.inlineParams());
|
|
78
81
|
}
|
|
82
|
+
if (isDefined(data.options?.with)) {
|
|
83
|
+
builder = builder.with(data.options.with);
|
|
84
|
+
}
|
|
85
|
+
if (data.options?.concurrently == true) {
|
|
86
|
+
builder = builder.concurrently();
|
|
87
|
+
}
|
|
79
88
|
return builder;
|
|
80
89
|
}
|
|
81
90
|
function buildPrimaryKey(table) {
|
|
82
|
-
const columns = primaryKeyColumnDefinitions.map((columnDefinition) =>
|
|
91
|
+
const columns = primaryKeyColumnDefinitions.map((columnDefinition) => table[columnDefinition.name]);
|
|
83
92
|
return primaryKey({
|
|
84
93
|
name: mergedTableReflectionData.compundPrimaryKeyName ?? getPrimaryKeyName(tableName, columns, { naming: mergedTableReflectionData.compundPrimaryKeyNaming }),
|
|
85
94
|
columns,
|
|
@@ -88,40 +97,33 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
88
97
|
const primaryKeyColumnDefinitions = columnDefinitions.filter((columnDefinition) => columnDefinition.reflectionData?.primaryKey == true);
|
|
89
98
|
const skipPrimaryKey = primaryKeyColumnDefinitions.length > 1;
|
|
90
99
|
const columnEntries = columnDefinitions.map((entry) => [entry.name, entry.buildType({ skipPrimaryKey })]);
|
|
91
|
-
const
|
|
92
|
-
.flatMap((tableReflectionData) => tableReflectionData.fullTextSearch ?? [])
|
|
93
|
-
.flatMap((ftsData) => getFullTextSearchColumns(ftsData, () => drizzleSchema, (property) => getColumn(drizzleSchema, property)));
|
|
94
|
-
const drizzleSchema = dbSchema.table(tableName, fromEntries([
|
|
95
|
-
...columnEntries,
|
|
96
|
-
...fullTextSearchColumnEntries,
|
|
97
|
-
]), (drizzleTable) => {
|
|
100
|
+
const drizzleSchema = dbSchema.table(tableName, fromEntries(columnEntries), (drizzleTable) => {
|
|
98
101
|
const table = drizzleTable;
|
|
99
|
-
const indexes = tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.index).filter(isDefined).map((data) => buildIndex(
|
|
100
|
-
const fullTextIndexes = tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.fullTextSearch ?? []).flatMap((ftsData) => getFullTextSearchIndexes(ftsData, table, (property) => getColumn(drizzleTable, property)));
|
|
102
|
+
const indexes = tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.index).filter(isDefined).map((data) => buildIndex(table, data));
|
|
101
103
|
const checks = tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.checks).filter(isDefined).map((data) => check(data.name, data.builder(table)));
|
|
102
104
|
return [
|
|
103
105
|
...((primaryKeyColumnDefinitions.length > 1)
|
|
104
|
-
? [buildPrimaryKey(
|
|
106
|
+
? [buildPrimaryKey(table)]
|
|
105
107
|
: []),
|
|
106
108
|
...(columnDefinitions.map((columnDefinition) => {
|
|
107
109
|
const indexData = columnDefinition.reflectionData?.index;
|
|
108
110
|
if (isUndefined(indexData)) {
|
|
109
111
|
return undefined;
|
|
110
112
|
}
|
|
111
|
-
return buildIndex(
|
|
113
|
+
return buildIndex(table, indexData, columnDefinition.name);
|
|
112
114
|
}).filter(isDefined)),
|
|
113
115
|
...tableReflectionDatas.flatMap((tableReflectionData) => {
|
|
114
116
|
return tableReflectionData.foreignKeys?.map((foreignKeyData) => {
|
|
115
117
|
const foreignTable = getDrizzleTableFromType(foreignKeyData.target(), dbSchema.schemaName);
|
|
116
118
|
return foreignKey({
|
|
117
119
|
name: foreignKeyData.options?.name ?? getForeignKeyName(tableName, foreignKeyData.columns, { naming: foreignKeyData.options?.naming }),
|
|
118
|
-
columns: foreignKeyData.columns.map((column) => getColumn(
|
|
120
|
+
columns: foreignKeyData.columns.map((column) => getColumn(table, column)),
|
|
119
121
|
foreignColumns: foreignKeyData.foreignColumns.map((column) => getColumn(foreignTable, column)),
|
|
120
122
|
});
|
|
121
123
|
}) ?? [];
|
|
122
124
|
}),
|
|
123
125
|
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.unique).filter(isDefined).map((data) => {
|
|
124
|
-
const columns = data.columns?.map((column) => getColumn(
|
|
126
|
+
const columns = data.columns?.map((column) => getColumn(table, column));
|
|
125
127
|
let constraint = unique(data.options?.name ?? getUniqueName(tableName, columns, { naming: data.options?.naming })).on(...columns);
|
|
126
128
|
if (data.options?.nulls == 'not distinct') {
|
|
127
129
|
constraint = constraint.nullsNotDistinct();
|
|
@@ -129,7 +131,6 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
129
131
|
return constraint;
|
|
130
132
|
}),
|
|
131
133
|
...indexes,
|
|
132
|
-
...fullTextIndexes,
|
|
133
134
|
...checks,
|
|
134
135
|
];
|
|
135
136
|
});
|
|
@@ -137,69 +138,6 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
137
138
|
drizzleSchema[columnDefinitionsMapSymbol] = columnDefinitionsMap;
|
|
138
139
|
return drizzleSchema;
|
|
139
140
|
}
|
|
140
|
-
function getFullTextSearchColumns(data, tableProvider, columnProvider) {
|
|
141
|
-
if (isDefined(data.vector)) {
|
|
142
|
-
const name = `fts_v_${data.name}`;
|
|
143
|
-
const generationSource = () => {
|
|
144
|
-
const table = tableProvider();
|
|
145
|
-
const source = assertDefinedPass(resolveValueOrProvider(data.source ?? data.vector?.rawVectorSource, table), 'Either "source" or "vector.rawVectorSource" must be provided for full-text search vector generation.');
|
|
146
|
-
const language = resolveValueOrProvider(data.vector?.language ?? 'simple', table);
|
|
147
|
-
return match(source)
|
|
148
|
-
.with(P.instanceOf(SQL), (sqlExpression) => sqlExpression)
|
|
149
|
-
.otherwise((paths) => {
|
|
150
|
-
const vectors = paths.map((property) => {
|
|
151
|
-
const column = columnProvider(property);
|
|
152
|
-
const tsVector = toTsVector(language, column);
|
|
153
|
-
const weight = data.vector?.weights?.[property];
|
|
154
|
-
if (isDefined(weight)) {
|
|
155
|
-
return setweight(tsVector, weight);
|
|
156
|
-
}
|
|
157
|
-
return tsVector;
|
|
158
|
-
});
|
|
159
|
-
return sql `(${sql.join(vectors, sql ` || `)})`;
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
const column = tsvector(name).generatedAlwaysAs(generationSource);
|
|
163
|
-
return [[name, column]];
|
|
164
|
-
}
|
|
165
|
-
return [];
|
|
166
|
-
}
|
|
167
|
-
function getFullTextSearchIndexes(data, table, columnProvider) {
|
|
168
|
-
return [
|
|
169
|
-
...iif(isDefined(data.vector), () => {
|
|
170
|
-
const indexName = `fts_${data.name}_bm25`;
|
|
171
|
-
const textSource = assertDefinedPass(data.source, 'Either "source" or "vector.rawVectorSource" must be provided for full-text search vector generation.');
|
|
172
|
-
const source = resolveValueOrProvider(textSource, table);
|
|
173
|
-
const indexExpression = match(source)
|
|
174
|
-
.with(P.instanceOf(SQL), (sqlExpression) => sqlExpression)
|
|
175
|
-
.otherwise((paths) => {
|
|
176
|
-
const columns = paths.map((property) => columnProvider(property));
|
|
177
|
-
return sql `(${sql.join(columns, sql ` || `)})`;
|
|
178
|
-
});
|
|
179
|
-
const bm25Index = index(indexName).using('bm25', indexExpression).with({ key_field: 'id' });
|
|
180
|
-
return [bm25Index];
|
|
181
|
-
}, () => []),
|
|
182
|
-
...iif(isDefined(data.vector), () => {
|
|
183
|
-
const columnName = `fts_v_${data.name}`;
|
|
184
|
-
const indexName = `${columnName}_gin`;
|
|
185
|
-
const ginIndex = index(indexName).using('gin', columnProvider(columnName)).with({ fastupdate: 'off' });
|
|
186
|
-
return [ginIndex];
|
|
187
|
-
}, () => []),
|
|
188
|
-
...iif(isDefined(data.trigram), () => {
|
|
189
|
-
const indexName = `fts_t_${data.name}_gist`;
|
|
190
|
-
const textSource = assertDefinedPass(data.source, 'Either "source" or "vector.rawVectorSource" must be provided for full-text search vector generation.');
|
|
191
|
-
const source = resolveValueOrProvider(textSource, table);
|
|
192
|
-
const indexExpression = match(source)
|
|
193
|
-
.with(P.instanceOf(SQL), (sqlExpression) => sqlExpression)
|
|
194
|
-
.otherwise((paths) => {
|
|
195
|
-
const columns = paths.map((property) => columnProvider(property));
|
|
196
|
-
return sql `(${sql.join(columns, sql ` || `)})`;
|
|
197
|
-
});
|
|
198
|
-
const gistIndex = index(indexName).using('gist', indexExpression).with({ fastupdate: 'off' });
|
|
199
|
-
return [gistIndex];
|
|
200
|
-
}, () => []),
|
|
201
|
-
];
|
|
202
|
-
}
|
|
203
141
|
function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath({ dollar: false }), prefix = '') {
|
|
204
142
|
const metadata = reflectionRegistry.getMetadata(type);
|
|
205
143
|
assertDefined(metadata, `Type ${type.name} does not have reflection metadata (path: ${path.toString()}).`);
|
|
@@ -289,41 +227,25 @@ function getPostgresBaseColumn(columnName, dbSchema, schema, reflectionData, con
|
|
|
289
227
|
if (reflectionData.encrypted) {
|
|
290
228
|
return bytea(columnName);
|
|
291
229
|
}
|
|
292
|
-
|
|
230
|
+
return match(schema)
|
|
231
|
+
.with(P.instanceOf(UuidSchema), (s) => {
|
|
293
232
|
let column = uuid(columnName);
|
|
294
|
-
if (
|
|
233
|
+
if (s.defaultRandom) {
|
|
295
234
|
column = column.defaultRandom();
|
|
296
235
|
}
|
|
297
236
|
return column;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
if (schema instanceof StringSchema) {
|
|
311
|
-
return text(columnName);
|
|
312
|
-
}
|
|
313
|
-
if (schema instanceof BooleanSchema) {
|
|
314
|
-
return boolean(columnName);
|
|
315
|
-
}
|
|
316
|
-
if (schema instanceof EnumerationSchema) {
|
|
317
|
-
const pgEnum = getPgEnum(dbSchema, schema.enumeration, context);
|
|
318
|
-
return pgEnum(columnName);
|
|
319
|
-
}
|
|
320
|
-
if (schema instanceof JsonSchema) {
|
|
321
|
-
return jsonb(columnName);
|
|
322
|
-
}
|
|
323
|
-
if (schema instanceof Uint8ArraySchema) {
|
|
324
|
-
return bytea(columnName);
|
|
325
|
-
}
|
|
326
|
-
throw new NotSupportedError(`Schema "${schema.constructor.name}" not supported on type "${context.type.name}" for property "${context.property}"`);
|
|
237
|
+
})
|
|
238
|
+
.with(P.instanceOf(TimestampSchema), () => timestamp(columnName))
|
|
239
|
+
.with(P.instanceOf(NumericDateSchema), () => numericDate(columnName))
|
|
240
|
+
.with(P.instanceOf(NumberSchema), (s) => (s.integer ? integer(columnName) : doublePrecision(columnName)))
|
|
241
|
+
.with(P.instanceOf(StringSchema), () => text(columnName))
|
|
242
|
+
.with(P.instanceOf(BooleanSchema), () => boolean(columnName))
|
|
243
|
+
.with(P.instanceOf(EnumerationSchema), (s) => getPgEnum(dbSchema, s.enumeration, context)(columnName))
|
|
244
|
+
.with(P.instanceOf(JsonSchema), () => jsonb(columnName))
|
|
245
|
+
.with(P.instanceOf(Uint8ArraySchema), () => bytea(columnName))
|
|
246
|
+
.otherwise(() => {
|
|
247
|
+
throw new NotSupportedError(`Schema "${schema.constructor.name}" not supported on type "${context.type.name}" for property "${context.property}"`);
|
|
248
|
+
});
|
|
327
249
|
}
|
|
328
250
|
const enumNames = new Map();
|
|
329
251
|
const enums = new MultiKeyMap();
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import { SQL, type SQLWrapper } from 'drizzle-orm';
|
|
2
|
+
import type { BaseEntity } from '../entity.js';
|
|
3
|
+
import type { Query, TsVectorParser, TsVectorWeight } from '../query.js';
|
|
4
|
+
import type { TargetColumn } from '../repository.types.js';
|
|
5
|
+
import type { ColumnDefinition, ExtraConfigColumnsFromType, PgTableFromType } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Resolves a target to a Drizzle PgColumn or SQLWrapper.
|
|
8
|
+
* @param target The target to resolve.
|
|
9
|
+
* @param table The Drizzle table object.
|
|
10
|
+
* @param columnDefinitionsMap A map from property names to column definitions.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveTargetColumn<T extends BaseEntity>(target: TargetColumn<T> | ColumnDefinition, table: PgTableFromType | ExtraConfigColumnsFromType, columnDefinitionsMap: Map<string, ColumnDefinition>): SQLWrapper;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves multiple targets to a Drizzle PgColumn or SQLWrapper.
|
|
15
|
+
* @param targets The targets to resolve.
|
|
16
|
+
* @param table The Drizzle table object.
|
|
17
|
+
* @param columnDefinitionsMap A map from property names to column definitions.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveTargetColumns<T extends BaseEntity>(targets: (TargetColumn<T> | ColumnDefinition)[], table: PgTableFromType, columnDefinitionsMap: Map<string, ColumnDefinition>): SQLWrapper[];
|
|
5
20
|
/**
|
|
6
21
|
* Converts a query object into a Drizzle SQL condition.
|
|
7
22
|
* Recursively handles nested logical operators and maps property names to database columns.
|
|
@@ -15,6 +30,5 @@ import type { ColumnDefinition, PgTableFromType } from './types.js';
|
|
|
15
30
|
* @throws {Error} If an unsupported query type is encountered.
|
|
16
31
|
*/
|
|
17
32
|
export declare function convertQuery(query: Query, table: PgTableFromType, columnDefinitionsMap: Map<string, ColumnDefinition>): SQL;
|
|
18
|
-
export declare function getTsQuery(text: string | SQL, language: string | SQL, parser:
|
|
19
|
-
export declare function getTsVector(fields: readonly
|
|
20
|
-
export declare function getColumnConcatenation(fields: readonly string[], table: PgTableFromType, columnDefinitionsMap: Map<string, ColumnDefinition>): SQL;
|
|
33
|
+
export declare function getTsQuery(text: string | SQL, language: string | SQL, parser: TsVectorParser): SQL;
|
|
34
|
+
export declare function getTsVector(fields: readonly (SQLWrapper | readonly [field: SQLWrapper, weight?: TsVectorWeight])[], language: string | SQL): SQL;
|