mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 04:06:00 +00:00
refactor: move sqlite queries to sql directory
This commit is contained in:
@@ -1,19 +1,6 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const { DatabaseAnalyser } = global.DBGATE_PACKAGES['dbgate-tools'];
|
const { DatabaseAnalyser } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||||
|
const sql = require('./sql');
|
||||||
const indexcolsQuery = `
|
|
||||||
SELECT
|
|
||||||
m.name as tableName,
|
|
||||||
il.name as constraintName,
|
|
||||||
il."unique" as isUnique,
|
|
||||||
ii.name as columnName,
|
|
||||||
il.origin
|
|
||||||
FROM sqlite_schema AS m,
|
|
||||||
pragma_index_list(m.name) AS il,
|
|
||||||
pragma_index_info(il.name) AS ii
|
|
||||||
WHERE m.type='table' AND il.origin <> 'pk'
|
|
||||||
ORDER BY ii.seqno, il.name
|
|
||||||
`;
|
|
||||||
|
|
||||||
class Analyser extends DatabaseAnalyser {
|
class Analyser extends DatabaseAnalyser {
|
||||||
constructor(dbhan, driver, version) {
|
constructor(dbhan, driver, version) {
|
||||||
@@ -26,8 +13,8 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _getFastSnapshot() {
|
async _getFastSnapshot() {
|
||||||
const objects = await this.driver.query(this.dbhan, "select * from sqlite_master where type='table' or type='view'");
|
const objects = await this.driver.query(this.dbhan, sql.objects);
|
||||||
const indexcols = await this.driver.query(this.dbhan, indexcolsQuery);
|
const indexcols = await this.driver.query(this.dbhan, sql.indexcols);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tables: objects.rows
|
tables: objects.rows
|
||||||
@@ -53,10 +40,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _runAnalysis() {
|
async _runAnalysis() {
|
||||||
const objects = await this.analyserQuery(
|
const objects = await this.analyserQuery(sql.objectsConditioned, ['tables', 'views']);
|
||||||
"select * from sqlite_master where (type='table' or type='view') and name =OBJECT_ID_CONDITION",
|
|
||||||
['tables', 'views']
|
|
||||||
);
|
|
||||||
const tables = objects.rows.filter((x) => x.type == 'table');
|
const tables = objects.rows.filter((x) => x.type == 'table');
|
||||||
const views = objects.rows.filter((x) => x.type == 'view');
|
const views = objects.rows.filter((x) => x.type == 'view');
|
||||||
// console.log('TABLES', tables);
|
// console.log('TABLES', tables);
|
||||||
@@ -79,7 +63,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
createSql: x.sql,
|
createSql: x.sql,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const indexcols = await this.driver.query(this.dbhan, indexcolsQuery);
|
const indexcols = await this.driver.query(this.dbhan, sql.indexcols);
|
||||||
|
|
||||||
for (const tableName of this.getRequestedObjectPureNames(
|
for (const tableName of this.getRequestedObjectPureNames(
|
||||||
'tables',
|
'tables',
|
||||||
|
|||||||
8
plugins/dbgate-plugin-sqlite/src/backend/sql/index.js
Normal file
8
plugins/dbgate-plugin-sqlite/src/backend/sql/index.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const objects = require('./objects.js');
|
||||||
|
const objectsConditioned = require('./objectsConditioned.js');
|
||||||
|
const indexcols = require('./indexcols.js');
|
||||||
|
module.exports = {
|
||||||
|
objects,
|
||||||
|
objectsConditioned,
|
||||||
|
indexcols,
|
||||||
|
};
|
||||||
14
plugins/dbgate-plugin-sqlite/src/backend/sql/indexcols.js
Normal file
14
plugins/dbgate-plugin-sqlite/src/backend/sql/indexcols.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module.exports = `
|
||||||
|
SELECT
|
||||||
|
m.name as tableName,
|
||||||
|
il.name as constraintName,
|
||||||
|
il."unique" as isUnique,
|
||||||
|
ii.name as columnName,
|
||||||
|
il.origin
|
||||||
|
FROM sqlite_schema AS m,
|
||||||
|
pragma_index_list(m.name) AS il,
|
||||||
|
pragma_index_info(il.name) AS ii
|
||||||
|
WHERE m.type='table' AND il.origin <> 'pk'
|
||||||
|
ORDER BY ii.seqno, il.name
|
||||||
|
|
||||||
|
`;
|
||||||
3
plugins/dbgate-plugin-sqlite/src/backend/sql/objects.js
Normal file
3
plugins/dbgate-plugin-sqlite/src/backend/sql/objects.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = `
|
||||||
|
select * from sqlite_master where (type='table' or type='view')
|
||||||
|
`;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = `
|
||||||
|
select * from sqlite_master where (type='table' or type='view') and name =OBJECT_ID_CONDITION
|
||||||
|
`;
|
||||||
Reference in New Issue
Block a user