• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

pg-connector: An ORM library for Postgresql on NodeJS

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

pg-connector

开源软件地址:

https://gitee.com/JandenMa/pg-connector

开源软件介绍:

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.jsimport 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 existsexport default User

Usage

  • import

    import PgConnector from 'pg-connector'// orconst 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人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap