Skip to main content

Create your first entity

In this section, we'll define the Book entity using Rell. This will allow us to manage book data and perform queries on it.

Define the Book entity

In Rell, entities are similar to tables in relational databases. We'll create a Book entity to manage the book information.

Entity diagram

Add the entity definition

Open the src/main/entities.rell file and insert the following Rell code:

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

Code explanation

  • entity keyword: Defines a new entity, similar to creating a table in a database.
  • Attributes:
    • key isbn: text: Sets isbn as the unique identifier for each book. The key keyword ensures uniqueness and text specifies that the isbn is stored as text.
    • title: text and author: text: Define the title and author attributes, both stored as text.

With the Book entity defined, you can now use it in your decentralized application.