0.0.34 • Published 3 years ago

@schirrel/pg-connection v0.0.34

Weekly downloads
235
License
ISC
Repository
github
Last release
3 years ago

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
  1. Model
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;
  1. Repository
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)
0.0.34

3 years ago

0.0.33

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.30

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago