Chromia
Start Building

05 / 26Part 1: Define your first entityBeginner

Create your first entity

Here you define a Book entity in Rell so your dapp can store book records and query them.

Define the Book entity

A Rell entity plays the same role as a table in a relational database. The Book entity holds the data for each book.

Add the entity definition

Add this code to src/main/entities.rell:

src/main/entities.rell
entity book {  key isbn: text;  title: text;  author: text;}

Code explanation

  • entity keyword: Declares a new entity, much like creating a database table.
  • Attributes:
    • key isbn: text: Makes isbn the unique identifier for every book. Marking it with key enforces uniqueness and adds an index on the field, so queries on it run faster. The text type stores the value as a string.
    • title: text and author: text: Hold the book's title and author, each as text.

The Book entity is now ready to use in your decentralized application.

Written for this site from Chromia’s public course. Code samples are the course’s own.