0.0.22 • Published 12 days ago

oute-services-db-handler-sdk v0.0.22

Weekly downloads
-
License
-
Repository
-
Last release
12 days ago

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)
0.0.22

12 days ago

0.0.21

16 days ago

0.0.20

17 days ago

0.0.18

19 days ago

0.0.19

18 days ago

0.0.17

26 days ago

0.0.16

27 days ago

0.0.11

30 days ago

0.0.12

30 days ago

0.0.13

30 days ago

0.0.14

30 days ago

0.0.15

29 days ago

0.0.10

1 month ago

0.0.9

1 month ago

0.0.8

2 months ago

0.0.7

2 months ago

0.0.5

2 months ago

0.0.6

2 months ago

0.0.3

2 months ago

0.0.4

2 months ago

0.0.2

2 months ago

0.0.1

2 months ago