mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 16:13:58 +00:00
feat: add listSchemas to duckdb
This commit is contained in:
@@ -231,6 +231,7 @@ function mapConstraintRowToForeignKeyInfo(duckDbConstraintData) {
|
|||||||
constraintType: 'foreignKey',
|
constraintType: 'foreignKey',
|
||||||
columns: columns,
|
columns: columns,
|
||||||
refTableName: duckDbConstraintData.referenced_table,
|
refTableName: duckDbConstraintData.referenced_table,
|
||||||
|
refSchemaName: duckDbConstraintData.schema_name,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (duckDbConstraintData.constraint_name != null) {
|
if (duckDbConstraintData.constraint_name != null) {
|
||||||
@@ -363,6 +364,31 @@ function mapIndexRowToIndexInfo(duckDbIndexRow) {
|
|||||||
return /** @type {import("dbgate-types").IndexInfo} */ (indexInfo);
|
return /** @type {import("dbgate-types").IndexInfo} */ (indexInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} DuckDbSchemaRow
|
||||||
|
* @property {string} oid
|
||||||
|
* @property {string} database_name
|
||||||
|
* @property {string} database_oid
|
||||||
|
* @property {string} schema_name
|
||||||
|
* @property {string | null} comment
|
||||||
|
* @property {{ [key: string]: string } | null} tags
|
||||||
|
* @property {boolean} internal
|
||||||
|
* @property {string | null} sql
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {DuckDbSchemaRow} duckDbSchemaRow
|
||||||
|
* @returns {import("dbgate-types").SchemaInfo}
|
||||||
|
*/
|
||||||
|
function mapSchemaRowToSchemaInfo(duckDbSchemaRow) {
|
||||||
|
const schemaInfo = {
|
||||||
|
schemaName: duckDbSchemaRow.schema_name,
|
||||||
|
objectId: duckDbSchemaRow.oid,
|
||||||
|
};
|
||||||
|
|
||||||
|
return /** @type {import("dbgate-types").SchemaInfo} */ (schemaInfo);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mapRawTableToTableInfo,
|
mapRawTableToTableInfo,
|
||||||
mapRawColumnToColumnInfo,
|
mapRawColumnToColumnInfo,
|
||||||
@@ -371,4 +397,5 @@ module.exports = {
|
|||||||
mapConstraintRowToUniqueInfo,
|
mapConstraintRowToUniqueInfo,
|
||||||
mapViewRowToViewInfo,
|
mapViewRowToViewInfo,
|
||||||
mapIndexRowToIndexInfo,
|
mapIndexRowToIndexInfo,
|
||||||
|
mapSchemaRowToSchemaInfo,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ const Analyser = require('./Analyser');
|
|||||||
const driverBase = require('../frontend/driver');
|
const driverBase = require('../frontend/driver');
|
||||||
const { getLogger, extractErrorLogData, createBulkInsertStreamBase } = require('dbgate-tools');
|
const { getLogger, extractErrorLogData, createBulkInsertStreamBase } = require('dbgate-tools');
|
||||||
const { getColumnsInfo, normalizeRow } = require('./helpers');
|
const { getColumnsInfo, normalizeRow } = require('./helpers');
|
||||||
|
const sql = require('./sql');
|
||||||
|
const { mapSchemaRowToSchemaInfo } = require('./Analyser.helpers');
|
||||||
|
|
||||||
const logger = getLogger('sqliteDriver');
|
const logger = getLogger('sqliteDriver');
|
||||||
|
|
||||||
@@ -111,11 +113,13 @@ const driver = {
|
|||||||
options.done();
|
options.done();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async script(dbhan, sql) {
|
async script(dbhan, sql, { useTransaction } = { useTransaction: false }) {
|
||||||
|
if (useTransaction) {
|
||||||
const dmp1 = driver.createDumper();
|
const dmp1 = driver.createDumper();
|
||||||
dmp1.beginTransaction();
|
dmp1.beginTransaction();
|
||||||
|
|
||||||
await dbhan.client.run(dmp1.s);
|
await dbhan.client.run(dmp1.s);
|
||||||
|
}
|
||||||
|
|
||||||
const statements = await dbhan.client.extractStatements(sql);
|
const statements = await dbhan.client.extractStatements(sql);
|
||||||
const count = statements.count;
|
const count = statements.count;
|
||||||
@@ -125,10 +129,12 @@ const driver = {
|
|||||||
await stmt.run();
|
await stmt.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (useTransaction) {
|
||||||
const dmp2 = driver.createDumper();
|
const dmp2 = driver.createDumper();
|
||||||
dmp2.commitTransaction();
|
dmp2.commitTransaction();
|
||||||
|
|
||||||
await dbhan.client.run(dmp2.s);
|
await dbhan.client.run(dmp2.s);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async readQuery(dbhan, sql, structure) {
|
async readQuery(dbhan, sql, structure) {
|
||||||
@@ -168,13 +174,20 @@ const driver = {
|
|||||||
},
|
},
|
||||||
async getVersion(dbhan) {
|
async getVersion(dbhan) {
|
||||||
const { rows } = await this.query(dbhan, 'SELECT version() AS version;');
|
const { rows } = await this.query(dbhan, 'SELECT version() AS version;');
|
||||||
const { version } = rows[0];
|
const { version } = rows?.[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version,
|
version,
|
||||||
versionText: `DuchDB ${version}`,
|
versionText: `DuchDB ${version}`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async listSchemas(dbhan) {
|
||||||
|
const schemasResult = await this.query(dbhan, sql.schemas);
|
||||||
|
const schemas = schemasResult.rows?.map(mapSchemaRowToSchemaInfo);
|
||||||
|
|
||||||
|
return schemas ?? null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = driver;
|
module.exports = driver;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const primaryKeys = require('./primaryKeys.js');
|
|||||||
const indexes = require('./indexes.js');
|
const indexes = require('./indexes.js');
|
||||||
const uniques = require('./uniques.js');
|
const uniques = require('./uniques.js');
|
||||||
const views = require('./views.js');
|
const views = require('./views.js');
|
||||||
|
const schemas = require('./schemas.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
tables,
|
tables,
|
||||||
@@ -14,4 +15,5 @@ module.exports = {
|
|||||||
indexes,
|
indexes,
|
||||||
uniques,
|
uniques,
|
||||||
views,
|
views,
|
||||||
|
schemas,
|
||||||
};
|
};
|
||||||
|
|||||||
1
plugins/dbgate-plugin-duckdb/src/backend/sql/schemas.js
Normal file
1
plugins/dbgate-plugin-duckdb/src/backend/sql/schemas.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = `SELECT * FROM duckdb_schemas() WHERE internal = false`;
|
||||||
Reference in New Issue
Block a user