npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ganjiang-datasource

v0.0.8

Published

ganjiang datasource crud and query sdk

Downloads

17

Readme

ganjiang-datasource

Build Status Codacy Badge Coverage Status Dependencies Known Vulnerabilities

npm version NPM downloads

issues

license

ganjiang datasource crud sdk.

:star: Features

  • support ganjiang datasource crud
  • support datasource query

:tada: Install

npm install ganjiang-datasource --save

:ghost: Test

npm test

:rocket: 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


import GanJiangDataSource from 'ganjiang-datasource'

const ganjiang = new GanJiangDataSource({
  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 gateway
}
const data = await ganjiang.create(DATASOURCE_INFO) // {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: 0
}
const data = await ganjiang.create(API_INFO) // {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.create(API_INFO) // {id: 'xxxxx'}

Get DataSource

const opt = { // optional
  attributes: 'database,token' // get datasource and token property only
}
const data = await ganjiang.read({
  name: 'datasource name',
  token: 'datasource token'
}, opt) // DATASOURCE_INFO

Update DataSource

const num = await ganjiang.update({
  name: 'datasource name',
  token: 'datasource token'
}, updateInfo) // updateInfo would be part of DATASOURCE_INFO

// num indicates the number updated successfully

Delete DataSource

const num = await ganjiang.delete({
  name: 'datasource name',
  token: 'datasource token'
})
// num indicates the number deleted successfully

Query DataSource with sql

const data = await ganjiang.query({
  name: 'datasource name',
  token: 'datasource token'
}, {
  sql: 'sql statement'
})
  • for dynamic values, using values to prevent from sql inject
const data = await ganjiang.query({
  name: 'datasource name',
  token: 'datasource token'
}, {
  sql: 'select * from app where id = ?',
  values: [1] // select * from app where id = 1
})

Request API (GateWay)

const data = await ganjiang.query({
  name: 'api name',
  token: 'api token'
}, {
  query: {}, // merge with default query
  body: {},// merge with default body
  headers: {},// merge with default headers
  opt: {}// override default options
})

:kissing_heart: WHILTE_LIST_AUTHORITY

you could ready more about white list in node-sql-parser module

License

MIT