mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 19:13:59 +00:00
code completion supports schemas
This commit is contained in:
1
packages/types/dbinfo.d.ts
vendored
1
packages/types/dbinfo.d.ts
vendored
@@ -114,4 +114,5 @@ export interface DatabaseInfoObjects {
|
|||||||
export interface DatabaseInfo extends DatabaseInfoObjects {
|
export interface DatabaseInfo extends DatabaseInfoObjects {
|
||||||
schemas: SchemaInfo[];
|
schemas: SchemaInfo[];
|
||||||
engine?: string;
|
engine?: string;
|
||||||
|
defaultSchema?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,53 @@ const COMMON_KEYWORDS = [
|
|||||||
'go',
|
'go',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function createTableLikeList(dbinfo, schemaCondition) {
|
||||||
|
return [
|
||||||
|
...(dbinfo.schemas?.map(x => ({
|
||||||
|
name: x.schemaName,
|
||||||
|
value: x.schemaName,
|
||||||
|
caption: x.schemaName,
|
||||||
|
meta: 'schema',
|
||||||
|
score: 1000,
|
||||||
|
})) || []),
|
||||||
|
...dbinfo.tables.filter(schemaCondition).map(x => ({
|
||||||
|
name: x.pureName,
|
||||||
|
value: x.pureName,
|
||||||
|
caption: x.pureName,
|
||||||
|
meta: 'table',
|
||||||
|
score: 1000,
|
||||||
|
})),
|
||||||
|
...dbinfo.views.filter(schemaCondition).map(x => ({
|
||||||
|
name: x.pureName,
|
||||||
|
value: x.pureName,
|
||||||
|
caption: x.pureName,
|
||||||
|
meta: 'view',
|
||||||
|
score: 1000,
|
||||||
|
})),
|
||||||
|
...dbinfo.matviews.filter(schemaCondition).map(x => ({
|
||||||
|
name: x.pureName,
|
||||||
|
value: x.pureName,
|
||||||
|
caption: x.pureName,
|
||||||
|
meta: 'matview',
|
||||||
|
score: 1000,
|
||||||
|
})),
|
||||||
|
...dbinfo.functions.filter(schemaCondition).map(x => ({
|
||||||
|
name: x.pureName,
|
||||||
|
value: x.pureName,
|
||||||
|
caption: x.pureName,
|
||||||
|
meta: 'function',
|
||||||
|
score: 1000,
|
||||||
|
})),
|
||||||
|
...dbinfo.procedures.filter(schemaCondition).map(x => ({
|
||||||
|
name: x.pureName,
|
||||||
|
value: x.pureName,
|
||||||
|
caption: x.pureName,
|
||||||
|
meta: 'procedure',
|
||||||
|
score: 1000,
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
export function mountCodeCompletion({ conid, database, editor, getText }) {
|
export function mountCodeCompletion({ conid, database, editor, getText }) {
|
||||||
setCompleters([]);
|
setCompleters([]);
|
||||||
addCompleter({
|
addCompleter({
|
||||||
@@ -90,6 +137,11 @@ export function mountCodeCompletion({ conid, database, editor, getText }) {
|
|||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const schema = (dbinfo.schemas || []).find(x => x.schemaName == colMatch[1]);
|
||||||
|
if (schema) {
|
||||||
|
list = createTableLikeList(dbinfo, x => x.schemaName == schema.schemaName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const onlyTables =
|
const onlyTables =
|
||||||
@@ -106,41 +158,8 @@ export function mountCodeCompletion({ conid, database, editor, getText }) {
|
|||||||
} else {
|
} else {
|
||||||
list = [
|
list = [
|
||||||
...(onlyTables ? [] : list),
|
...(onlyTables ? [] : list),
|
||||||
...dbinfo.tables.map(x => ({
|
...createTableLikeList(dbinfo, x => !dbinfo.defaultSchema || dbinfo.defaultSchema == x.schemaName),
|
||||||
name: x.pureName,
|
|
||||||
value: x.pureName,
|
|
||||||
caption: x.pureName,
|
|
||||||
meta: 'table',
|
|
||||||
score: 1000,
|
|
||||||
})),
|
|
||||||
...dbinfo.views.map(x => ({
|
|
||||||
name: x.pureName,
|
|
||||||
value: x.pureName,
|
|
||||||
caption: x.pureName,
|
|
||||||
meta: 'view',
|
|
||||||
score: 1000,
|
|
||||||
})),
|
|
||||||
...dbinfo.matviews.map(x => ({
|
|
||||||
name: x.pureName,
|
|
||||||
value: x.pureName,
|
|
||||||
caption: x.pureName,
|
|
||||||
meta: 'matview',
|
|
||||||
score: 1000,
|
|
||||||
})),
|
|
||||||
...dbinfo.functions.map(x => ({
|
|
||||||
name: x.pureName,
|
|
||||||
value: x.pureName,
|
|
||||||
caption: x.pureName,
|
|
||||||
meta: 'function',
|
|
||||||
score: 1000,
|
|
||||||
})),
|
|
||||||
...dbinfo.procedures.map(x => ({
|
|
||||||
name: x.pureName,
|
|
||||||
value: x.pureName,
|
|
||||||
caption: x.pureName,
|
|
||||||
meta: 'procedure',
|
|
||||||
score: 1000,
|
|
||||||
})),
|
|
||||||
...(onlyTables
|
...(onlyTables
|
||||||
? []
|
? []
|
||||||
: _.flatten(
|
: _.flatten(
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class MsSqlAnalyser extends DatabaseAnalyser {
|
|||||||
const schemaRows = await this.driver.query(this.pool, this.createQuery('getSchemas'));
|
const schemaRows = await this.driver.query(this.pool, this.createQuery('getSchemas'));
|
||||||
const indexesRows = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
const indexesRows = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||||
const indexcolsRows = await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
const indexcolsRows = await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
||||||
|
const defaultSchemaRows = await this.driver.query(this.pool, 'SELECT SCHEMA_NAME() as name');
|
||||||
|
|
||||||
const schemas = schemaRows.rows;
|
const schemas = schemaRows.rows;
|
||||||
|
|
||||||
@@ -150,6 +151,7 @@ class MsSqlAnalyser extends DatabaseAnalyser {
|
|||||||
procedures,
|
procedures,
|
||||||
functions,
|
functions,
|
||||||
schemas,
|
schemas,
|
||||||
|
defaultSchema: defaultSchemaRows.rows[0] ? defaultSchemaRows.rows[0].name : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user