diff --git a/README.md b/README.md index 9a6868c9..405996c6 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ DbGate is licensed under GPL-3.0 license and is free to use for any purpose. * Try it online - [demo.dbgate.org](https://demo.dbgate.org) - online demo application * **Download** application for Windows, Linux or Mac from [dbgate.org](https://dbgate.org/download/) * Run web version as [NPM package](https://www.npmjs.com/package/dbgate-serve) or as [docker image](https://hub.docker.com/r/dbgate/dbgate) +* Use nodeJs [scripting interface](https://dbgate.org/docs/scripting.html) ([API documentation](https://dbgate.org/docs/apidoc.html)) ## Supported databases * MySQL diff --git a/packages/api/src/shell/executeQuery.js b/packages/api/src/shell/executeQuery.js index 4d7bd6c8..8dcdc1ab 100644 --- a/packages/api/src/shell/executeQuery.js +++ b/packages/api/src/shell/executeQuery.js @@ -5,6 +5,16 @@ const { getLogger, getLimitedQuery } = require('dbgate-tools'); const logger = getLogger('execQuery'); +/** + * Executes SQL query + * @param {object} options + * @param {connectionType} options.connection - connection object + * @param {object} options.systemConnection - system connection (result of driver.connect) + * @param {object} options.driver - driver object + * @param {string} options.sql - SQL query + * @param {string} options.sqlFile - SQL file + * @param {boolean} options.logScriptItems - whether to log script items instead of whole script + */ async function executeQuery({ connection = undefined, systemConnection = undefined, diff --git a/packages/api/src/shell/tableReader.js b/packages/api/src/shell/tableReader.js index cc5f88a9..373b9ce1 100644 --- a/packages/api/src/shell/tableReader.js +++ b/packages/api/src/shell/tableReader.js @@ -3,6 +3,15 @@ const requireEngineDriver = require('../utility/requireEngineDriver'); const connectUtility = require('../utility/connectUtility'); const logger = getLogger('tableReader'); +/** + * Creates reader object for {@link copyStream} function. This reader object reads data from table or view. + * @param {object} options + * @param {connectionType} options.connection - connection object + * @param {object} options.systemConnection - system connection (result of driver.connect) + * @param {string} options.pureName - table name + * @param {string} options.schemaName - schema name + * @returns {Promise} - reader object + */ async function tableReader({ connection, systemConnection, pureName, schemaName }) { const driver = requireEngineDriver(connection); const dbhan = systemConnection || (await connectUtility(driver, connection, 'read')); diff --git a/packages/api/src/shell/tableWriter.js b/packages/api/src/shell/tableWriter.js index b22bf088..90a5b579 100644 --- a/packages/api/src/shell/tableWriter.js +++ b/packages/api/src/shell/tableWriter.js @@ -3,6 +3,20 @@ const requireEngineDriver = require('../utility/requireEngineDriver'); const connectUtility = require('../utility/connectUtility'); const logger = getLogger('tableWriter'); +/** + * Creates writer object for {@link copyStream} function. This writer object writes data to table. Table could be created if not exists. + * @param {object} options + * @param {connectionType} options.connection - connection object + * @param {object} options.systemConnection - system connection (result of driver.connect) + * @param {string} options.pureName - table name + * @param {string} options.schemaName - schema name + * @param {object} options.driver - driver object + * @param {boolean} options.dropIfExists - drop table if exists + * @param {boolean} options.truncate - truncate table before insert + * @param {boolean} options.createIfNotExists - create table if not exists + * @param {boolean} options.commitAfterInsert - commit transaction after insert + * @returns {Promise} - writer object + */ async function tableWriter({ connection, schemaName, pureName, driver, systemConnection, ...options }) { logger.info(`Writing table ${fullNameToString({ schemaName, pureName })}`); diff --git a/packages/api/src/shell/types.js b/packages/api/src/shell/types.js index a3352c3f..ebdc4574 100644 --- a/packages/api/src/shell/types.js +++ b/packages/api/src/shell/types.js @@ -1,12 +1,27 @@ /** * Reader (input) object for copyStream function * @typedef {Object} readerType - * + * */ /** - * Wrtiter (output) object for copyStream function + * Writer (output) object for copyStream function * @typedef {Object} writerType - * + * */ +/** + * Typ uživatelské role. + * @typedef {('mysql@dbgate-plugin-mysql' | 'mariadb@dbgate-plugin-mysql' | 'postgres@dbgate-plugin-postgres' + * |'sqlite@dbgate-plugin-sqlite' | 'oracle@dbgate-plugin-oracle' | 'cockroach@dbgate-plugin-postgres' | 'redshift@dbgate-plugin-postgres')} engineType + */ + +/** + * @typedef {Object} connectionType + * @property {engineType} engine + * @property {string} server + * @property {string} user + * @property {string} password + * @property {string} database + * @property {string} port + */