Documentation for the Codomat

Entities

Jump to Section

If you want two words to describe the function of a backend, they would be non but managing data. Your post to a social network, the task you create in a TODO list, or the money transfer you make on your banking app: these are all pieces of data the backend receives, stores, and deliver according to specific rules.

Entities is the Codomat’s way to think about data in an organized way.

Independent

An entity is a group of related pieces of data which represent a logical, independent object. These pieces of data are called fields. In a social network, an entity could represent a post. The fields which define the post could be:

  • post text
  • post author
  • post creation time
  • if this post is a reply, to which other post is it?

In Codomat specification language, you would define this entity as follows:


Entity posts has the fields
    author text timestamp replyto
.

Another entity could represent the act of a user following another user. The fields which define a follow could be:

  • follower
  • followed
  • time of follow

In Codomat specification language:


Entity follows has the fields
    follower followed timestamp
.

We call these entities independent because their existence doesn’t depend on other entities. This is opposed to the kind of entities we see in the next section.

Derived

Often you need your backend to to load your entities in a sophisticated way. For example, you want to load all users that the current users is following. To support this case, the Codomat has a concept of derived entities. Derived entities are data which are dependent on other entities.

In Codomat specification language:

Derived myfollows
    uses follows
    is record.followed for record in follows if record.follower = current_user.id
.

Note here that myfollows definition specifies which independent entity it uses, follows and how myfollows is derived from follows. The definition language is similar to set builder notation or Python list comprehension


Learning to define entities allows you to tell your backend how to store and load the data necessary to make your app work.