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

@openaddresses/batch-generic

v17.1.0

Published

JSON Schema/ORM Hybrid Helper for Drizzle-ORM

Downloads

828

Readme

Installation

npm add @openaddresses/batch-generic

Example Usage

The Generic Pool object is simply a wrapper around the slonik Pool class. All classes that exist on the Slonik Pool are mirrored onto the Generic Pool with the addition of several functions related to generation of internal JSON schemas.

import { Pool } from '@openaddresses/batch-generic';

async function start() {
    const pool = await Pool.connect('<postgres://<conn-str>');

    await pool.end();
}

Tables

Each table within the database should also receive it's own Class definition that extends Generic. Upon Pool connection, a JSON Schema is generated dynamically for each table in the database. This schema is then used to ensure that objects always dynamically mirror their in database representations. State of the class is thus managed almost entirely though the database definition and automatically mirrored to the class.

CREATE TABLE dog (
    id      BIGSERIAL PRIMARY KEY,
    breed   TEXT,
    size    TEXT NOT NULL,
    tags    JSONB
);
import Generic from '@openaddresses/batch-generic';

class MyClass extends Generic {
    static _table = '<postgres table name>';
}
import { Pool } from '@openaddresses/batch-generic';
import Dog from './lib/types/dog.js';

async function start() {
    const pool = await Pool.connect('<postgres://<conn-str>');

    const dog = await Dog.from(pool, 1);
    await dog.commit({
        breed: 'newfie',
        size: 'large',
        tags: ['tag']
    });
    await dog.delete();

    await pool.end();
}

Views

Views are also supported by extending the Generic class. Views are given access to read-only functions such as list() or from() but access to write functions such as commit() or generate() will produce an error.

CREATE TABLE view_dog
    AS
        SELECT
            *
        FROM
            dog
import Generic from '@openaddresses/batch-generic';

class MyClass extends Generic {
    static _view = '<postgres view name>';
}
import { Pool } from '@openaddresses/batch-generic';
import Dog from './lib/views/dog.js';

async function start() {
    const pool = await Pool.connect('<postgres://<conn-str>');

    const dog = await Dog.from(pool, 1);

    await pool.end();
}

Docs

API Docs can be found here