Skip to content

mortifia/node-postgres-datasource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg-Data-Source

for apollo-server, combine node-postgres with logical of SQLDataSource

Getting Started

Installation

To install: npm i pg-datasource

Usage

// pgDB.js

const { PgDataSource } = require('pg-datasource')

class PgDB extends PgDataSource {
  async helloWorld() {
    return await this.db.query('SELECT NOW() as now')
  }
}

module.exports = PgDB;

And use it in your Apollo server configuration:

// index.js

const PgDB = require("./PgDB");
const db = new PgDB(pgConnection);
// you can pass a Postgres.js instance or other db instance instead of a configuration object

const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache,
  context,
  dataSources: () => ({ db })
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published