https://github.com/schirrel/pg-connection
Simple PostgreSQL query builder for nodejs
https://github.com/schirrel/pg-connection
database hacktoberfest javascript nodejs orm pg-connection postgres postgresql potgresql-wrapper query-builder
Last synced: 8 months ago
JSON representation
Simple PostgreSQL query builder for nodejs
- Host: GitHub
- URL: https://github.com/schirrel/pg-connection
- Owner: schirrel
- License: mit
- Created: 2020-09-07T12:20:14.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T13:43:57.000Z (almost 2 years ago)
- Last Synced: 2025-10-06T07:41:39.607Z (8 months ago)
- Topics: database, hacktoberfest, javascript, nodejs, orm, pg-connection, postgres, postgresql, potgresql-wrapper, query-builder
- Language: JavaScript
- Homepage:
- Size: 156 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg-connection
Simple PotgreSQL wrapper for nodejs, to simplify its development.
WIP
## Install
``npm install @schirrel/pg-connection --save``
### Config
Uses `.env` to aquire credentials.
|Prop|Required| Default | Description |
| ------------ | ------------ | ------------ | ------------ |
|PG_USER| Required | | |
|PG_URL| Required | | |
|PG_DATABASE |Required | | |
|PG_PASSWORD |Required | | |
|PG_PORT | Optional |5432 | |
|PG_SSL | Optional |false | |
|PG_REJECT_UNHAUTHORIZED | Optional | | |
|PG_LOG | Optional |false | |
## Usage
Using in 3 Steps
1. .env
```
PG_USER=postgres
PG_URL=localhost
PG_DATABASE=postgres
PG_PASSWORD=postgres
PG_SCHEMA=mercado_alencar
PG_LOG=true
```
2. Model
```javascript
const Model = require('@schirrel/pg-connection/Model');
class User extends Model{
constructor(args = {}){
super("USER");
this.addColumn('email', 'EMAIL');
this.addColumn('name', 'NAME');
this.addColumn('password', 'PASSWORD');
this.addColumn('active', 'ACTIVE', true);
this.setValues(args);
}
}
module.exports = User;
```
3. Repository
```javascript
const Repository = require('@schirrel/pg-connection/Repository');
const User = require('../models/User');
class UserRepository extends Repository{
constructor(){
super(User);
}
}
module.exports = UserRepository;
```
And thats it.
## TL;DR
### Model
- Used as `extends Model` at your model class
- Call `super("TABLE_NAME")` with your table name
- To add a columns `this.addColumn('email', 'EMAIL');`, it accepts a 3rd parameter as the default value.
- To set values of your constructor use ``this.setValues(args);``
### Repository
- Used as `extends Repository` at your repo class
- Call `super(YourClass);` with your class reference
- it already have built in: get(id), create(model), update(model),delete(id), list(), search(options)