postgres-data-source

1.1.6 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i postgres-data-source

Weekly Downloads

7

Version

1.1.6

License

MIT

Unpacked Size

3.53 kB

Total Files

4

Last publish

Collaborators

  • mortifia