@nocobase/database 2.1.24 → 2.1.26
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/lib/database.js +4 -1
- package/lib/query-interface/mysql-query-interface.d.ts +4 -1
- package/lib/query-interface/mysql-query-interface.js +8 -3
- package/lib/query-interface/postgres-query-interface.d.ts +8 -2
- package/lib/query-interface/postgres-query-interface.js +31 -17
- package/lib/query-interface/query-interface.d.ts +4 -1
- package/lib/query-interface/sqlite-query-interface.d.ts +4 -1
- package/lib/query-interface/sqlite-query-interface.js +6 -3
- package/package.json +4 -4
package/lib/database.js
CHANGED
|
@@ -772,7 +772,10 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
772
772
|
},
|
|
773
773
|
async onDump(dumper, collection) {
|
|
774
774
|
try {
|
|
775
|
-
const viewDef = await collection.db.queryInterface.viewDef(
|
|
775
|
+
const viewDef = await collection.db.queryInterface.viewDef({
|
|
776
|
+
viewName: collection.model.tableName,
|
|
777
|
+
schema: collection.db.inDialect("postgres") ? collection.collectionSchema() : void 0
|
|
778
|
+
});
|
|
776
779
|
dumper.writeSQLContent(`view-${collection.name}`, {
|
|
777
780
|
sql: [
|
|
778
781
|
`DROP VIEW IF EXISTS ${collection.getTableNameWithSchemaAsString()}`,
|
|
@@ -24,7 +24,10 @@ export default class MysqlQueryInterface extends QueryInterface {
|
|
|
24
24
|
};
|
|
25
25
|
}>;
|
|
26
26
|
parseSQL(sql: string): any;
|
|
27
|
-
viewDef(
|
|
27
|
+
viewDef(options: {
|
|
28
|
+
viewName: string;
|
|
29
|
+
schema?: string;
|
|
30
|
+
}): Promise<string>;
|
|
28
31
|
showTableDefinition(tableInfo: TableInfo): Promise<any>;
|
|
29
32
|
getAutoIncrementInfo(options: {
|
|
30
33
|
tableInfo: TableInfo;
|
|
@@ -67,7 +67,7 @@ const _MysqlQueryInterface = class _MysqlQueryInterface extends import_query_int
|
|
|
67
67
|
}
|
|
68
68
|
async viewColumnUsage(options) {
|
|
69
69
|
try {
|
|
70
|
-
const { ast } = this.parseSQL(await this.viewDef(options
|
|
70
|
+
const { ast } = this.parseSQL(await this.viewDef(options));
|
|
71
71
|
const columns = ast.columns;
|
|
72
72
|
const results = [];
|
|
73
73
|
for (const column of columns) {
|
|
@@ -90,8 +90,13 @@ const _MysqlQueryInterface = class _MysqlQueryInterface extends import_query_int
|
|
|
90
90
|
parseSQL(sql) {
|
|
91
91
|
return import_sql_parser.default.parse(sql);
|
|
92
92
|
}
|
|
93
|
-
async viewDef(
|
|
94
|
-
const
|
|
93
|
+
async viewDef(options) {
|
|
94
|
+
const tableName = options.schema ? {
|
|
95
|
+
schema: options.schema,
|
|
96
|
+
tableName: options.viewName
|
|
97
|
+
} : options.viewName;
|
|
98
|
+
const quotedViewName = this.db.utils.quoteTable(tableName);
|
|
99
|
+
const viewDefinition = await this.db.sequelize.query(`SHOW CREATE VIEW ${quotedViewName}`, { type: "SELECT" });
|
|
95
100
|
const createView = viewDefinition[0]["Create View"];
|
|
96
101
|
const regex = /(?<=AS\s)([\s\S]*)/i;
|
|
97
102
|
const match = createView.match(regex);
|
|
@@ -30,9 +30,15 @@ export default class PostgresQueryInterface extends QueryInterface {
|
|
|
30
30
|
listViews(options?: {
|
|
31
31
|
schema?: string;
|
|
32
32
|
}): Promise<[unknown[], unknown]>;
|
|
33
|
-
viewDef(
|
|
33
|
+
viewDef(options: {
|
|
34
|
+
viewName: string;
|
|
35
|
+
schema?: string;
|
|
36
|
+
}): Promise<string>;
|
|
34
37
|
parseSQL(sql: string): any;
|
|
35
|
-
viewColumnUsage(options:
|
|
38
|
+
viewColumnUsage(options: {
|
|
39
|
+
viewName: string;
|
|
40
|
+
schema?: string;
|
|
41
|
+
}): Promise<{
|
|
36
42
|
[view_column_name: string]: {
|
|
37
43
|
column_name: string;
|
|
38
44
|
table_name: string;
|
|
@@ -113,26 +113,33 @@ const _PostgresQueryInterface = class _PostgresQueryInterface extends import_que
|
|
|
113
113
|
async listViews(options) {
|
|
114
114
|
var _a;
|
|
115
115
|
const targetSchema = (options == null ? void 0 : options.schema) || ((_a = this.db.options) == null ? void 0 : _a.schema) || "public";
|
|
116
|
-
const sql =
|
|
117
|
-
SELECT viewname as name, definition, schemaname as schema
|
|
118
|
-
FROM pg_views
|
|
119
|
-
WHERE schemaname = '${targetSchema}'
|
|
120
|
-
ORDER BY viewname;
|
|
121
|
-
` : `
|
|
116
|
+
const sql = `
|
|
122
117
|
SELECT viewname as name, definition, schemaname as schema
|
|
123
118
|
FROM pg_views
|
|
124
|
-
WHERE schemaname
|
|
119
|
+
WHERE schemaname = :targetSchema
|
|
125
120
|
ORDER BY viewname;
|
|
126
121
|
`;
|
|
127
|
-
return await this.db.sequelize.query(sql, {
|
|
122
|
+
return await this.db.sequelize.query(sql, {
|
|
123
|
+
replacements: {
|
|
124
|
+
targetSchema
|
|
125
|
+
},
|
|
126
|
+
type: "SELECT"
|
|
127
|
+
});
|
|
128
128
|
}
|
|
129
|
-
async viewDef(
|
|
130
|
-
const
|
|
129
|
+
async viewDef(options) {
|
|
130
|
+
const { viewName } = options;
|
|
131
|
+
const schema = options.schema || this.db.options.schema || "public";
|
|
131
132
|
const viewDefQuery = await this.db.sequelize.query(
|
|
132
133
|
`
|
|
133
|
-
select pg_get_viewdef(format('%I.%I',
|
|
134
|
+
select pg_get_viewdef(format('%I.%I', :schema, :viewName)::regclass, true) as definition
|
|
134
135
|
`,
|
|
135
|
-
{
|
|
136
|
+
{
|
|
137
|
+
replacements: {
|
|
138
|
+
schema,
|
|
139
|
+
viewName
|
|
140
|
+
},
|
|
141
|
+
type: "SELECT"
|
|
142
|
+
}
|
|
136
143
|
);
|
|
137
144
|
return import_lodash.default.trim(viewDefQuery[0]["definition"]);
|
|
138
145
|
}
|
|
@@ -142,15 +149,22 @@ const _PostgresQueryInterface = class _PostgresQueryInterface extends import_que
|
|
|
142
149
|
});
|
|
143
150
|
}
|
|
144
151
|
async viewColumnUsage(options) {
|
|
145
|
-
const { viewName
|
|
152
|
+
const { viewName } = options;
|
|
153
|
+
const schema = options.schema || this.db.options.schema || "public";
|
|
146
154
|
const sql = `
|
|
147
155
|
SELECT *
|
|
148
156
|
FROM information_schema.view_column_usage
|
|
149
|
-
WHERE view_schema =
|
|
150
|
-
AND view_name =
|
|
157
|
+
WHERE view_schema = :schema
|
|
158
|
+
AND view_name = :viewName;
|
|
151
159
|
`;
|
|
152
|
-
const columnUsages = await this.db.sequelize.query(sql, {
|
|
153
|
-
|
|
160
|
+
const columnUsages = await this.db.sequelize.query(sql, {
|
|
161
|
+
replacements: {
|
|
162
|
+
schema,
|
|
163
|
+
viewName
|
|
164
|
+
},
|
|
165
|
+
type: "SELECT"
|
|
166
|
+
});
|
|
167
|
+
const def = await this.viewDef({ schema, viewName });
|
|
154
168
|
try {
|
|
155
169
|
const { ast } = this.parseSQL(def);
|
|
156
170
|
const columns = ast[0].columns;
|
|
@@ -21,7 +21,10 @@ export default abstract class QueryInterface {
|
|
|
21
21
|
abstract listViews(options?: {
|
|
22
22
|
schema?: string;
|
|
23
23
|
}): any;
|
|
24
|
-
abstract viewDef(
|
|
24
|
+
abstract viewDef(options: {
|
|
25
|
+
viewName: string;
|
|
26
|
+
schema?: string;
|
|
27
|
+
}): Promise<string>;
|
|
25
28
|
abstract viewColumnUsage(options: {
|
|
26
29
|
viewName: string;
|
|
27
30
|
schema?: string;
|
|
@@ -24,7 +24,10 @@ export default class SqliteQueryInterface extends QueryInterface {
|
|
|
24
24
|
};
|
|
25
25
|
}>;
|
|
26
26
|
parseSQL(sql: string): any;
|
|
27
|
-
viewDef(
|
|
27
|
+
viewDef(options: {
|
|
28
|
+
viewName: string;
|
|
29
|
+
schema?: string;
|
|
30
|
+
}): Promise<string>;
|
|
28
31
|
showTableDefinition(tableInfo: TableInfo): Promise<any>;
|
|
29
32
|
getAutoIncrementInfo(options: {
|
|
30
33
|
tableInfo: TableInfo;
|
|
@@ -70,7 +70,7 @@ const _SqliteQueryInterface = class _SqliteQueryInterface extends import_query_i
|
|
|
70
70
|
}
|
|
71
71
|
async viewColumnUsage(options) {
|
|
72
72
|
try {
|
|
73
|
-
const { ast } = this.parseSQL(await this.viewDef(options
|
|
73
|
+
const { ast } = this.parseSQL(await this.viewDef(options));
|
|
74
74
|
const columns = ast.columns;
|
|
75
75
|
const results = [];
|
|
76
76
|
for (const column of columns) {
|
|
@@ -93,12 +93,15 @@ const _SqliteQueryInterface = class _SqliteQueryInterface extends import_query_i
|
|
|
93
93
|
parseSQL(sql) {
|
|
94
94
|
return import_sql_parser.default.parse(sql);
|
|
95
95
|
}
|
|
96
|
-
async viewDef(
|
|
96
|
+
async viewDef(options) {
|
|
97
97
|
const viewDefinition = await this.db.sequelize.query(
|
|
98
98
|
`SELECT sql
|
|
99
99
|
FROM sqlite_master
|
|
100
|
-
WHERE name =
|
|
100
|
+
WHERE name = :viewName AND type = 'view'`,
|
|
101
101
|
{
|
|
102
|
+
replacements: {
|
|
103
|
+
viewName: options.viewName
|
|
104
|
+
},
|
|
102
105
|
type: "SELECT"
|
|
103
106
|
}
|
|
104
107
|
);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "2.1.
|
|
10
|
-
"@nocobase/utils": "2.1.
|
|
9
|
+
"@nocobase/logger": "2.1.26",
|
|
10
|
+
"@nocobase/utils": "2.1.26",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "b25700115794487b342ac33a63a1a988c75c112c"
|
|
42
42
|
}
|