{"id":43678,"library":"postgres-schema-builder","title":"postgres-schema-builder","description":"A TypeScript library for building PostgreSQL schemas and writing typesafe queries. Version 1.3.0, last updated in 2020 (no recent releases). It uses a declarative schema definition with TableSchema, automatic TypeScript type inference from column types, and a Table API for CRUD operations. Key differentiator: strong TypeScript type safety for schema and queries, including compile-time checks for nullable columns and foreign keys. Not actively maintained; no query builder for joins or aggregations. Alternative: kysely or drizzle-orm.","status":"maintenance","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/yss14/postgres-schema-builder","tags":["javascript","postgres","postgresql","typescript","typesafe","schema","query","builder","database"],"install":[{"cmd":"npm install postgres-schema-builder","lang":"bash","label":"npm"},{"cmd":"yarn add postgres-schema-builder","lang":"bash","label":"yarn"},{"cmd":"pnpm add postgres-schema-builder","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS require works but ESM is preferred; the package ships both CJS and ESM.","wrong":"const TableSchema = require('postgres-schema-builder').TableSchema","symbol":"TableSchema","correct":"import { TableSchema } from 'postgres-schema-builder'"},{"note":"Use for defining column types like ColumnType.Integer, ColumnType.Varchar.","symbol":"ColumnType","correct":"import { ColumnType } from 'postgres-schema-builder'"},{"note":"Do not import from subpaths; the package has no deep imports.","wrong":"import { Table } from 'postgres-schema-builder/src'","symbol":"Table","correct":"import { Table } from 'postgres-schema-builder'"},{"note":"Used for raw SQL fragments if needed.","symbol":"SQL","correct":"import { SQL } from 'postgres-schema-builder'"},{"note":"For default values like NativeFunction.Now.","symbol":"NativeFunction","correct":"import { NativeFunction } from 'postgres-schema-builder'"},{"note":"For defining JSON columns with a TypeScript interface.","symbol":"JSONType","correct":"import { JSONType } from 'postgres-schema-builder'"},{"note":"Use for foreign key constraints.","symbol":"ForeignKeyUpdateDeleteRule","correct":"import { ForeignKeyUpdateDeleteRule } from 'postgres-schema-builder'"}],"quickstart":{"code":"import { TableSchema, ColumnType, NativeFunction, JSONType, ForeignKeyUpdateDeleteRule, TableRecord, Table, SQL } from 'postgres-schema-builder'\n\n// Define schema\nexport namespace DatabaseV1 {\n    const baseSchema = {\n        date_added: { type: ColumnType.TimestampTZ, nullable: false, defaultValue: { func: NativeFunction.Now } },\n        date_removed: { type: ColumnType.TimestampTZ, nullable: true },\n    }\n    export const users = TableSchema({\n        ...baseSchema,\n        user_id: { type: ColumnType.Integer, primaryKey: true, unique: true },\n        name: { type: ColumnType.Varchar, nullable: false },\n        settings: { type: JSONType<{ key: string }>(), nullable: false },\n    })\n}\n\n// Create interfaces and table objects\nexport const Tables = DatabaseV1\nexport interface IUserDBResult extends TableRecord<typeof Tables.users> { }\nexport const UsersTable = Table(Tables, 'users')\n\n// Typesafe queries\nconst createSQL = UsersTable.create() // returns string\nconst dropSQL = UsersTable.drop()\nconst insertSQL = UsersTable.insert(['name'])(['Fresh Herrmann'])\nconst selectSQL = UsersTable.select('*', ['user_id'])([42])\nconsole.log(createSQL, dropSQL, insertSQL, selectSQL)","lang":"typescript","description":"Defines a PostgreSQL schema using TableSchema, creates table objects, and demonstrates typesafe insert/select queries."},"warnings":[{"fix":"For joins, construct raw SQL using the SQL helper or consider alternatives like kysely.","message":"The package does not support JOIN queries out of the box; you must use raw SQL or another query builder.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No direct replacement; use namespaces to organize schema versions.","message":"The package uses deprecated TableSchema syntax without explicit versioning; schema versions are defined by namespaces.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Check types manually; consider using ColumnType.Integer (0/1) as a workaround.","message":"Boolean columns are not supported; use ColumnType.Boolean but it may not be correctly typed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate if you need ongoing support; consider migrating to maintained alternatives.","message":"The package is not actively maintained; last release 2020, no recent bug fixes.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.3.0':17 '2020':21 'activ':69 'aggreg':77 'altern':78 'api':43 'automat':33 'build':9 'builder':4,73,91 'check':61 'column':38,64 'compil':59 'compile-tim':58 'crud':45 'databas':92 'declar':28 'definit':30 'differenti':48 'drizzl':82 'drizzle-orm':81 'foreign':66 'includ':57 'infer':36 'javascript':84 'join':75 'key':47,67 'kyse':79 'last':18 'librari':7 'maintain':70 'nullabl':63 'oper':46 'orm':83 'postgr':2,85 'postgres-schema-build':1 'postgresql':10,86 'queri':15,56,72,90 'recent':23 'releas':24 'safeti':52 'schema':3,11,29,54,89 'strong':49 'tabl':42 'tableschema':32 'time':60 'type':35,39,51 'typesaf':14,88 'typescript':6,34,50,87 'updat':19 'use':26 'version':16 'write':13","created_at":"2026-06-05T17:00:57.043292+00:00","updated_at":"2026-06-05T17:00:57.043292+00:00","problems":[{"fix":"Run 'npm install postgres-schema-builder' and ensure import is 'postgres-schema-builder', not a subpath.","cause":"Missing installation or import path incorrect.","error":"Cannot find module 'postgres-schema-builder'"},{"fix":"Use TypeScript >=3.5. Ensure tsconfig.json includes 'esModuleInterop'. The package ships .d.ts files.","cause":"Incorrect TypeScript version or missing type declarations.","error":"Property 'insert' does not exist on type 'Table<...>'"},{"fix":"Check your schema: set nullable: true for columns that allow null values.","cause":"Trying to insert null into a non-nullable column.","error":"Type 'null' is not assignable to type 'string | number'"},{"fix":"Use 'typeof Tables.users' instead of 'DatabaseV1.users' for the interface.","cause":"TableRecord expects a type, not a namespace.","error":"Cannot use namespace 'DatabaseV1' as a type"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/yss14/","github":"https://github.com/yss14/postgres-schema-builder","docs":null,"changelog":null,"pypi":null,"npm":"postgres-schema-builder","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}