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

0.0.14 • Public • Published

shitgen

Stands for "shit PostgreSQL type generator". I simply couldn't miss the opportunity on the naming (even if a bit crass), so here we are. The primary motivation of this project is to

  • enable rapid prototyping on simple web applications
  • allow you to use Prisma-esque method without learning yet another intermediary schema langauge.

shitgen is a toy library that generates both types and models based on basic DDL. It's basically a bad yet (barely) "functional enough" ORM with support for basic CRUD operations. You will likely have to write raw SQL slapped with type casting for more advanced applications or basic optimizations.

Currently uses postgres under the hood.

NOTE: I did not look at how other libraries achieve type generation, so the approach may differ substantially here. All I can say is this TypeScript is cursed and shockingly still works.

Installation

NOTE: not stable, do not install unless you want bugs

pnpm add shitgen -D

Usage

# empties the current database and all tables, because migrations are for the weak
shitgen nuke --force

# Generate types & utility methods from a schema file
shitgen generate ./schema.sql -o "./dist/database.ts"
-- schema.sql
CREATE TABLE IF NOT EXISTS user_ (
  id INTEGER PRIMARY KEY,
  username TEXT NOT NULL UNIQUE,
  password TEXT NOT NULL,
  name TEXT DEFAULT 'unnamed',
  avatar_id INTEGER REFERENCES avatar_(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS avatar_ (
  id INTEGER PRIMARY KEY,
  src TEXT NOT NULL,
  alt TEXT
);

The full list of command documentation can be found with shitgen --help.

@todo adapters that implement a shared interface for different kinds of postgres clients?
@todo I need testing really badly
@todo one to many relationships (auto create?)

Readme

Keywords

none

Package Sidebar

Install

npm i shitgen

Weekly Downloads

758

Version

0.0.14

License

ISC

Unpacked Size

42 kB

Total Files

36

Last publish

Collaborators

  • natmfat