开源软件名称:pglink-lite
开源软件地址:https://gitee.com/JandenMa/pglink-lite
开源软件介绍:
pglink-liteA library for Postgresql to use ORM on NodeJS with GraphQL Via Janden Ma MIT LICENCE
This library is built for who uses GraphQL on NodeJS, you can use model to operate data. Version Change Logs- Build20190812 : Prepared version
- Build20190819 : Beta version
- Build20190826 : Fix bugs.
- Build20190829 : Add multi insert and update functions.
- Build20190917 :
MultiUpdateWithConditions bug fixes.- Supports all update functions in model to set the fields, which need to update to current time automatically, when updated.
- Build20190919 : Supports set global parameter
globalAutoSetTimeFields - Build20190924 :
- Changed
tableName and returnTableName in Transaction to alias and returnWithAlias - Added
Execute function in dataAccess to run a single query - Bug fixes
- Optimized something
- Build20191022 : Update README.
- Build20191111 : Vast changes.
- Build20191112 :
- Added the ability to force flatten results.
- Added the ability to return a single record.
- Build20191114 : Correct
pg package dependency. - Build20191120 :
- Added
connectionTimeoutMillis and idleTimeoutMillis parameters. - Added
DataAccess.Disconnect() function (beta).
- Build20191219 :
findByPk function supports multiple primary keys. - Build20200107 : Resolved async issue for
autoSetTimeFields - Build20200116 : Added
ssl - Build20200120 : Bug fixes.
- Build20200212 : Performance improvements.
- Build20200218 : Bug fixes.
- Build20200409 : Bug fixes and performance improvements.
- Build20200421 : Added customize transaction functions
- BeginTransaction
- CommitTransaction
- RollbackTransaction
- Build20200423 : Bug fixes
- Build20200427 : Optimized client connections in
Transaction - Build20200514 : Correct
sortBy option for build querying sql - Build20200824 : Bug fixes
- Build20200917 : Correct declaration and signature of parameters to
Transaction - Build20201010 : Upgrade
pg to support PostgreSQL 13 - Build20201027 : Try to resolve ssl connections failed issue
- Build20201029 : Add
preserveClient for leaving the client open for further operations in the transaction
Installationnpm yarn yarn add pglink-lite --save
Quick ExampleInstance (core/pglink.js) // core/pgsqlize.jsconst { PgLink } = require('pglink-lite')const pglink = new PgLink({ host: 'http://192.168.1.100', port: 5432, userName: 'root', password: '123456', database: 'test', connectionTimeoutMillis: 0, idleTimeoutMillis: 60000, globalAutoSetTimeFields: ['updatedAt'], ssl: true})module.exports.default = pglink Model (models/users.js) // models/users.jsconst pglink = require('../core/pglink')class UserModel extends pglink.Model { constructor() { super({ tableName: 'users', pkName: 'userId'}) }}module.exports.default = UserModel Schema (schemas/users.js) // schemas/users.js// you need to install something for gql first, we use apollo-server hereconst { gql } = require('apollo-server')const typeDefs = gql` type User { userId: ID! userName: String status: Boolean } input UserInsertInput { userName!: String } input UserEditInput { userId!: ID userName: String status: Boolean } type Query { getUserById(userId: ID!): User } type Mutation { insertUser(user: UserInsertInput): User editUser(user: UserEditInput): User }`module.exports.default = typeDefs Resolver (resolvers/users.js) // resolvers/users.jsconst UserModel = require('../models/users.js')const getUserById = async (_, args) => { const inst = new UserModel() const res = await inst.findByPk({ pk: args.userId }) return res}const insertUser = async (_, args) => { const inst = new UserModel() const res = await inst.insertOne({ params: args.user }) return res}const editUser = async (_, args) => { const inst = new UserModel() const res = await inst.updateByPk({ params: args.user }) return res}module.exports = { getUserById, insertUser, editUser}
Usage |
请发表评论