Introduction
Rex is schema-first and type-safe ORM.
Declarative Schema
rex.hcl
client "db" {
// define generators for client
// support multiple generators
generator "rex-client-go" {}
generator "rex-client-java" {}
// define database connection
// support multiple environments through `REX_ENV`
adapter = "postgresql"
config "development" {
database = "blog_development"
user = "postgres"
password = "postgres"
}
config "production" {
url = env("DATABASE_URL")
}
// define database schema with models
model "Post" {
column "title" {
type = string
}
column "content" {
type = text
}
}
}
Database Migration
Client Generation
rex g client db
Client API
- Go
- Java
- TypeScript
client := db.NewClient()
post, err := client.CreatePost(client.ChangePost().setTitle("post title"))
posts, err := client.QueryPost().All()