🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@brevity-builder/postgres

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brevity-builder/postgres

latest
Source
npmnpm
Version
0.0.26
Version published
Maintainers
0
Created
Source

Serverless Postgres.js for Neon

Getting Started

SQL-over-HTTP

import postgres from "@brevity-builder/postgres/http";

const sql = postgres(connectionString);

async function getUsersOver(age) {
  const users = await sql`
    select
      name,
      age
    from users
    where age > ${age}
  `;
  // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
  return users;
}

async function insertUser({ name, age }) {
  const users = await sql`
    insert into users
      (name, age)
    values
      (${name}, ${age})
    returning name, age
  `;
  // users = Result [{ name: "Murray", age: 68 }]
  return users;
}

async function transaction() {
  const showLatestN = 10;

  // Note: that neon's sql-over-http does not support interactive transactions
  // so we are passing an arary to begin (and not a callback).
  const [posts, tags] = await sql.begin([
    sql`SELECT * FROM posts ORDER BY posted_at DESC LIMIT ${showLatestN}`,
    sql`SELECT * FROM tags`,
  ]);
}

SQL-over-Websoket

import postgres from "@brevity-builder/postgres";

const sql = postgres(connectionString);

async function getUsersOver(age) {
  const users = await sql`
    select
      name,
      age
    from users
    where age > ${age}
  `;
  // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
  return users;
}

async function insertUser({ name, age }) {
  const users = await sql`
    insert into users
      (name, age)
    values
      (${name}, ${age})
    returning name, age
  `;
  // users = Result [{ name: "Murray", age: 68 }]
  return users;
}

async function transaction() {
  const [user, account] = await sql.begin(async (sql) => {
    const [user] = await sql`
    insert into users (
      name
    ) values (
      'Murray'
    )
    returning *
  `;

    const [account] = await sql`
    insert into accounts (
      user_id
    ) values (
      ${user.user_id}
    )
    returning *
  `;

    return [user, account];
  });
}

Docs

Please see the Postgres.js docs for more information about the api.

License

MIT

Keywords

bun

FAQs

Package last updated on 04 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts