{"id":22544106,"url":"https://github.com/samhuk/ts-pg-orm","last_synced_at":"2025-04-09T23:50:40.777Z","repository":{"id":41198049,"uuid":"507312094","full_name":"samhuk/ts-pg-orm","owner":"samhuk","description":"Delightful Typescript PostgreSQL ORM","archived":false,"fork":false,"pushed_at":"2023-01-25T21:16:58.000Z","size":425,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T23:50:35.761Z","etag":null,"topics":["orm","postgresql","sql","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samhuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing/development.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"samhuk"}},"created_at":"2022-06-25T13:00:13.000Z","updated_at":"2022-12-06T19:59:35.000Z","dependencies_parsed_at":"2023-01-19T23:34:20.171Z","dependency_job_id":null,"html_url":"https://github.com/samhuk/ts-pg-orm","commit_stats":null,"previous_names":["samhuk/ts-entity-framework"],"tags_count":8,"template":false,"template_full_name":"samhuk/ts-npm-package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhuk%2Fts-pg-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhuk%2Fts-pg-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhuk%2Fts-pg-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samhuk%2Fts-pg-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samhuk","download_url":"https://codeload.github.com/samhuk/ts-pg-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131454,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["orm","postgresql","sql","typescript"],"created_at":"2024-12-07T14:06:11.157Z","updated_at":"2025-04-09T23:50:40.753Z","avatar_url":"https://github.com/samhuk.png","language":"TypeScript","funding_links":["https://github.com/sponsors/samhuk","https://www.buymeacoffee.com/samhuk"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./images/wordmark-dark.png\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"./images/wordmark-light.png\"\u003e\n    \u003cimg alt=\"ts-pg-orm\" src=\"./images/wordmark-light.svg\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cem\u003eDelightful Typescript PostgreSQL ORM\u003c/em\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/samhuk/ts-pg-orm/actions/workflows/ci.yaml/badge.svg\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/samhuk/ts-pg-orm/actions/workflows/ci.yaml/badge.svg\" alt=\"ci status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/samhuk/ts-pg-orm\" \u003e \n    \u003cimg src=\"https://codecov.io/gh/samhuk/ts-pg-orm/branch/master/graph/badge.svg?token=N0WKDLEDNM\"/\u003e \n  \u003c/a\u003e\n  \u003ca href=\"https://img.shields.io/badge/License-MIT-green.svg\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-green.svg\" alt=\"license\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://app.fossa.com/projects/custom%2B33608%2Fgithub.com%2Fsamhuk%2Fts-pg-orm?ref=badge_shield\" alt=\"FOSSA Status\"\u003e\n    \u003cimg src=\"https://app.fossa.com/api/projects/custom%2B33608%2Fgithub.com%2Fsamhuk%2Fts-pg-orm.svg?type=shield\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://badge.fury.io/js/ts-pg-orm.svg\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badge.fury.io/js/ts-pg-orm.svg\" alt=\"npm version\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Overview\n\nts-pg-orm provides PostgreSQL persistence for your Typescript application. Write expressive, zero guess-work, fully type-enforced typescript queries to perform CRUD operations on PostgreSQL databases.\n\nStart by viewing the [Getting Started](https://github.com/samhuk/ts-pg-orm/wiki/Getting-Started) guide.\n\n[ts-pg-orm is available on npm](https://www.npmjs.com/package/ts-pg-orm).\n\n## Usage Overview\n\nDefine data formats, relations, and database connectivity to create type-safe auto-completing data stores:\n\n```typescript\nimport { createDataFormat, createTsPgOrm, ... } from 'ts-pg-orm'\nconst userDF = createDataFormat(...)\nconst ORM = createTsPgOrm([userDF, ...] as const).setRelations([...] as const)\nconst orm = await ORM.connect({ host: 'localhost', port: 5432, ... })\nawait orm.provisionStores()\n```\n\nPerform CRUD operations on data stores:\n\n```typescript\n// Create\nconst userCreated = await orm.stores.user.create({ name: 'alice' })\n// Get\nconst userFound = await orm.stores.user.get({\n  fields: ['name'],\n  filter: { field: 'id', op: Operator.EQUALS, val: 1 },\n  relations: { // Recursively include related data\n    userGroups: {\n      query: { ... },\n      relations: { ... }\n    },\n  },\n})\n// Update\nconst userUpdated = await orm.stores.user.update({\n  query: {\n    filter: { ... },\n  },\n  record: { name: 'bob' },\n  return: true,\n})\n// Delete\nconst userDeleted = await orm.stores.user.delete({\n  query: {\n    filter: { ... },\n  },\n  return: true,\n})\n```\n\nCreate types to use throughout your application:\n\n```typescript\nexport type UserRecord = ToRecord\u003ctypeof USER_DFD\u003e\n// { id: number, name: string, ... }\nexport type CreateUserRecordOptions = CreateRecordOptions\u003ctypeof USER_DFD\u003e\n// { name: string, ... }\nexport type UserGroupRecord = ToRecord\u003ctypeof USER_GROUP_DFD\u003e\n// { id: number, name: string, ... }\n```\n\nUse type-enforced sql information to create bespoke SQL statements:\n\n```typescript\nconst userSql = ORM.dataFormats.user.sql\nconst customUserSql = `select ${userSql.columnNames.name} from ${userSql.tableName}`\n```\n\n## Examples\n\n### Integration Tests\n\nThe integration test suite connects to a real PostgreSQL server at (by default) postgres@localhost:5432 and performs various ts-pg-orm queries with a set of example data formats and relations.\n\nRun `npm run integration-tests` to build and run these. The database connection configuration is at `/.env-cmdrc.json`.\n\n---\n\nIf you found this package delightful, feel free to [buy me a coffee](https://www.buymeacoffee.com/samhuk) ✨\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamhuk%2Fts-pg-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamhuk%2Fts-pg-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamhuk%2Fts-pg-orm/lists"}