Skip to content

mortifia/PostgresDataSource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published