5.1.7 • Published 1 year ago

ts-pg-orm v5.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Overview

ts-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.

Start by viewing the Getting Started guide.

ts-pg-orm is available on npm.

Usage Overview

Define data formats, relations, and database connectivity to create type-safe auto-completing data stores:

import { createDataFormat, createTsPgOrm, ... } from 'ts-pg-orm'
const userDF = createDataFormat(...)
const ORM = createTsPgOrm([userDF, ...] as const).setRelations([...] as const)
const orm = await ORM.connect({ host: 'localhost', port: 5432, ... })
await orm.provisionStores()

Perform CRUD operations on data stores:

// Create
const userCreated = await orm.stores.user.create({ name: 'alice' })
// Get
const userFound = await orm.stores.user.get({
  fields: ['name'],
  filter: { field: 'id', op: Operator.EQUALS, val: 1 },
  relations: { // Recursively include related data
    userGroups: {
      query: { ... },
      relations: { ... }
    },
  },
})
// Update
const userUpdated = await orm.stores.user.update({
  query: {
    filter: { ... },
  },
  record: { name: 'bob' },
  return: true,
})
// Delete
const userDeleted = await orm.stores.user.delete({
  query: {
    filter: { ... },
  },
  return: true,
})

Create types to use throughout your application:

export type UserRecord = ToRecord<typeof USER_DFD>
// { id: number, name: string, ... }
export type CreateUserRecordOptions = CreateRecordOptions<typeof USER_DFD>
// { name: string, ... }
export type UserGroupRecord = ToRecord<typeof USER_GROUP_DFD>
// { id: number, name: string, ... }

Use type-enforced sql information to create bespoke SQL statements:

const userSql = ORM.dataFormats.user.sql
const customUserSql = `select ${userSql.columnNames.name} from ${userSql.tableName}`

Examples

Integration Tests

The 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.

Run npm run integration-tests to build and run these. The database connection configuration is at /.env-cmdrc.json.


If you found this package delightful, feel free to buy me a coffee

5.1.7

1 year ago

5.1.5

2 years ago

5.1.4

2 years ago

5.1.3

2 years ago

5.1.2

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.1.0-beta4

2 years ago

5.1.0-beta3

2 years ago

5.1.0-beta2

2 years ago

5.1.0-beta1

2 years ago

5.1.6

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.3.6

2 years ago

4.3.5

2 years ago

4.3.2

2 years ago

4.3.1

2 years ago

4.3.4

2 years ago

4.3.3

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

4.1.5

2 years ago

4.1.4

2 years ago

4.1.3

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

4.1.0

2 years ago

4.0.8

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.0.20

2 years ago

3.0.19

2 years ago

3.0.18

2 years ago

3.0.17

2 years ago

3.0.16

2 years ago

3.0.15

2 years ago

3.0.14

2 years ago

3.0.13

2 years ago

3.0.12

2 years ago

3.0.11

2 years ago

3.0.10

2 years ago

3.0.9

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago