# oute-services-db-handler-sdk

> - Initialization

Latest version **0.0.53** (published 2024-06-27) · 0 weekly downloads

## Install

```sh
npm install oute-services-db-handler-sdk
pnpm add oute-services-db-handler-sdk
yarn add oute-services-db-handler-sdk
bun add oute-services-db-handler-sdk
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.53 |
| Published | 2024-06-27 |
| First published | 2024-03-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 57.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |

## Links

- npm: https://www.npmjs.com/package/oute-services-db-handler-sdk
- npm.io page: https://npm.io/package/oute-services-db-handler-sdk

## Dependencies (7)

- [pg](https://npm.io/package/pg.md) ^8.11.3
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [pg-hstore](https://npm.io/package/pg-hstore.md) ^2.3.4
- [sequelize](https://npm.io/package/sequelize.md) ^6.37.0
- [sequelize-auto](https://npm.io/package/sequelize-auto.md) ^0.8.8
- [oute-services-utility-sdk](https://npm.io/package/oute-services-utility-sdk.md) ^0.0.64
- [oute-services-flow-utility-sdk](https://npm.io/package/oute-services-flow-utility-sdk.md) ^0.0.86

## Recent versions

- 0.0.53 (latest) — 2024-06-27
- 0.0.52 — 2024-06-26
- 0.0.51 — 2024-06-25
- 0.0.50 — 2024-06-24
- 0.0.49 — 2024-06-24
- 0.0.48 — 2024-06-21
- 0.0.47 — 2024-06-21
- 0.0.46 — 2024-06-19
- 0.0.45 — 2024-06-18
- 0.0.44 — 2024-06-17
- 0.0.43 — 2024-06-17
- 0.0.42 — 2024-06-17
- 0.0.41 — 2024-06-14
- 0.0.40 — 2024-06-10
- 0.0.39 — 2024-06-10
- … 38 more at https://npm.io/package/oute-services-db-handler-sdk/versions

## README

# This module expose helper functions

- Initialization

```js
  var db_handler_instance = require("oute-services-db-handler-sdk")
```

- Get client for db connection

```js
  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

```js
  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

```js
  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

```js
  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

```js
  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

```js
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  data = {user_id: 1}
  await db_handler_instance.crud.insert(orm_type, instance, data)
```

- Find all

```js
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  options = { where: {"user_id": "s1"}}
  await db_handler_instance.crud.find(orm_type, instance, options)
```

- update all

```js
  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

```js
  orm_type = "sequelize"
  instance = sequelize.define('users', {})
  options = { where: {"user_id": "s1"}}
  await db_handler_instance.crud.deleteMany(orm_type, instance, options)
```

---
_Source: https://npm.io/package/oute-services-db-handler-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
