npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pg-apify

v1.0.4

Published

<img alt="GitHub License" src="https://img.shields.io/github/license/edsol/pg-apify"> <img alt="NPM Version" src="https://img.shields.io/npm/v/pg-apify"> <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/pg-apify"> <img alt="NPM Down

Downloads

11

Readme

Postgres GraphQL TypeScript

pg-apify

Effortlessly transform your PostgreSQL database into a powerful REST and GraphQL API server with zero coding required

Features

  • Zero Coding Required: Instantly generate REST and GraphQL endpoints from your PostgreSQL schema without writing a single line of code.
  • Rapid Setup: Get your API server up and running in just a few seconds.
  • Seamless Integration: Easily integrates with your existing PostgreSQL databases, enabling quick and efficient data access.
  • Customizable Middleware: Enhance your API with custom logic using flexible middleware support.
  • Beautiful API: Automatically generate comprehensive API documentation using Scalar to ensure clear and detailed endpoint information.

Install and requirements

install pg-apify:

bun install pg-apify
// or
npm install pg-apify

local installation of postgREST is also required, follow official wiki to install correctly.

Usage

Zero-coding

creates and use .env file or passes the configuration directly via parameters and run server

import { pgApifyServer, postgraphileOptions, postgrestOptions } from "pg-apify";
import { dev as options } from "./postgraphileOptions";

const postgraphileServerOptions: postgraphileOptions = {
  enabled: true,
  databaseUrl: process.env.DATABASE_URL,
  schema: process.env.PGSCHEMA,
  options: options,
};

const postgrestServerOptions: postgrestOptions = {
  enabled: true,
  enableDocs: true,
};
pgApifyServer(postgraphileServerOptions, postgrestServerOptions);

a GraphQL server, RestAPI and OpenAPI documentation will be launched

🚀 GraphQL server available at http://localhost:5000/graphql
🚀 GraphiQL available at http://localhost:5000/graphiql
📖 API docs is running at http://localhost:3000/docs
🔥 API is running at http://localhost:3000

note

The postgraphileOptions file contains the Postgraphile options (docs), see the example file, copy it or create your own custom configuration file.

Request middleware

intercepts all GET requests

requestHandler.registerHandler("get", async (params, context, info) => {
  // your code

  return {
    success: false,
    status: 404,
    message: "Custom error message",
  };
});

or specific endpoint

requestHandler.registerRouteHandler(
  "get",
  "foo",
  async (params, context, info) => {
    // your code

    return {
      success: false,
      status: 404,
      message: "Custom error message",
    };
  }
);

Under the hood

PostGraphile

pg-apify leverages PostGraphile, a powerful tool that automatically generates a GraphQL API from your PostgreSQL schema. PostGraphile inspects your database schema, including tables, columns, relationships, and constraints, and creates a fully-functional GraphQL API. This allows you to take advantage of GraphQL's flexibility and efficiency in querying and mutating data.

PostgREST

In addition to GraphQL, pg-apify also utilizes PostgREST, a standalone web server that turns your PostgreSQL database directly into a RESTful API. PostgREST reads the database schema and creates RESTful endpoints that correspond to your tables and views, enabling CRUD operations with ease.

Scalar

Using scalar to generate interactive API documentation from OpenAPI/Swagger documents.

Do you want to support my work? Buy me an espresso coffee (I'm Italian)