-
Notifications
You must be signed in to change notification settings - Fork 1
data models
Data Models are the fundamental building blocks in data-primals-engine, defining how your application's data is structured and stored. They are essentially blueprints for collections of documents, enabling you to organize and manage diverse types of information.
In data-primals-engine, a data model is a flexible definition of a data entity. Unlike traditional relational databases, models here are schema-less (thanks to MongoDB), meaning you can evolve their structure over time without rigid migration processes. Each model corresponds to a collection in your MongoDB database.
Models can be defined either through the platform's user interface or by providing a JSON schema. Key attributes of a model include:
| Attribute | Type | Description |
|---|---|---|
name |
string, unique | The technical name of the model (e.g., product, user). Used for API and internal references. |
description |
string | A brief explanation of the model's purpose. |
icon |
string | An icon (e.g., a Font Awesome class) to visually represent the model in the UI. |
tags |
array of strings | Keywords for categorization and filtering. |
locked |
boolean | If true, the model is a system model and cannot be modified or deleted via the UI. |
fields |
array of objects | The core of the model, defining its attributes. |
Each field within a model defines a specific piece of data. Fields have various properties to control their type, behavior, and validation:
| Attribute | Type | Description - |
|---|---|---|
name |
string | The name of the attribute (e.g., title, price, email). Unique within the model. - |
type |
string | The data type of the field. Common types include string, number, boolean, datetime, email, richtext, enum, file, relation, array, and code. - |
required |
boolean | If true, the field must have a value. - |
unique |
boolean | If true, the field's value must be unique across all documents in the collection. - |
default |
any | A default value for the field. - |
min, max |
number | Minimum and maximum values for number fields, or length for string fields. - |
relation |
string | The name of the model this field relates to (for relation type). - |
multiple |
boolean | If true, the field can relate to multiple documents in the target model (for relation type). - |
hint |
string | A helpful description displayed in the UI. - |
The product model, defined in defaultModels.js, illustrates how fields are used to structure information about a product:
product: {
name: 'product',
"icon": "FaShoppingBag",
"description": "",
"tags": ["ecommerce", "products"],
fields: [
{ name: 'name', type: 'string_t', required: true },
{ name: 'image', type: 'array', itemsType: 'file', mimeTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'] },
{ name: 'description', type: 'richtext_t' },
{ name: 'price', type: 'number', required: true },
{ name: 'currency', type: 'relation', relation: 'currency', required: true },
{ name: 'billingFrequency', type: 'enum', items: ['none', 'monthly', 'yearly'] },
{ name: 'slug', type: 'string', required: true, unique: true },
{ name: 'brand', type: 'relation', relation: 'brand' },
{ name: 'category', type: 'relation', relation: 'taxonomy' },
{ name: 'seoTitle', type: 'string_t' },
{ name: 'seoDescription', type: 'string_t' }
]
},This example shows how a product can have a translatable name, multiple image files, a price with a currency relation, and be linked to a brand and category (taxonomy).
By defining models and their fields, you create a robust and adaptable data foundation for your data-primals-engine application.