https://github.com/thales-eduardo/crud-node-pg
crud with driver native node-postgres
https://github.com/thales-eduardo/crud-node-pg
jest node-pg nodejs
Last synced: 3 months ago
JSON representation
crud with driver native node-postgres
- Host: GitHub
- URL: https://github.com/thales-eduardo/crud-node-pg
- Owner: Thales-Eduardo
- License: mit
- Created: 2021-09-28T17:00:40.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T22:57:15.000Z (over 2 years ago)
- Last Synced: 2025-03-27T04:19:02.916Z (6 months ago)
- Topics: jest, node-pg, nodejs
- Language: TypeScript
- Homepage:
- Size: 344 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# [CRUD with driver native node-postgres](https://node-postgres.com/features/connecting)
Para iniciar a aplicação.
> docker-compose up -d
deletar os contêineres.
> docker-compose down
Essa api simples e apenas uma introdução, porem esta pronta para escalar caso queira.
# Query
```sql
CREATE TABLE IF NOT EXISTS USERS(
ID UUID PRIMARY KEY,
NAME VARCHAR (255) NOT NULL,
EMAIL VARCHAR (255) NOT NULL,
DATE TIMESTAMP DEFAULT NOW()
);
``````js
//Adicionando usuário.
await this.client.query(
'INSERT INTO USERS (ID, NAME, EMAIL) VALUES ($1, $2, $3)',
[id, name, email],
);//Buscar usuário por id.
await this.client.query('SELECT * FROM USERS WHERE ID = $1 LIMIT 1', [idUser]);//Buscar todos os usuários com paginação e limitando a quantidade no retorno.
await this.client.query('SELECT * FROM USERS LIMIT $1 OFFSET $2', [
limit,
offset,
]);//Atualizar dados do usuário especificado.
await this.client.query(
'UPDATE USERS SET NAME = $1, EMAIL = $2 WHERE ID = $3',
[name, email, id],
);//Deletar usuário específico.
await this.client.query('DELETE FROM USERS WHERE ID = $1', [id]);
```