Skip to main content
For each table you want to have in your database you need to create a class and decorate it with the @Table decorator. Once you do this we call the class an . To define columns you need to create fields in the class and decorate them with the @Column decorator. Every needs to have a . Example:
/entities/users.ts
@Table("users")
export class Users {
  @PrimaryKey({ name: "id", type: "UUID" })
  id: string;

  @Column({ name: "username", type: "TEXT" })
  username: string;
}
You can read more about defining tables here

Client

Initialize a :
tygress-client.ts
import { Users } from "./entities";
import { PostgresClient } from "tygress";

export default new PostgresClient({
  databaseUrl: "postgres://username:password@host:5432/database",
  entities: [Users], // List all your tables here
  migrationFolders: [path.join(__dirname, "migrations")], // Needed for migrations to work
});

Database setup

Create your database yarn tygress db:create Generate your initial migration: yarn tygress migration:generate InitialMigration Run the migration: yarn tygress migration:run More about migrations ->

Usage

Elsewhere in your application you can run queries like this:
index.ts
import DB from 'tygress-client.ts'

const users = await DB.select(Users, { where: { username: 'batman' }})

Continue reading

Keep learning how to use Tygress