1.1.0 • Published 3 years ago

postgres-datasource v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

PostgresDataSource

for apollo-server, combine Postgres.js with logical of SQLDataSource

Getting Started

Installation

To install: npm i postgresdatasource

Usage

// postgresDB.js

const { PostgresDataSource } = require('postgresdatasource')

class PostgresDB extends SQLDataSource {
  getUsers() {
    return this.db`
      select *
      from "user".users
    `
  }
}

module.exports = PostgresDB;

And use it in your Apollo server configuration:

// index.js

const PostgresDB = require("./postgresDB");
const db = new PostgresDB(postgresUrl, postgresConfig);
// 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: () => ({ PostgresDB })
});
1.1.0

3 years ago