Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saintedlama/groomish
Micro ORM for Postgres
https://github.com/saintedlama/groomish
Last synced: about 15 hours ago
JSON representation
Micro ORM for Postgres
- Host: GitHub
- URL: https://github.com/saintedlama/groomish
- Owner: saintedlama
- Created: 2022-06-04T12:05:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-19T13:24:07.000Z (over 2 years ago)
- Last Synced: 2024-10-12T12:25:44.616Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 271 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Groomish
[![CI](https://github.com/saintedlama/groomish/actions/workflows/ci.yml/badge.svg)](https://github.com/saintedlama/groomish/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/saintedlama/groomish/badge.svg?branch=main)](https://coveralls.io/github/saintedlama/groomish?branch=main)[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/saintedlama/groomish/tree/main)
## 1 minute example
Install latest `pg` peer dependency and `groomish`
```shell
npm i pg groomish
```Start working with a repository
```js
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);
}
```