set the process.env.DEBUG
by export DEBUG = true
, ganjiang will log out debug info
const GanJiangDS = require('ganjiang-ds')
const ganjiangDS = new GanJiangDS({
host: '127.0.0.1', // ganjiang ds host
token: 'xxxxx', // access token
})
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
}
const ds = await ganjiangDS.getDataSource(id)
console.log(ds) // same as create ds result
const newDsInfo = {
database: 'new-db',
}
const updateResult = await ganjiangDS.updateDataSource(id, newDsInfo)
console.log(updateResult) // true for update successfully, false for failed
const deleteResult = await ganjiangDS.deleteDataSource(id)
console.log(deleteResult) // true for delete successfully, false for failed
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
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'