rent
Learn by example

1. Define the schema in RSL

Rent projects have one schema source: rent/schema.rsl. Start the project and generate an initial client explicitly:

rent init User Post Comment
rent generate

Then describe fields and relationships in the central schema. This is the complete source from which the Rust client is generated:

datasource db {
  provider = "sqlite"
}

model User {
  id    BigInt @id
  name  String
  posts Post[]

  @@map("users")
}

model Post {
  id        BigInt @id
  title     String
  author_id BigInt
  author    User   @relation(fields: [author_id], references: [id])
  comments  Comment[]

  @@map("posts")
}

model Comment {
  id      BigInt @id
  body    String
  post_id BigInt
  post    Post   @relation(fields: [post_id], references: [id], onDelete: Cascade)

  @@map("comments")
}

Rent infers the target and cardinality from the RSL field type and connects User.posts to Post.author. Running rent generate validates references and replaces the generated Rust client atomically. Later chapters add versioning, many-to-many joins, tenant fields, rich values, and advanced indexes only when those concepts are taught.

This chapter owns crates/rent/examples/tutorial_00_schema/schema.rsl. Run cargo run -p rent --example tutorial_00_schema; it parses and semantically validates that focused file. The same schema program runs under nextest.