@contember/database 2.0.2 → 2.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +1 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +2 -1
- package/dist/development/src/builders/ColumnExpressionFactory.cjs +16 -6
- package/dist/development/src/builders/ColumnExpressionFactory.cjs.map +1 -1
- package/dist/development/src/builders/ColumnExpressionFactory.js +12 -2
- package/dist/development/src/builders/ColumnExpressionFactory.js.map +1 -1
- package/dist/development/src/builders/ConditionBuilder.cjs +24 -15
- package/dist/development/src/builders/ConditionBuilder.cjs.map +1 -1
- package/dist/development/src/builders/ConditionBuilder.js +17 -8
- package/dist/development/src/builders/ConditionBuilder.js.map +1 -1
- package/dist/development/src/builders/SelectBuilder.cjs +1 -2
- package/dist/development/src/builders/SelectBuilder.cjs.map +1 -1
- package/dist/development/src/builders/SelectBuilder.js +2 -3
- package/dist/development/src/builders/SelectBuilder.js.map +1 -1
- package/dist/development/src/builders/WindowFunction.cjs +12 -2
- package/dist/development/src/builders/WindowFunction.cjs.map +1 -1
- package/dist/development/src/builders/WindowFunction.js +12 -2
- package/dist/development/src/builders/WindowFunction.js.map +1 -1
- package/dist/development/src/builders/internal/Returning.cjs +10 -2
- package/dist/development/src/builders/internal/Returning.cjs.map +1 -1
- package/dist/development/src/builders/internal/Returning.js +10 -2
- package/dist/development/src/builders/internal/Returning.js.map +1 -1
- package/dist/development/src/builders/utils.cjs +12 -3
- package/dist/development/src/builders/utils.cjs.map +1 -1
- package/dist/development/src/builders/utils.js +13 -4
- package/dist/development/src/builders/utils.js.map +1 -1
- package/dist/development/src/client/Client.cjs +1 -1
- package/dist/development/src/client/Client.js +1 -1
- package/dist/development/src/metadata/DatabaseMetadataResolver.cjs +4 -3
- package/dist/development/src/metadata/DatabaseMetadataResolver.cjs.map +1 -1
- package/dist/development/src/metadata/DatabaseMetadataResolver.js +4 -3
- package/dist/development/src/metadata/DatabaseMetadataResolver.js.map +1 -1
- package/dist/development/src/metadata/IndexMetadata.cjs +3 -0
- package/dist/development/src/metadata/IndexMetadata.cjs.map +1 -1
- package/dist/development/src/metadata/IndexMetadata.js +3 -0
- package/dist/development/src/metadata/IndexMetadata.js.map +1 -1
- package/dist/development/src/utils/createDatabaseIfNotExists.cjs +1 -1
- package/dist/development/src/utils/createDatabaseIfNotExists.js +1 -1
- package/dist/development/src/utils/retryTransaction.cjs +1 -1
- package/dist/development/src/utils/retryTransaction.js +1 -1
- package/dist/development/src/utils/sql.cjs +8 -0
- package/dist/development/src/utils/sql.cjs.map +1 -1
- package/dist/development/src/utils/sql.js +8 -0
- package/dist/development/src/utils/sql.js.map +1 -1
- package/dist/production/index.cjs +1 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +2 -1
- package/dist/production/src/builders/ColumnExpressionFactory.cjs +16 -6
- package/dist/production/src/builders/ColumnExpressionFactory.cjs.map +1 -1
- package/dist/production/src/builders/ColumnExpressionFactory.js +12 -2
- package/dist/production/src/builders/ColumnExpressionFactory.js.map +1 -1
- package/dist/production/src/builders/ConditionBuilder.cjs +24 -15
- package/dist/production/src/builders/ConditionBuilder.cjs.map +1 -1
- package/dist/production/src/builders/ConditionBuilder.js +17 -8
- package/dist/production/src/builders/ConditionBuilder.js.map +1 -1
- package/dist/production/src/builders/SelectBuilder.cjs +1 -2
- package/dist/production/src/builders/SelectBuilder.cjs.map +1 -1
- package/dist/production/src/builders/SelectBuilder.js +2 -3
- package/dist/production/src/builders/SelectBuilder.js.map +1 -1
- package/dist/production/src/builders/WindowFunction.cjs +12 -2
- package/dist/production/src/builders/WindowFunction.cjs.map +1 -1
- package/dist/production/src/builders/WindowFunction.js +12 -2
- package/dist/production/src/builders/WindowFunction.js.map +1 -1
- package/dist/production/src/builders/internal/Returning.cjs +10 -2
- package/dist/production/src/builders/internal/Returning.cjs.map +1 -1
- package/dist/production/src/builders/internal/Returning.js +10 -2
- package/dist/production/src/builders/internal/Returning.js.map +1 -1
- package/dist/production/src/builders/utils.cjs +12 -3
- package/dist/production/src/builders/utils.cjs.map +1 -1
- package/dist/production/src/builders/utils.js +13 -4
- package/dist/production/src/builders/utils.js.map +1 -1
- package/dist/production/src/client/Client.cjs +1 -1
- package/dist/production/src/client/Client.js +1 -1
- package/dist/production/src/metadata/DatabaseMetadataResolver.cjs +4 -3
- package/dist/production/src/metadata/DatabaseMetadataResolver.cjs.map +1 -1
- package/dist/production/src/metadata/DatabaseMetadataResolver.js +4 -3
- package/dist/production/src/metadata/DatabaseMetadataResolver.js.map +1 -1
- package/dist/production/src/metadata/IndexMetadata.cjs +3 -0
- package/dist/production/src/metadata/IndexMetadata.cjs.map +1 -1
- package/dist/production/src/metadata/IndexMetadata.js +3 -0
- package/dist/production/src/metadata/IndexMetadata.js.map +1 -1
- package/dist/production/src/utils/createDatabaseIfNotExists.cjs +1 -1
- package/dist/production/src/utils/createDatabaseIfNotExists.js +1 -1
- package/dist/production/src/utils/retryTransaction.cjs +1 -1
- package/dist/production/src/utils/retryTransaction.js +1 -1
- package/dist/production/src/utils/sql.cjs +8 -0
- package/dist/production/src/utils/sql.cjs.map +1 -1
- package/dist/production/src/utils/sql.js +8 -0
- package/dist/production/src/utils/sql.js.map +1 -1
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts.map +1 -1
- package/dist/tests/src/tags.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/builders/ColumnExpressionFactory.d.ts.map +1 -1
- package/dist/types/builders/ConditionBuilder.d.ts +2 -2
- package/dist/types/builders/ConditionBuilder.d.ts.map +1 -1
- package/dist/types/builders/SelectBuilder.d.ts.map +1 -1
- package/dist/types/builders/WindowFunction.d.ts.map +1 -1
- package/dist/types/builders/utils.d.ts +0 -2
- package/dist/types/builders/utils.d.ts.map +1 -1
- package/dist/types/client/Transaction.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/metadata/DatabaseMetadata.d.ts.map +1 -1
- package/dist/types/metadata/DatabaseMetadataResolver.d.ts.map +1 -1
- package/dist/types/metadata/IndexMetadata.d.ts +1 -0
- package/dist/types/metadata/IndexMetadata.d.ts.map +1 -1
- package/dist/types/metadata/stringArrayEquals.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/createDatabaseIfNotExists.d.ts.map +1 -1
- package/dist/types/utils/pgClientFactory.d.ts.map +1 -1
- package/dist/types/utils/retryTransaction.d.ts.map +1 -1
- package/dist/types/utils/sql.d.ts +1 -0
- package/dist/types/utils/sql.d.ts.map +1 -1
- package/dist/types/utils/withDatabaseAdvisoryLock.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/builders/ColumnExpressionFactory.ts +3 -3
- package/src/builders/ConditionBuilder.ts +14 -15
- package/src/builders/SelectBuilder.ts +4 -4
- package/src/builders/WindowFunction.ts +3 -2
- package/src/builders/internal/Returning.ts +2 -2
- package/src/builders/utils.ts +2 -4
- package/src/index.ts +1 -0
- package/src/metadata/DatabaseMetadataResolver.ts +4 -2
- package/src/metadata/IndexMetadata.ts +4 -0
- package/src/utils/sql.ts +8 -0
- package/dist/development/src/builders/formatUtils.cjs +0 -23
- package/dist/development/src/builders/formatUtils.cjs.map +0 -1
- package/dist/development/src/builders/formatUtils.js +0 -23
- package/dist/development/src/builders/formatUtils.js.map +0 -1
- package/dist/production/src/builders/formatUtils.cjs +0 -23
- package/dist/production/src/builders/formatUtils.cjs.map +0 -1
- package/dist/production/src/builders/formatUtils.js +0 -23
- package/dist/production/src/builders/formatUtils.js.map +0 -1
- package/dist/types/builders/formatUtils.d.ts +0 -4
- package/dist/types/builders/formatUtils.d.ts.map +0 -1
- package/src/builders/formatUtils.ts +0 -17
|
@@ -2,9 +2,9 @@ import { Value } from '../types'
|
|
|
2
2
|
import { Literal } from '../Literal'
|
|
3
3
|
import { QueryBuilder } from './QueryBuilder'
|
|
4
4
|
import { SelectBuilder } from './SelectBuilder'
|
|
5
|
-
import { toFqnWrap } from './formatUtils'
|
|
6
5
|
import { Compiler } from './Compiler'
|
|
7
6
|
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
|
|
7
|
+
import { formatColumnIdentifier } from '../utils'
|
|
8
8
|
|
|
9
9
|
export type ConditionCallback = (builder: ConditionBuilder) => ConditionBuilder
|
|
10
10
|
export type ConditionExpression = ConditionBuilder | ConditionCallback
|
|
@@ -19,13 +19,12 @@ export enum Operator {
|
|
|
19
19
|
'contains' = 'contains',
|
|
20
20
|
'startsWith' = 'startsWith',
|
|
21
21
|
'endsWith' = 'endsWith',
|
|
22
|
-
|
|
23
22
|
'containsCI' = 'containsCI',
|
|
24
23
|
'startsWithCI' = 'startsWithCI',
|
|
25
24
|
'endsWithCI' = 'endsWithCI',
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
const likeOperators = [
|
|
27
|
+
const likeOperators: string[] = [
|
|
29
28
|
Operator.contains,
|
|
30
29
|
Operator.containsCI,
|
|
31
30
|
Operator.startsWith,
|
|
@@ -63,8 +62,8 @@ export class ConditionBuilder {
|
|
|
63
62
|
return this.processConditionExpression(ConditionBuilder.process(condition), ['and', true])
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
compare(columnName: QueryBuilder.ColumnIdentifier, operator: Operator
|
|
67
|
-
if (!Object.values(Operator).includes(operator)) {
|
|
65
|
+
compare(columnName: QueryBuilder.ColumnIdentifier, operator: Operator | `${Operator}`, value: Value | Literal): ConditionBuilder {
|
|
66
|
+
if (!(Object.values(Operator) as string[]).includes(operator)) {
|
|
68
67
|
throw new Error(`Operator ${operator} is not supported`)
|
|
69
68
|
}
|
|
70
69
|
|
|
@@ -74,30 +73,30 @@ export class ConditionBuilder {
|
|
|
74
73
|
}
|
|
75
74
|
value = value.replace(/([\\%_])/g, v => '\\' + v)
|
|
76
75
|
}
|
|
77
|
-
return this.with(new Literal(ConditionBuilder.createOperatorSql(
|
|
76
|
+
return this.with(new Literal(ConditionBuilder.createOperatorSql(formatColumnIdentifier(columnName), '?', operator), [value]))
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
columnsEq(columnName1: QueryBuilder.ColumnIdentifier, columnName2: QueryBuilder.ColumnIdentifier): ConditionBuilder {
|
|
81
80
|
return this.compareColumns(columnName1, Operator.eq, columnName2)
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
compareColumns(columnName1: QueryBuilder.ColumnIdentifier, operator: Operator
|
|
85
|
-
return this.with(new Literal(ConditionBuilder.createOperatorSql(
|
|
83
|
+
compareColumns(columnName1: QueryBuilder.ColumnIdentifier, operator: Operator | `${Operator}`, columnName2: QueryBuilder.ColumnIdentifier) {
|
|
84
|
+
return this.with(new Literal(ConditionBuilder.createOperatorSql(formatColumnIdentifier(columnName1), formatColumnIdentifier(columnName2), operator)))
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
in(columnName: QueryBuilder.ColumnIdentifier, values: ReadonlyArray<Value> | SelectBuilder<SelectBuilder.Result>, columnType?: string): ConditionBuilder {
|
|
89
88
|
if (!isReadonlyArray(values)) {
|
|
90
89
|
// todo: replace placeholder with some kind of callback
|
|
91
90
|
const query = values.createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, new Set()))
|
|
92
|
-
return this.with(new Literal(`${
|
|
91
|
+
return this.with(new Literal(`${formatColumnIdentifier(columnName)} in (${query.sql})`, query.parameters))
|
|
93
92
|
}
|
|
94
93
|
values = values.filter(it => it !== undefined)
|
|
95
94
|
if (columnType && values.length > 100) {
|
|
96
|
-
return this.with(new Literal(`${
|
|
95
|
+
return this.with(new Literal(`${formatColumnIdentifier(columnName)} = any(?::${columnType}[])`, [values]))
|
|
97
96
|
}
|
|
98
97
|
if (values.length > 0) {
|
|
99
98
|
const parameters = values.map(() => '?').join(', ')
|
|
100
|
-
return this.with(new Literal(`${
|
|
99
|
+
return this.with(new Literal(`${formatColumnIdentifier(columnName)} in (${parameters})`, values))
|
|
101
100
|
}
|
|
102
101
|
return this.raw('false')
|
|
103
102
|
}
|
|
@@ -114,11 +113,11 @@ export class ConditionBuilder {
|
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
isNull(columnName: QueryBuilder.ColumnIdentifier): ConditionBuilder {
|
|
117
|
-
return this.with(new Literal(`${
|
|
116
|
+
return this.with(new Literal(`${formatColumnIdentifier(columnName)} is null`))
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
isNotNull(columnName: QueryBuilder.ColumnIdentifier): ConditionBuilder {
|
|
121
|
-
return this.with(new Literal(`${
|
|
120
|
+
return this.with(new Literal(`${formatColumnIdentifier(columnName)} is not null`))
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
raw(sql: string, ...bindings: Value[]): ConditionBuilder {
|
|
@@ -148,8 +147,8 @@ export class ConditionBuilder {
|
|
|
148
147
|
return this
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
private static createOperatorSql(left: string, right: string, operator: Operator): string {
|
|
152
|
-
if (!Object.values(Operator).includes(operator)) {
|
|
150
|
+
private static createOperatorSql(left: string, right: string, operator: Operator | `${Operator}`): string {
|
|
151
|
+
if (!(Object.values(Operator) as string[]).includes(operator)) {
|
|
153
152
|
throw new Error(`Operator ${operator} is not supported`)
|
|
154
153
|
}
|
|
155
154
|
switch (operator) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { With } from './internal/With'
|
|
2
2
|
import { Where } from './internal/Where'
|
|
3
|
-
import { aliasLiteral } from '../utils'
|
|
3
|
+
import { aliasLiteral, formatColumnIdentifier } from '../utils'
|
|
4
4
|
import { Compiler } from './Compiler'
|
|
5
5
|
import { QueryBuilder } from './QueryBuilder'
|
|
6
6
|
import { Client, Connection } from '../client'
|
|
7
7
|
import { Literal } from '../Literal'
|
|
8
|
-
import { ConditionBuilder,
|
|
8
|
+
import { ConditionBuilder, ConditionExpression } from './ConditionBuilder'
|
|
9
9
|
import { LockModifier, LockType } from './LockType'
|
|
10
|
-
import { columnExpressionToLiteral
|
|
10
|
+
import { columnExpressionToLiteral } from './utils'
|
|
11
11
|
import { createSubQueryLiteralFactory, SubQueryExpression, SubQueryLiteralFactory } from './internal/Subqueries'
|
|
12
12
|
|
|
13
13
|
export type SelectBuilderSpecification = <Result>(qb: SelectBuilder<Result>) => SelectBuilder<Result>
|
|
@@ -87,7 +87,7 @@ class SelectBuilder<Result = SelectBuilder.Result> implements With.Aware, Where.
|
|
|
87
87
|
expression: QueryBuilder.ColumnIdentifier | Literal,
|
|
88
88
|
direction: SelectBuilder.OrderByDirection = 'asc',
|
|
89
89
|
): SelectBuilder<Result> {
|
|
90
|
-
const literal = expression instanceof Literal ? expression : new Literal(
|
|
90
|
+
const literal = expression instanceof Literal ? expression : new Literal(formatColumnIdentifier(expression))
|
|
91
91
|
return this.withOption('orderBy', [...this.options.orderBy, [literal, direction]])
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { QueryBuilder } from './QueryBuilder'
|
|
2
2
|
import { Literal } from '../Literal'
|
|
3
|
-
import { columnExpressionToLiteral
|
|
3
|
+
import { columnExpressionToLiteral } from './utils'
|
|
4
|
+
import { formatColumnIdentifier } from '../utils'
|
|
4
5
|
|
|
5
6
|
class WindowFunction<HasFunction extends boolean> implements QueryBuilder.Orderable<WindowFunction<HasFunction>> {
|
|
6
7
|
private constructor(
|
|
@@ -31,7 +32,7 @@ class WindowFunction<HasFunction extends boolean> implements QueryBuilder.Ordera
|
|
|
31
32
|
expression: QueryBuilder.ColumnIdentifier | Literal,
|
|
32
33
|
direction: 'asc' | 'desc' = 'asc',
|
|
33
34
|
): WindowFunction<HasFunction> {
|
|
34
|
-
const raw = expression instanceof Literal ? expression : new Literal(
|
|
35
|
+
const raw = expression instanceof Literal ? expression : new Literal(formatColumnIdentifier(expression))
|
|
35
36
|
return new WindowFunction(this.windowFunction, this.partitionByExpr, [
|
|
36
37
|
...this.orderByColumns,
|
|
37
38
|
raw.appendString(direction === 'asc' ? ' asc' : ' desc'),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QueryBuilder } from '../'
|
|
2
2
|
import { Literal } from '../../Literal'
|
|
3
3
|
import { Connection } from '../../client'
|
|
4
|
-
import {
|
|
4
|
+
import { formatColumnIdentifier } from '../../utils'
|
|
5
5
|
|
|
6
6
|
class Returning {
|
|
7
7
|
constructor(private readonly columns: (QueryBuilder.ColumnIdentifier | Literal)[] = []) {}
|
|
@@ -10,7 +10,7 @@ class Returning {
|
|
|
10
10
|
if (this.columns.length === 0) {
|
|
11
11
|
return new Literal('')
|
|
12
12
|
}
|
|
13
|
-
const columns = this.columns.map(it => (it instanceof Literal ? it : new Literal(
|
|
13
|
+
const columns = this.columns.map(it => (it instanceof Literal ? it : new Literal(formatColumnIdentifier(it))))
|
|
14
14
|
return new Literal(' returning ').appendAll(columns, ', ')
|
|
15
15
|
}
|
|
16
16
|
|
package/src/builders/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Literal } from '../Literal'
|
|
2
2
|
import { QueryBuilder } from './QueryBuilder'
|
|
3
3
|
import { ColumnExpressionFactory } from './ColumnExpressionFactory'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export { toFqnWrap }
|
|
4
|
+
import { formatColumnIdentifier } from '../utils'
|
|
7
5
|
|
|
8
6
|
export function resolveValues(values: QueryBuilder.Values): QueryBuilder.ResolvedValues {
|
|
9
7
|
return Object.entries(values)
|
|
@@ -23,7 +21,7 @@ export function columnExpressionToLiteral(
|
|
|
23
21
|
if (typeof expr === 'function') {
|
|
24
22
|
return expr(new ColumnExpressionFactory())
|
|
25
23
|
} else if (typeof expr === 'string' || Array.isArray(expr)) {
|
|
26
|
-
return new Literal(
|
|
24
|
+
return new Literal(formatColumnIdentifier(expr))
|
|
27
25
|
}
|
|
28
26
|
return expr
|
|
29
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ export class DatabaseMetadataResolver {
|
|
|
35
35
|
indexName: it.index_name,
|
|
36
36
|
tableName: it.table_name,
|
|
37
37
|
columnNames: it.columns,
|
|
38
|
+
unique: it.is_unique,
|
|
38
39
|
}))
|
|
39
40
|
|
|
40
41
|
return createDatabaseMetadata({
|
|
@@ -81,7 +82,8 @@ export class DatabaseMetadataResolver {
|
|
|
81
82
|
SELECT
|
|
82
83
|
MAX(idx_class.relname) AS index_name,
|
|
83
84
|
MAX(table_class.relname) AS table_name,
|
|
84
|
-
JSONB_AGG(DISTINCT pg_attribute.attname) AS columns
|
|
85
|
+
JSONB_AGG(DISTINCT pg_attribute.attname) AS columns,
|
|
86
|
+
BOOL_OR(indisunique) AS is_unique
|
|
85
87
|
FROM pg_index
|
|
86
88
|
JOIN pg_class AS table_class
|
|
87
89
|
ON pg_index.indrelid = table_class.oid
|
|
@@ -93,7 +95,6 @@ export class DatabaseMetadataResolver {
|
|
|
93
95
|
ON pg_attribute.attrelid = table_class.oid AND pg_attribute.attnum = ANY (pg_index.indkey)
|
|
94
96
|
WHERE pg_namespace.nspname = ?
|
|
95
97
|
AND indisprimary = FALSE
|
|
96
|
-
AND indisunique = FALSE
|
|
97
98
|
GROUP BY pg_index.indexrelid
|
|
98
99
|
`, [schema]))
|
|
99
100
|
.rows
|
|
@@ -135,5 +136,6 @@ type IndexRow = {
|
|
|
135
136
|
index_name: string
|
|
136
137
|
table_name: string
|
|
137
138
|
columns: string[]
|
|
139
|
+
is_unique: boolean
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -4,6 +4,7 @@ export interface IndexMetadata {
|
|
|
4
4
|
indexName: string
|
|
5
5
|
tableName: string
|
|
6
6
|
columnNames: string[]
|
|
7
|
+
unique: boolean
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export type IndexFilter = Partial<IndexMetadata>
|
|
@@ -33,6 +34,9 @@ export class IndexMetadataSet {
|
|
|
33
34
|
if (filter.columnNames !== undefined && !stringArrayEquals(it.columnNames, filter.columnNames)) {
|
|
34
35
|
return false
|
|
35
36
|
}
|
|
37
|
+
if (filter.unique !== undefined && it.unique !== filter.unique) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
36
40
|
return true
|
|
37
41
|
}))
|
|
38
42
|
}
|
package/src/utils/sql.ts
CHANGED
|
@@ -19,3 +19,11 @@ export const prependSchema = (tableExpression: string | Literal, schema: string,
|
|
|
19
19
|
: `${wrapIdentifier(schema)}.${wrapIdentifier(tableExpression)}`,
|
|
20
20
|
)
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
export function formatColumnIdentifier(columnName: string | [string, string]): string {
|
|
24
|
+
if (typeof columnName === 'string') {
|
|
25
|
+
return columnName === '*' ? '*' : wrapIdentifier(columnName)
|
|
26
|
+
}
|
|
27
|
+
const columnExpr = columnName[1] === '*' ? '*' : wrapIdentifier(columnName[1])
|
|
28
|
+
return `${wrapIdentifier(columnName[0])}.${columnExpr}`
|
|
29
|
+
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const sql = require("../utils/sql.cjs");
|
|
4
|
-
require("./Compiler.cjs");
|
|
5
|
-
require("../Literal.cjs");
|
|
6
|
-
require("./SelectBuilder.cjs");
|
|
7
|
-
require("./internal/With.cjs");
|
|
8
|
-
require("./internal/Where.cjs");
|
|
9
|
-
require("../client/EventManager.cjs");
|
|
10
|
-
require("@contember/queryable");
|
|
11
|
-
require("../client/Connection.cjs");
|
|
12
|
-
require("node:timers");
|
|
13
|
-
require("../utils/Mutex.cjs");
|
|
14
|
-
require("pg");
|
|
15
|
-
function toFqnWrap(columnName) {
|
|
16
|
-
if (typeof columnName === "string") {
|
|
17
|
-
return columnName === "*" ? "*" : sql.wrapIdentifier(columnName);
|
|
18
|
-
}
|
|
19
|
-
const columnExpr = columnName[1] === "*" ? "*" : sql.wrapIdentifier(columnName[1]);
|
|
20
|
-
return `${sql.wrapIdentifier(columnName[0])}.${columnExpr}`;
|
|
21
|
-
}
|
|
22
|
-
exports.toFqnWrap = toFqnWrap;
|
|
23
|
-
//# sourceMappingURL=formatUtils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatUtils.cjs","sources":["../../../../../packages/database/src/builders/formatUtils.ts"],"sourcesContent":["import { QueryBuilder } from './QueryBuilder'\nimport { wrapIdentifier } from '../utils'\n\nexport function toFqn(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName\n\t}\n\treturn `${columnName[0]}.${columnName[1]}`\n}\n\nexport function toFqnWrap(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName === '*' ? '*' : wrapIdentifier(columnName)\n\t}\n\tconst columnExpr = columnName[1] === '*' ? '*' : wrapIdentifier(columnName[1])\n\treturn `${wrapIdentifier(columnName[0])}.${columnExpr}`\n}\n"],"names":["wrapIdentifier"],"mappings":";;;;;;;;;;;;;;AAUO,SAAS,UAAU,YAAmD;AACxE,MAAA,OAAO,eAAe,UAAU;AACnC,WAAO,eAAe,MAAM,MAAMA,IAAAA,eAAe,UAAU;AAAA,EAAA;AAEtD,QAAA,aAAa,WAAW,CAAC,MAAM,MAAM,MAAMA,IAAA,eAAe,WAAW,CAAC,CAAC;AAC7E,SAAO,GAAGA,IAAAA,eAAe,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU;AACtD;;"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { wrapIdentifier } from "../utils/sql.js";
|
|
2
|
-
import "./Compiler.js";
|
|
3
|
-
import "../Literal.js";
|
|
4
|
-
import "./SelectBuilder.js";
|
|
5
|
-
import "./internal/With.js";
|
|
6
|
-
import "./internal/Where.js";
|
|
7
|
-
import "../client/EventManager.js";
|
|
8
|
-
import "@contember/queryable";
|
|
9
|
-
import "../client/Connection.js";
|
|
10
|
-
import "node:timers";
|
|
11
|
-
import "../utils/Mutex.js";
|
|
12
|
-
import "pg";
|
|
13
|
-
function toFqnWrap(columnName) {
|
|
14
|
-
if (typeof columnName === "string") {
|
|
15
|
-
return columnName === "*" ? "*" : wrapIdentifier(columnName);
|
|
16
|
-
}
|
|
17
|
-
const columnExpr = columnName[1] === "*" ? "*" : wrapIdentifier(columnName[1]);
|
|
18
|
-
return `${wrapIdentifier(columnName[0])}.${columnExpr}`;
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
toFqnWrap
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=formatUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatUtils.js","sources":["../../../../../packages/database/src/builders/formatUtils.ts"],"sourcesContent":["import { QueryBuilder } from './QueryBuilder'\nimport { wrapIdentifier } from '../utils'\n\nexport function toFqn(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName\n\t}\n\treturn `${columnName[0]}.${columnName[1]}`\n}\n\nexport function toFqnWrap(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName === '*' ? '*' : wrapIdentifier(columnName)\n\t}\n\tconst columnExpr = columnName[1] === '*' ? '*' : wrapIdentifier(columnName[1])\n\treturn `${wrapIdentifier(columnName[0])}.${columnExpr}`\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAUO,SAAS,UAAU,YAAmD;AACxE,MAAA,OAAO,eAAe,UAAU;AACnC,WAAO,eAAe,MAAM,MAAM,eAAe,UAAU;AAAA,EAAA;AAEtD,QAAA,aAAa,WAAW,CAAC,MAAM,MAAM,MAAM,eAAe,WAAW,CAAC,CAAC;AAC7E,SAAO,GAAG,eAAe,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU;AACtD;"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const sql = require("../utils/sql.cjs");
|
|
4
|
-
require("./Compiler.cjs");
|
|
5
|
-
require("../Literal.cjs");
|
|
6
|
-
require("./SelectBuilder.cjs");
|
|
7
|
-
require("./internal/With.cjs");
|
|
8
|
-
require("./internal/Where.cjs");
|
|
9
|
-
require("../client/EventManager.cjs");
|
|
10
|
-
require("@contember/queryable");
|
|
11
|
-
require("../client/Connection.cjs");
|
|
12
|
-
require("node:timers");
|
|
13
|
-
require("../utils/Mutex.cjs");
|
|
14
|
-
require("pg");
|
|
15
|
-
function toFqnWrap(columnName) {
|
|
16
|
-
if (typeof columnName === "string") {
|
|
17
|
-
return columnName === "*" ? "*" : sql.wrapIdentifier(columnName);
|
|
18
|
-
}
|
|
19
|
-
const columnExpr = columnName[1] === "*" ? "*" : sql.wrapIdentifier(columnName[1]);
|
|
20
|
-
return `${sql.wrapIdentifier(columnName[0])}.${columnExpr}`;
|
|
21
|
-
}
|
|
22
|
-
exports.toFqnWrap = toFqnWrap;
|
|
23
|
-
//# sourceMappingURL=formatUtils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatUtils.cjs","sources":["../../../../../packages/database/src/builders/formatUtils.ts"],"sourcesContent":["import { QueryBuilder } from './QueryBuilder'\nimport { wrapIdentifier } from '../utils'\n\nexport function toFqn(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName\n\t}\n\treturn `${columnName[0]}.${columnName[1]}`\n}\n\nexport function toFqnWrap(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName === '*' ? '*' : wrapIdentifier(columnName)\n\t}\n\tconst columnExpr = columnName[1] === '*' ? '*' : wrapIdentifier(columnName[1])\n\treturn `${wrapIdentifier(columnName[0])}.${columnExpr}`\n}\n"],"names":["wrapIdentifier"],"mappings":";;;;;;;;;;;;;;AAUO,SAAS,UAAU,YAAmD;AACxE,MAAA,OAAO,eAAe,UAAU;AACnC,WAAO,eAAe,MAAM,MAAMA,IAAAA,eAAe,UAAU;AAAA,EAAA;AAEtD,QAAA,aAAa,WAAW,CAAC,MAAM,MAAM,MAAMA,IAAA,eAAe,WAAW,CAAC,CAAC;AAC7E,SAAO,GAAGA,IAAAA,eAAe,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU;AACtD;;"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { wrapIdentifier } from "../utils/sql.js";
|
|
2
|
-
import "./Compiler.js";
|
|
3
|
-
import "../Literal.js";
|
|
4
|
-
import "./SelectBuilder.js";
|
|
5
|
-
import "./internal/With.js";
|
|
6
|
-
import "./internal/Where.js";
|
|
7
|
-
import "../client/EventManager.js";
|
|
8
|
-
import "@contember/queryable";
|
|
9
|
-
import "../client/Connection.js";
|
|
10
|
-
import "node:timers";
|
|
11
|
-
import "../utils/Mutex.js";
|
|
12
|
-
import "pg";
|
|
13
|
-
function toFqnWrap(columnName) {
|
|
14
|
-
if (typeof columnName === "string") {
|
|
15
|
-
return columnName === "*" ? "*" : wrapIdentifier(columnName);
|
|
16
|
-
}
|
|
17
|
-
const columnExpr = columnName[1] === "*" ? "*" : wrapIdentifier(columnName[1]);
|
|
18
|
-
return `${wrapIdentifier(columnName[0])}.${columnExpr}`;
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
toFqnWrap
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=formatUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatUtils.js","sources":["../../../../../packages/database/src/builders/formatUtils.ts"],"sourcesContent":["import { QueryBuilder } from './QueryBuilder'\nimport { wrapIdentifier } from '../utils'\n\nexport function toFqn(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName\n\t}\n\treturn `${columnName[0]}.${columnName[1]}`\n}\n\nexport function toFqnWrap(columnName: QueryBuilder.ColumnIdentifier): string {\n\tif (typeof columnName === 'string') {\n\t\treturn columnName === '*' ? '*' : wrapIdentifier(columnName)\n\t}\n\tconst columnExpr = columnName[1] === '*' ? '*' : wrapIdentifier(columnName[1])\n\treturn `${wrapIdentifier(columnName[0])}.${columnExpr}`\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAUO,SAAS,UAAU,YAAmD;AACxE,MAAA,OAAO,eAAe,UAAU;AACnC,WAAO,eAAe,MAAM,MAAM,eAAe,UAAU;AAAA,EAAA;AAEtD,QAAA,aAAa,WAAW,CAAC,MAAM,MAAM,MAAM,eAAe,WAAW,CAAC,CAAC;AAC7E,SAAO,GAAG,eAAe,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU;AACtD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatUtils.d.ts","sourceRoot":"","sources":["../../../src/builders/formatUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,wBAAgB,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,gBAAgB,GAAG,MAAM,CAKvE;AAED,wBAAgB,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC,gBAAgB,GAAG,MAAM,CAM3E"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
2
|
-
import { wrapIdentifier } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function toFqn(columnName: QueryBuilder.ColumnIdentifier): string {
|
|
5
|
-
if (typeof columnName === 'string') {
|
|
6
|
-
return columnName
|
|
7
|
-
}
|
|
8
|
-
return `${columnName[0]}.${columnName[1]}`
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function toFqnWrap(columnName: QueryBuilder.ColumnIdentifier): string {
|
|
12
|
-
if (typeof columnName === 'string') {
|
|
13
|
-
return columnName === '*' ? '*' : wrapIdentifier(columnName)
|
|
14
|
-
}
|
|
15
|
-
const columnExpr = columnName[1] === '*' ? '*' : wrapIdentifier(columnName[1])
|
|
16
|
-
return `${wrapIdentifier(columnName[0])}.${columnExpr}`
|
|
17
|
-
}
|