Mantra how-to guide

Mantra data models types

Mantra uses RedEntities as a fast and simple Object Mapper for data models and it is based on a small number of types

12-Mar-2022
A  A  A 

Mantra relies on RedEntities as simple but flexible and fast Object Mapper.

This is one of the most important features of Mantra: to make independent components data model definitions from how data data is persisted.

In the time of writing this, MySql flavours, MariaDB, Aurora, Sqlite and PostgreSQL are supported. RedEntities, MongoDB, SqlServer / Sql Azure and Oracle will be added in the coming months.

The important thing to point out is that by configuration, the data model of a component is persisted in any of those data provider, transparently, and the component doesn't know anything about how Mantra stores its data.

Following one of the Mantra Development Principles (data models should be as simple as posible and each component only defines a small number of entities), the number of data types is also small but enough.

As an example, this is a simple query built using RedEntities in any Mantra component:

const usersCount = await db.users.S().C();

The goal of this Mantra subproject, is to write CRUD operations as fast as posible.

The types supported by RedEntities are these ones:

  • string: a variable string with 512 characters maximum.

  • key: a variable string with 24 characters maximum.

  • integer: the canonical integer type.

  • boolean: the canonical boolean type.

  • datetime: the canonical datetime type.

  • json: a variable string that RedEntities uses to store JSON objects.

  • float: the canonical float type.

  • longtext: for long texts.

According to the data provider indicated, RedEntities translates those base types to the final data provider types.