This commit is contained in:
Jan Prochazka 2024-11-15 16:28:00 +01:00
parent f23575c405
commit c5d23410f4
5 changed files with 52 additions and 3 deletions

View File

@ -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 * 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/) * **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) * 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 ## Supported databases
* MySQL * MySQL

View File

@ -5,6 +5,16 @@ const { getLogger, getLimitedQuery } = require('dbgate-tools');
const logger = getLogger('execQuery'); 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({ async function executeQuery({
connection = undefined, connection = undefined,
systemConnection = undefined, systemConnection = undefined,

View File

@ -3,6 +3,15 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
const connectUtility = require('../utility/connectUtility'); const connectUtility = require('../utility/connectUtility');
const logger = getLogger('tableReader'); 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<readerType>} - reader object
*/
async function tableReader({ connection, systemConnection, pureName, schemaName }) { async function tableReader({ connection, systemConnection, pureName, schemaName }) {
const driver = requireEngineDriver(connection); const driver = requireEngineDriver(connection);
const dbhan = systemConnection || (await connectUtility(driver, connection, 'read')); const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));

View File

@ -3,6 +3,20 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
const connectUtility = require('../utility/connectUtility'); const connectUtility = require('../utility/connectUtility');
const logger = getLogger('tableWriter'); 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<writerType>} - writer object
*/
async function tableWriter({ connection, schemaName, pureName, driver, systemConnection, ...options }) { async function tableWriter({ connection, schemaName, pureName, driver, systemConnection, ...options }) {
logger.info(`Writing table ${fullNameToString({ schemaName, pureName })}`); logger.info(`Writing table ${fullNameToString({ schemaName, pureName })}`);

View File

@ -1,12 +1,27 @@
/** /**
* Reader (input) object for copyStream function * Reader (input) object for copyStream function
* @typedef {Object} readerType * @typedef {Object} readerType
* *
*/ */
/** /**
* Wrtiter (output) object for copyStream function * Writer (output) object for copyStream function
* @typedef {Object} writerType * @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
*/