You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

dbgate-api

Package Overview
Dependencies
Maintainers
1
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dbgate-api

Allows run DbGate data-manipulation scripts.

6.3.3
latest
Source
npm
Version published
Weekly downloads
176
50.43%
Maintainers
1
Weekly downloads
 
Created
Source

dbgate-api

Allows run DbGate data-manipulation scripts.

Installation

yarn add dbgate-api

Usage

This example exports table Customer info CSV file.

const dbgateApi = require('dbgate-api');
const dbgatePluginMysql = require("dbgate-plugin-mysql");
const dbgatePluginCsv = require("dbgate-plugin-csv");

dbgateApi.registerPlugins(dbgatePluginMysql);

async function run() {
  const reader = await dbgateApi.tableReader({
    connection: { server: 'localhost', engine: 'mysql@dbgate-plugin-mysql', user: 'root', password: 'xxxx', database: 'Chinook' },
    pureName: 'Customer',
  });
  const writer = await dbgatePluginCsv.shellApi.writer({ fileName: 'Customer.csv' });
  await dbgateApi.copyStream(reader, writer);

  console.log('Finished job script');
}
dbgateApi.runScript(run);

Silly example, runs without any dependencies. Copy fakeObjectReader to consoleObjectWriter .


const dbgateApi = require('dbgate-api');
async function run() {
  const reader = await dbgateApi.fakeObjectReader();
  const writer = await dbgateApi.consoleObjectWriter();
  await dbgateApi.copyStream(reader, writer);
  console.log('Finished job script');
}
dbgateApi.runScript(run);

dbgateApi functions

dbgateApi.copyStream

Copies data from reader into writer. Reader and writer should be created from functions listed below.

  await dbgateApi.copyStream(reader, writer);

dbgateApi.tableReader

Reads table or view.

  const reader = await dbgateApi.tableReader({
    connection: { server: 'localhost', engine: 'postgres@dbgate-plugin-postgres', user: 'root', password: 'xxxx', database: 'DB_NAME' },
    schemaName: 'public',
    pureName: 'Customer',
  });

dbgateApi.queryReader

Executes query and reads its result.

  const reader = await dbgateApi.tableReader({
    connection: { server: 'localhost', engine: 'mysql@dbgate-plugin-mysql', user: 'root', password: 'xxxx', database: 'DB_NAME' },
    sql: 'SELECT * FROM Album',
  });

dbgateApi.tableWriter

Imports data into table. Options are optional, default values are false.

  • dropIfExists - if table already exists, it is dropped before import
  • truncate - delete table content before import
  • createIfNotExists - create table, if not exists
  const reader = await dbgateApi.tableWriter({
    connection: { server: 'localhost', engine: 'mysql@dbgate-plugin-mysql', user: 'root', password: 'xxxx', database: 'DB_NAME' },
    pureName: 'Customer',
    options: {
      dropIfExists: false,
      truncate: false,
      createIfNotExists: false,
    }
  });

dbgateApi.jsonLinesReader

Reads JSON lines data file. On first line could be structure. Every line contains one row as JSON serialized object.

  const reader = await dbgateApi.jsonLinesReader({
    fileName: 'test.jsonl',
    encoding: 'utf-8',
    header: true,
    limitRows: null
  });

dbgateApi.jsonLinesWriter

Writes JSON lines data file. On first line could be structure. Every line contains one row as JSON serialized object.

  const reader = await dbgateApi.jsonLinesWriter({
    fileName: 'test.jsonl',
    encoding: 'utf-8',
    header: true
  });

Keywords

sql

FAQs

Package last updated on 09 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts