# @obi-tec/manager-postgres-database

> A simple library to help developers to manage connections and queries on postgres database

Latest version **3.0.2** (published 2023-02-06) · Apache License license · 0 weekly downloads

## Install

```sh
npm install @obi-tec/manager-postgres-database
pnpm add @obi-tec/manager-postgres-database
yarn add @obi-tec/manager-postgres-database
bun add @obi-tec/manager-postgres-database
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2023-02-06 |
| First published | 2022-05-04 |
| Weekly downloads | 0 |
| License | Apache License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 34.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Obi Tec |
| Maintainers | brunocamboim, jonatas.saraiva, dev-obi-tec |
| Keywords | node-js, postgres, database |

## Links

- npm: https://www.npmjs.com/package/@obi-tec/manager-postgres-database
- Repository: https://github.com/obi-tec/manager-postgres-database
- Homepage: https://github.com/obi-tec/manager-postgres-database#readme
- Issues: https://github.com/obi-tec/manager-postgres-database/issues
- npm.io page: https://npm.io/package/@obi-tec/manager-postgres-database

## Dependencies (6)

- [pg](https://npm.io/package/pg.md) ^8.7.3
- [knex](https://npm.io/package/knex.md) ^2.3.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [pg-format](https://npm.io/package/pg-format.md) ^1.0.4
- [@obi-tec/logger-console](https://npm.io/package/@obi-tec/logger-console.md) ^1.0.3
- [@obi-tec/express-response-models](https://npm.io/package/@obi-tec/express-response-models.md) ^1.0.3

## Recent versions

- 3.0.2 (latest) — 2023-02-06
- 3.0.1 — 2023-02-06
- 3.0.0 — 2023-02-06
- 2.2.4 — 2022-12-13
- 2.2.3 — 2022-12-13
- 2.1.3 — 2022-12-07
- 2.1.2 — 2022-12-07
- 2.1.0 — 2022-12-07
- 2.0.0 — 2022-12-06
- 1.0.4 — 2022-12-06
- 1.0.3 — 2022-05-05
- 1.0.2 — 2022-05-04
- 1.0.0 — 2022-05-04

## README

<p align="center">
  <a href="https://www.obitec.com.br/" target="_blank">
    <img src="https://media-exp1.licdn.com/dms/image/C4D0BAQEF_yY60ZuXMw/company-logo_100_100/0/1612555454150?e=1659571200&v=beta&t=J5EkLoozUME9lupU-MSfXHSWOqAfVnNrd320Xa9BPLM"/>
  </a>
</p>

<a name="description"></a>

# Manager Postgres Database
<p align="center">🚀 A simple library to help developers to manage connections and queries on postgres database</p>


<a name="content"></a>

###  🏁 Content
<!--ts-->
   * [Install](#install)
   * [How to use](#how-to-use)
   * [Status](#status)
<!--te-->

<br>
<a name="install"></a>

# Install
```bash
npm install @obi-tec/manager-postgres-database
```
See all tags clicking <a href="https://github.com/obi-tec/manager-postgres-database/tags"> here</a>.

<br>
<a name="how-to-use"></a>
# How to Use
In your file.js, import the dependency and extract the DatabaseConnection.

``` javascript
  const { DatabaseConnection } = require('@obi-tec/manager-postgres-database');
```

<br>

### Setup Connection
``` javascript
  DatabaseConnection.getInstance(
    'default',
    true,
    connectionSettings : {
      application_name : '',
      min              : 0,
      max              : 1,
      host             : 'localhost',
      port             : '5432',
      user             : 'postgres',
      password         : 'postgres',
      database         : 'postgres'
    },
    enableLogs   : false,
    camelizeKeys : true
  );
```
<br>

### Using DatabaseConnection
We are used to using two types of instances: read and write. By the way, when you will use this function, remember to inform which of the options you wanna use.

Example:
``` javascript
  const query  = 'SELECT * FROM user WHERE id = $1';
  const userId = 1;

  await DatabaseConnection.getInstance().connect();

  // passing true value if you want to use database read-only
  // await DatabaseConnection.getInstance(true).connect();

  const user = await DatabaseConnection.getInstance().queryFirstOrNull('getUserById', query, [userId]);
  await DatabaseConnection.getInstance().closeConnection();
```
<br>
<a name="status"></a>

# Status
<h4 align="center">
	🚧  Open for contribuitions...   🚧
</h4>

---
_Source: https://npm.io/package/@obi-tec/manager-postgres-database · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
