ganjiang-datasource
ganjiang datasource crud sdk.
⭐️ Features
- support ganjiang datasource crud
- support datasource query
🎉 Install
npm install ganjiang-datasource --save
👻 Test
npm test
🚀 Usage
if you want print out the debug info, please set DEBUG='ds'
in process environment by command: export DEBUG='ds'
Init ganjiang datasource manager
const ganjiang = host: 'xx.xx.xx.xx' // datasource host required token: 'access_token' // datasource api access token optional
Create DataSource
Create MySQL DataSource
const DATASOURCE_INFO = name: 'test' host: 'host' port: 3306 database: 'database' user: 'user' password: 'password' db_cfg: // 可选 limit: 100 // 限制select最多返回100, 默认是1000 dialect: 'mysql' // optional token: '0123456789' // read, update, delete or query datasource need this token whiteList: 'select::null::(.*)' // db white list type: 1 // 0 for api, 1 for mysql 2 for psql 3 for api gatewayconst data = await ganjiang // {id: 'xxxxx'}
Create Api DataSource
const API_INFO = name: 'api_test' url: 'http://xxx.xxx.xx.xx/url/path' method: 'get' token: '0123456789' headers: {} // default headers query: {} // default query body: {} // default body type: 0const data = await ganjiang // {id: 'xxxxx'}
Create Api GateWay DataSource
const API_INFO = name: 'api_test' url: 'http://xxx.xxx.xx.xx/url/path' method: 'get' token: '0123456789' headers: {} // default headers query: {} // default query body: {} // default body type: 3 appKey: 'your app key' appSecret: 'your app secret'const data = await ganjiang // {id: 'xxxxx'}
Get DataSource
const opt = // optional attributes: 'database,token' // get datasource and token property onlyconst data = await ganjiang // DATASOURCE_INFO
Update DataSource
const num = await ganjiang // updateInfo would be part of DATASOURCE_INFO // num indicates the number updated successfully
Delete DataSource
const num = await ganjiang// num indicates the number deleted successfully
Query DataSource with sql
const data = await ganjiang
- for dynamic values, using
values
to prevent from sql inject
const data = await ganjiang
Request API (GateWay)
const data = await ganjiang
😘 WHILTE_LIST_AUTHORITY
you could ready more about white list in node-sql-parser module