0.1.6 • Published 4 years ago

pg-connector v0.1.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Pg-Connector

Lib Version:0.1.6

Document Version:0.1.6

Author:Janden Ma

LICENCE: MIT

Version Change Logs

  • v0.1.1 (Build20200514): Correct orderBy option for build querying sql
  • v0.1.2 (Build20200514): Update README
  • v0.1.3 (Build20200515): Optimizations
  • v0.1.4 (Build20200621): Resolve bugs
  • v0.1.5 (Build20200729): Bug fixes
  • v0.1.6 (Build20201010): Support PostgreSQL 13

What is Pg-Connector?

Pg-Connector is an ORM library for Postgresql on NodeJS.

Installation

  • npm

    npm i pg-connector --save
  • yarn

    yarn add pg-connector --save

Quick Example

  • Instance (core/pg.js)

    // core/pg.js
    import PgConnector from 'pg-connector'
    
    const Pg = new PgConnector({
      host: 'http://192.168.1.100',
      port: 5432,
      userName: 'root',
      password: '123456',
      database: 'test',
      connectionTimeoutMillis: 0,
      idleTimeoutMillis: 60000,
      ssl: true
    })
    
    export default Pg
  • Model (models/users.js)

    import Pg from '../core/pg.js';
    
    class User extends Pg.Model{
      constructor(){
        super({
          autoCreate: true,
          tables: [
            {
              index: 0,
              name: 'users',
              primaryKeys: ['id'],
              fields: [
                {
                  name: 'id',
                  type: Pg.DataType.SERIAL
                },
                {
                  name: 'name',
                  type: Pg.DataType.VARCHAR,
                  length: 100
                },
                {
                  name: 'age',
                  type: Pg.DataType.INT
                }
              ]
            }
          ]
        });
        
        // other functions you want to override or customize
      }
    }
    
    User.init();  // will create data table if not exists
    
    export default User

Usage

  • import

    import PgConnector from 'pg-connector'
    // or
    const PgConnector = require('pg-connector')
  • Instantiate

    const Pg = new PgConnector({
      host: 'http://192.168.1.100',
      port: 5432,
      userName: 'root',
      password: '123456',
      database: 'test',
      connectionTimeoutMillis: 0,
      idleTimeoutMillis: 60000,
      ssl: true
    })
    KeyTypeIntroductionDefault value
    hoststringPostgresql server host"localhost"
    portnumberPostgresql server port5432
    userNamestringPostgresql server user name"postgres"
    passwordstringPostgresql server password""(empty)
    databasestringPostgresql database name"postgres"
    connectionMaxnumberPostgresql database max connection10
    connectionTimeoutMillisnumberNumber of milliseconds to wait before timing out when connecting a new client, by default this is 0 which means no timeout0
    idleTimeoutMillisnumberNumber of milliseconds a client must sit idle in the pool and not be checked out, before it is disconnected from the backend and discarded, default is 10000 (10 seconds) - set to 0 to disable auto-disconnection of idle clients10000
    sslbooleanTo connect to pg using sslfalse

Modules

  • LibDataAccess
  • LibSQLBuilder
  • LibModel
  • DataTypes
    • SERIAL: Serial Id
    • BIT
    • BOOLEAN
    • CHAR
    • VARCHAR
    • INT: Int 4
    • BIGINT: Int 8
    • SMALLINT: Int 2
    • FLOAT
    • DOUBLE
    • DECIMAL
    • NUMERIC
    • JSON
    • DATE
    • TIMESTAMP
    • TIMESTAMPTZ: Timestamp with time zone
    • TEXT
0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.1.0-rc2

4 years ago

0.1.0-rc1

4 years ago

0.1.0-beta6

4 years ago

0.1.0-beta5

4 years ago

0.1.0-beta4

4 years ago

0.1.0-beta3

4 years ago

0.1.0-beta2

4 years ago

0.1.0-beta1

4 years ago

0.1.0-alpha4

4 years ago

0.1.0-alpha5

4 years ago

0.1.0-alpha3

4 years ago

0.1.0-alpha2

4 years ago

0.1.0-alpha

4 years ago

1.0.0

4 years ago