kysely 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/dialect/postgres/postgres-introspector.js +15 -13
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/operation-node/reference-node.d.ts +1 -1
- package/dist/cjs/operation-node/reference-node.js +1 -2
- package/dist/cjs/operation-node/selection-node.d.ts +2 -1
- package/dist/cjs/parser/select-parser.js +2 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +15 -13
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/operation-node/reference-node.d.ts +1 -1
- package/dist/esm/operation-node/reference-node.js +1 -2
- package/dist/esm/operation-node/selection-node.d.ts +2 -1
- package/dist/esm/parser/select-parser.js +2 -1
- package/package.json +1 -1
|
@@ -22,38 +22,40 @@ class PostgresIntrospector {
|
|
|
22
22
|
.selectFrom('pg_catalog.pg_attribute as a')
|
|
23
23
|
.innerJoin('pg_catalog.pg_class as c', 'a.attrelid', 'c.oid')
|
|
24
24
|
.innerJoin('pg_catalog.pg_namespace as ns', 'c.relnamespace', 'ns.oid')
|
|
25
|
-
.innerJoin('pg_catalog.pg_tables as t', (join) => join
|
|
26
|
-
.onRef('t.tablename', '=', 'c.relname')
|
|
27
|
-
.onRef('t.schemaname', '=', 'ns.nspname'))
|
|
28
25
|
.innerJoin('pg_catalog.pg_type as typ', 'a.atttypid', 'typ.oid')
|
|
29
26
|
.select([
|
|
30
27
|
'a.attname as column',
|
|
31
28
|
'a.attnotnull as not_null',
|
|
32
29
|
'a.atthasdef as has_default',
|
|
33
|
-
'
|
|
34
|
-
'
|
|
30
|
+
'c.relname as table',
|
|
31
|
+
'ns.nspname as schema',
|
|
35
32
|
'typ.typname as type',
|
|
36
33
|
// Detect if the column is auto incrementing by finding the sequence
|
|
37
34
|
// that is created for `serial` and `bigserial` columns.
|
|
38
35
|
this.#db
|
|
39
36
|
.selectFrom('pg_class')
|
|
40
37
|
.select((0, sql_js_1.sql) `true`.as('auto_incrementing'))
|
|
38
|
+
// Make sure the sequence is in the same schema as the table.
|
|
39
|
+
.whereRef('relnamespace', '=', 'c.relnamespace')
|
|
41
40
|
.where('relkind', '=', 'S')
|
|
42
|
-
.where('relname', '=', (0, sql_js_1.sql) `
|
|
41
|
+
.where('relname', '=', (0, sql_js_1.sql) `c.relname || '_' || a.attname || '_seq'`)
|
|
43
42
|
.as('auto_incrementing'),
|
|
44
43
|
])
|
|
45
|
-
|
|
46
|
-
.where('
|
|
47
|
-
.where('
|
|
44
|
+
// r == normal table
|
|
45
|
+
.where('c.relkind', '=', 'r')
|
|
46
|
+
.where('ns.nspname', '!~', '^pg_')
|
|
47
|
+
.where('ns.nspname', '!=', 'information_schema')
|
|
48
|
+
// No system columns
|
|
49
|
+
.where('a.attnum', '>=', 0)
|
|
48
50
|
.where('a.attisdropped', '!=', true)
|
|
49
|
-
.orderBy('
|
|
50
|
-
.orderBy('
|
|
51
|
+
.orderBy('ns.nspname')
|
|
52
|
+
.orderBy('c.relname')
|
|
51
53
|
.orderBy('a.attname')
|
|
52
54
|
.castTo();
|
|
53
55
|
if (!options.withInternalKyselyTables) {
|
|
54
56
|
query = query
|
|
55
|
-
.where('
|
|
56
|
-
.where('
|
|
57
|
+
.where('c.relname', '!=', migrator_js_1.DEFAULT_MIGRATION_TABLE)
|
|
58
|
+
.where('c.relname', '!=', migrator_js_1.DEFAULT_MIGRATION_LOCK_TABLE);
|
|
57
59
|
}
|
|
58
60
|
const rawColumns = await query.execute();
|
|
59
61
|
return this.#parseTableMetadata(rawColumns);
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export * from './migration/file-migration-provider.js';
|
|
|
73
73
|
export * from './plugin/kysely-plugin.js';
|
|
74
74
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
75
75
|
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
76
|
+
export * from './plugin/with-schema/with-schema-plugin.js';
|
|
76
77
|
export * from './operation-node/add-column-node.js';
|
|
77
78
|
export * from './operation-node/add-constraint-node.js';
|
|
78
79
|
export * from './operation-node/alias-node.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -89,6 +89,7 @@ __exportStar(require("./migration/file-migration-provider.js"), exports);
|
|
|
89
89
|
__exportStar(require("./plugin/kysely-plugin.js"), exports);
|
|
90
90
|
__exportStar(require("./plugin/camel-case/camel-case-plugin.js"), exports);
|
|
91
91
|
__exportStar(require("./plugin/deduplicate-joins/deduplicate-joins-plugin.js"), exports);
|
|
92
|
+
__exportStar(require("./plugin/with-schema/with-schema-plugin.js"), exports);
|
|
92
93
|
__exportStar(require("./operation-node/add-column-node.js"), exports);
|
|
93
94
|
__exportStar(require("./operation-node/add-constraint-node.js"), exports);
|
|
94
95
|
__exportStar(require("./operation-node/alias-node.js"), exports);
|
|
@@ -13,5 +13,5 @@ export interface ReferenceNode extends OperationNode {
|
|
|
13
13
|
export declare const ReferenceNode: Readonly<{
|
|
14
14
|
is(node: OperationNode): node is ReferenceNode;
|
|
15
15
|
create(table: TableNode, column: ColumnNode): ReferenceNode;
|
|
16
|
-
createSelectAll(table:
|
|
16
|
+
createSelectAll(table: TableNode): ReferenceNode;
|
|
17
17
|
}>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReferenceNode = void 0;
|
|
4
|
-
const table_node_js_1 = require("./table-node.js");
|
|
5
4
|
const select_all_node_js_1 = require("./select-all-node.js");
|
|
6
5
|
const object_utils_js_1 = require("../util/object-utils.js");
|
|
7
6
|
/**
|
|
@@ -21,7 +20,7 @@ exports.ReferenceNode = (0, object_utils_js_1.freeze)({
|
|
|
21
20
|
createSelectAll(table) {
|
|
22
21
|
return (0, object_utils_js_1.freeze)({
|
|
23
22
|
kind: 'ReferenceNode',
|
|
24
|
-
table
|
|
23
|
+
table,
|
|
25
24
|
column: select_all_node_js_1.SelectAllNode.create(),
|
|
26
25
|
});
|
|
27
26
|
},
|
|
@@ -3,6 +3,7 @@ import { ColumnNode } from './column-node.js';
|
|
|
3
3
|
import { OperationNode } from './operation-node.js';
|
|
4
4
|
import { ReferenceNode } from './reference-node.js';
|
|
5
5
|
import { SelectAllNode } from './select-all-node.js';
|
|
6
|
+
import { TableNode } from './table-node.js';
|
|
6
7
|
declare type SelectionNodeChild = ColumnNode | ReferenceNode | AliasNode | SelectAllNode;
|
|
7
8
|
export interface SelectionNode extends OperationNode {
|
|
8
9
|
readonly kind: 'SelectionNode';
|
|
@@ -15,6 +16,6 @@ export declare const SelectionNode: Readonly<{
|
|
|
15
16
|
is(node: OperationNode): node is SelectionNode;
|
|
16
17
|
create(selection: SelectionNodeChild): SelectionNode;
|
|
17
18
|
createSelectAll(): SelectionNode;
|
|
18
|
-
createSelectAllFromTable(table:
|
|
19
|
+
createSelectAllFromTable(table: TableNode): SelectionNode;
|
|
19
20
|
}>;
|
|
20
21
|
export {};
|
|
@@ -6,6 +6,7 @@ const selection_node_js_1 = require("../operation-node/selection-node.js");
|
|
|
6
6
|
const reference_parser_js_1 = require("./reference-parser.js");
|
|
7
7
|
const dynamic_reference_builder_js_1 = require("../dynamic/dynamic-reference-builder.js");
|
|
8
8
|
const complex_expression_parser_js_1 = require("./complex-expression-parser.js");
|
|
9
|
+
const table_parser_js_1 = require("./table-parser.js");
|
|
9
10
|
function parseSelectExpressionOrList(selection) {
|
|
10
11
|
if ((0, object_utils_js_1.isReadonlyArray)(selection)) {
|
|
11
12
|
return selection.map((it) => parseSelectExpression(it));
|
|
@@ -40,7 +41,7 @@ function parseSelectAll(table) {
|
|
|
40
41
|
exports.parseSelectAll = parseSelectAll;
|
|
41
42
|
function parseSelectAllArg(table) {
|
|
42
43
|
if ((0, object_utils_js_1.isString)(table)) {
|
|
43
|
-
return selection_node_js_1.SelectionNode.createSelectAllFromTable(table);
|
|
44
|
+
return selection_node_js_1.SelectionNode.createSelectAllFromTable((0, table_parser_js_1.parseTable)(table));
|
|
44
45
|
}
|
|
45
46
|
throw new Error(`invalid value selectAll expression: ${JSON.stringify(table)}`);
|
|
46
47
|
}
|
|
@@ -20,38 +20,40 @@ export class PostgresIntrospector {
|
|
|
20
20
|
.selectFrom('pg_catalog.pg_attribute as a')
|
|
21
21
|
.innerJoin('pg_catalog.pg_class as c', 'a.attrelid', 'c.oid')
|
|
22
22
|
.innerJoin('pg_catalog.pg_namespace as ns', 'c.relnamespace', 'ns.oid')
|
|
23
|
-
.innerJoin('pg_catalog.pg_tables as t', (join) => join
|
|
24
|
-
.onRef('t.tablename', '=', 'c.relname')
|
|
25
|
-
.onRef('t.schemaname', '=', 'ns.nspname'))
|
|
26
23
|
.innerJoin('pg_catalog.pg_type as typ', 'a.atttypid', 'typ.oid')
|
|
27
24
|
.select([
|
|
28
25
|
'a.attname as column',
|
|
29
26
|
'a.attnotnull as not_null',
|
|
30
27
|
'a.atthasdef as has_default',
|
|
31
|
-
'
|
|
32
|
-
'
|
|
28
|
+
'c.relname as table',
|
|
29
|
+
'ns.nspname as schema',
|
|
33
30
|
'typ.typname as type',
|
|
34
31
|
// Detect if the column is auto incrementing by finding the sequence
|
|
35
32
|
// that is created for `serial` and `bigserial` columns.
|
|
36
33
|
this.#db
|
|
37
34
|
.selectFrom('pg_class')
|
|
38
35
|
.select(sql `true`.as('auto_incrementing'))
|
|
36
|
+
// Make sure the sequence is in the same schema as the table.
|
|
37
|
+
.whereRef('relnamespace', '=', 'c.relnamespace')
|
|
39
38
|
.where('relkind', '=', 'S')
|
|
40
|
-
.where('relname', '=', sql `
|
|
39
|
+
.where('relname', '=', sql `c.relname || '_' || a.attname || '_seq'`)
|
|
41
40
|
.as('auto_incrementing'),
|
|
42
41
|
])
|
|
43
|
-
|
|
44
|
-
.where('
|
|
45
|
-
.where('
|
|
42
|
+
// r == normal table
|
|
43
|
+
.where('c.relkind', '=', 'r')
|
|
44
|
+
.where('ns.nspname', '!~', '^pg_')
|
|
45
|
+
.where('ns.nspname', '!=', 'information_schema')
|
|
46
|
+
// No system columns
|
|
47
|
+
.where('a.attnum', '>=', 0)
|
|
46
48
|
.where('a.attisdropped', '!=', true)
|
|
47
|
-
.orderBy('
|
|
48
|
-
.orderBy('
|
|
49
|
+
.orderBy('ns.nspname')
|
|
50
|
+
.orderBy('c.relname')
|
|
49
51
|
.orderBy('a.attname')
|
|
50
52
|
.castTo();
|
|
51
53
|
if (!options.withInternalKyselyTables) {
|
|
52
54
|
query = query
|
|
53
|
-
.where('
|
|
54
|
-
.where('
|
|
55
|
+
.where('c.relname', '!=', DEFAULT_MIGRATION_TABLE)
|
|
56
|
+
.where('c.relname', '!=', DEFAULT_MIGRATION_LOCK_TABLE);
|
|
55
57
|
}
|
|
56
58
|
const rawColumns = await query.execute();
|
|
57
59
|
return this.#parseTableMetadata(rawColumns);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export * from './migration/file-migration-provider.js';
|
|
|
73
73
|
export * from './plugin/kysely-plugin.js';
|
|
74
74
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
75
75
|
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
76
|
+
export * from './plugin/with-schema/with-schema-plugin.js';
|
|
76
77
|
export * from './operation-node/add-column-node.js';
|
|
77
78
|
export * from './operation-node/add-constraint-node.js';
|
|
78
79
|
export * from './operation-node/alias-node.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -74,6 +74,7 @@ export * from './migration/file-migration-provider.js';
|
|
|
74
74
|
export * from './plugin/kysely-plugin.js';
|
|
75
75
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
76
76
|
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
77
|
+
export * from './plugin/with-schema/with-schema-plugin.js';
|
|
77
78
|
export * from './operation-node/add-column-node.js';
|
|
78
79
|
export * from './operation-node/add-constraint-node.js';
|
|
79
80
|
export * from './operation-node/alias-node.js';
|
|
@@ -13,5 +13,5 @@ export interface ReferenceNode extends OperationNode {
|
|
|
13
13
|
export declare const ReferenceNode: Readonly<{
|
|
14
14
|
is(node: OperationNode): node is ReferenceNode;
|
|
15
15
|
create(table: TableNode, column: ColumnNode): ReferenceNode;
|
|
16
|
-
createSelectAll(table:
|
|
16
|
+
createSelectAll(table: TableNode): ReferenceNode;
|
|
17
17
|
}>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="./reference-node.d.ts" />
|
|
2
|
-
import { TableNode } from './table-node.js';
|
|
3
2
|
import { SelectAllNode } from './select-all-node.js';
|
|
4
3
|
import { freeze } from '../util/object-utils.js';
|
|
5
4
|
/**
|
|
@@ -19,7 +18,7 @@ export const ReferenceNode = freeze({
|
|
|
19
18
|
createSelectAll(table) {
|
|
20
19
|
return freeze({
|
|
21
20
|
kind: 'ReferenceNode',
|
|
22
|
-
table
|
|
21
|
+
table,
|
|
23
22
|
column: SelectAllNode.create(),
|
|
24
23
|
});
|
|
25
24
|
},
|
|
@@ -3,6 +3,7 @@ import { ColumnNode } from './column-node.js';
|
|
|
3
3
|
import { OperationNode } from './operation-node.js';
|
|
4
4
|
import { ReferenceNode } from './reference-node.js';
|
|
5
5
|
import { SelectAllNode } from './select-all-node.js';
|
|
6
|
+
import { TableNode } from './table-node.js';
|
|
6
7
|
declare type SelectionNodeChild = ColumnNode | ReferenceNode | AliasNode | SelectAllNode;
|
|
7
8
|
export interface SelectionNode extends OperationNode {
|
|
8
9
|
readonly kind: 'SelectionNode';
|
|
@@ -15,6 +16,6 @@ export declare const SelectionNode: Readonly<{
|
|
|
15
16
|
is(node: OperationNode): node is SelectionNode;
|
|
16
17
|
create(selection: SelectionNodeChild): SelectionNode;
|
|
17
18
|
createSelectAll(): SelectionNode;
|
|
18
|
-
createSelectAllFromTable(table:
|
|
19
|
+
createSelectAllFromTable(table: TableNode): SelectionNode;
|
|
19
20
|
}>;
|
|
20
21
|
export {};
|
|
@@ -4,6 +4,7 @@ import { SelectionNode } from '../operation-node/selection-node.js';
|
|
|
4
4
|
import { parseAliasedStringReference } from './reference-parser.js';
|
|
5
5
|
import { isDynamicReferenceBuilder, } from '../dynamic/dynamic-reference-builder.js';
|
|
6
6
|
import { parseAliasedComplexExpression, } from './complex-expression-parser.js';
|
|
7
|
+
import { parseTable } from './table-parser.js';
|
|
7
8
|
export function parseSelectExpressionOrList(selection) {
|
|
8
9
|
if (isReadonlyArray(selection)) {
|
|
9
10
|
return selection.map((it) => parseSelectExpression(it));
|
|
@@ -36,7 +37,7 @@ export function parseSelectAll(table) {
|
|
|
36
37
|
}
|
|
37
38
|
function parseSelectAllArg(table) {
|
|
38
39
|
if (isString(table)) {
|
|
39
|
-
return SelectionNode.createSelectAllFromTable(table);
|
|
40
|
+
return SelectionNode.createSelectAllFromTable(parseTable(table));
|
|
40
41
|
}
|
|
41
42
|
throw new Error(`invalid value selectAll expression: ${JSON.stringify(table)}`);
|
|
42
43
|
}
|