Skip to content

Latest commit

 

History

History

deno-postgresql-neon

Northwind Traders (by subZero)

Running on Deno Deploy + PostgreSQL (Neon)

This is a demo of subZero library capabilities, leveraged in a NextJS app, to automatically expose a PostgREST compatible backend on top of the underlying database.

See the source code on GitHub.

Features / Advantages

  • Integrates in your codebase as a library (no need to deploy a separate service)
  • Runs in any context (Docker, AWS Lambda, Vercel, Netlify, Fly.io, Cloudflare Pages, Deno, Node, etc)
  • Implemented in Rust with JS/TypeScript bindings through WASM with no dependencies
  • Multiple databases supported:
    • SQLite (including Cloudflare D1)
    • PostgreSQL (including YugabyteDB, CockroachDB, TimescaleDB, etc)
    • ClickHouse
    • MySQL (PlanetScaleDB upcoming)
  • Supports advanced analytical queries (window functions, aggregates, etc)

Example details

  • Frontend is implemented in NextJS
  • Everything is deployed to Deno Deploy
  • Data is stored in a PostgreSQL database hosted on Neon
  • The backend is a Deno server that serves both the static frontend files and the the api. Most of the code deals with the configuration of the backend, and 99% of the functionality is within these lines:
    // generate the SQL query from request object
    const { query, parameters } = await subzero.fmtStatement(publicSchema, `${urlPrefix}/`, role, req, queryEnv)
    // .....
    // execute the query
    result = (await db.queryObject(query, parameters)).rows[0]
    // .....
    // send the response back to the client
    const body = result.body
    const status = Number(result.status) || 200
    return new Response(body, {status,headers})

Running locally

  • Clone the repo
    git clone https://github.com/subzerocloud/showcase.git
  • cd to the example directory
    cd showcase/deno-postgresql-neon
  • Install dependencies
    yarn install
  • Copy .env.local file
    cp .env.example .env
  • Run in dev mode
    yarn dev
  • Open the app in your browser
    open http://localhost:3000

Credits