oute-services-db-handler-sdk

0.0.22 • Public • Published

This module expose helper functions

  • Initialization
  var db_handler_instance = require("oute-services-db-handler-sdk")
  • Get client for db connection
  state = {}
  db_config = {db_type: "postgres", configs: []}
  options = {logging: false} //additional options
  await db_handler_instance.getClient(state, db_config, options)
  • Execute query on the client
  query = "select 1 as const"
  db_options = {logging: false}
  query_options = {type: "SELECT"}
  db_config = {db_type: "postgres", configs: []}
  state = {}
  client_info = await db_handler_instance.getClient(state, db_config)
  await db_handler_instance.executeQuery(client_info?.db_client, client_info?.db_type, query, options)
  • Disconnect client
  state = {}
  db_config = {db_type: "postgres", configs: []}
  client_info = await db_handler_instance.getClient(state, db_config)
  await db_handler_instance.disconnect(client_info?.db_client, client_info?.db_type)
  • Sync db models
  state = {}
  db_config = {db_type: "postgres", configs: []}
  options = {logging: false} //additional options
  model_dir = __dirname + "/models" //schema name will auto append to this path
  sync_info = await db_handler_instance.syncDbModel(state, db_config, options, model_dir)

CRUD operation

  • Generate model
  state = {}
  db_config = {}
  table_config = {}
  fields_config = []
  options = {type: "SELECT", logging: false}
  client_info = await db_handler_instance.getClient(state, db_config, options)
  model_info = await db_handler_instance.getModel(client_info?.db_client, client_info?.orm_type, client_info?.orm_misc?.data_types, client_info?.db_type, table_config, fields_config)
  • Insert single row
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  data = {user_id: 1}
  await db_handler_instance.crud.insert(orm_type, instance, data)
  • Find all
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  options = { where: {"user_id": "s1"}}
  await db_handler_instance.crud.find(orm_type, instance, options)
  • update all
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  update = {first_name: "update"}
  options = { where: {"user_id": "s1"}}
  await db_handler_instance.crud.updateMany(orm_type, instance, update, options)
  • delete all
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  options = { where: {"user_id": "s1"}}
  await db_handler_instance.crud.deleteMany(orm_type, instance, options)

Readme

Keywords

none

Package Sidebar

Install

npm i oute-services-db-handler-sdk

Weekly Downloads

47

Version

0.0.22

License

none

Unpacked Size

76.7 kB

Total Files

30

Last publish

Collaborators

  • oute