ganjiang-ds

1.0.3 • Public • Published

Ganjiang-DS SDK

Debug the output

set the process.env.DEBUG by export DEBUG = true, ganjiang will log out debug info

create ganjiang-ds client

  const GanJiangDS = require('ganjiang-ds')
  const ganjiangDS = new GanJiangDS({
    host: '127.0.0.1', // ganjiang ds host
    token: 'xxxxx', // access token
  })

create datasource

  const dsInfo = {
    host: 'host',
    port: 3306,
    user: 'user',
    password: 'password',
    database: 'db',
    type: 1, // 1 for mysql, 2 for pg
  }
  const ds = await ganjiangDS.createDataSource(dsInfo)
  console.log(ds) // show the following data
  {
    extra: dsInfo
    type: dsInfo.type
    id: ds.id // the following method need this id
  }

get datasource by id

  const ds = await ganjiangDS.getDataSource(id)
  console.log(ds) // same as create ds result

update datasource by id

  const newDsInfo = {
    database: 'new-db',
  }
  const updateResult = await ganjiangDS.updateDataSource(id, newDsInfo)
  console.log(updateResult) // true for update successfully, false for failed

delete datasource by id

  const deleteResult = await ganjiangDS.deleteDataSource(id)
  console.log(deleteResult) // true for delete successfully, false for failed

query datasource with sql

  const sqlVal = 'SELECT * FROM table1 limit 0, 10'
  const type = 'origin'
  const options = {
    filter: [{
      name: 'sql',
      value: sqlVal,
    }],
    transforms: [{
      name: 'type',
      value: type
    }]
  }
  const data = await ganjiangDS.requestData(id, options)
  console.log(data) // data is query sql on ds

format sql

const SQL_TPL = 'SELECT columnA FROM tableA WHERE columnB in (?) and columnC = ?'
const val = [['d', 'c', 'f'], 'g']
const SQL = ganjiangDS.formatSQL(SQL_TPL, val)
console.log(SQL) // SELECT columnA FROM tableA WHERE columnB in ('d', 'c', 'f') and columnC = 'g'

Package Sidebar

Install

npm i ganjiang-ds

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

6.73 kB

Total Files

4

Last publish

Collaborators

  • taozhi.tz