1.1.6 • Published 3 years ago

postgres-data-source v1.1.6

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

Postgres-Data-Source

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

Getting Started

Installation

To install: npm i postgres-data-source

Usage

// postgresDB.js

const { PostgresDataSource } = require('postgres-data-source')

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 })
});