groomish
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Groomish

CI Coverage Status

1 minute example

import { Client } from "pg";
import groomish from "groomish";

async function demo() {
  // create a new pg client or pool since groomish does not manage pg connections
  const client = new Client({
    user: "postgres",
    database: "postgres",
    password: "postgres",
    host: "localhost",
  });

  await client.connect();

  // create a users table
  await client.query(`CREATE TABLE users (id SERIAL PRIMARY KEY, first_name VARCHAR, last_name VARCHAR)`);

  // Let's start working with groomish - use the client and create a users repository
  const users = groomish(client).repository("users");

  const john = await users.insert({ first_name: "John", last_name: "Doe" });
  const jane = await users.insert({ first_name: "Jane", last_name: "Doe" });

  // Select all users with first name "John"
  const johns = await users.select({ first_name: "John" });

  for (const aJohn of johns) {
    // Update the first name of each John to "Johnny"
    aJohn.first_name = "Johnny";
    const updatedUser = await users.update(aJohn);
  }

  // Select Jane by id and delete the user
  const toDelete = await users.get(jane.id);
  await users.delete(toDelete);
}

Readme

Keywords

none

Package Sidebar

Install

npm i groomish

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

66.8 kB

Total Files

38

Last publish

Collaborators

  • saintedlama