Skip to main content

Data Model in Marblism

Marblism uses ZenStack, a superset of Prisma, for defining and managing the data model of your application. This powerful combination allows for efficient database operations, type safety, and enhanced features like access control.

ZenStack Overview

ZenStack extends Prisma's schema definition language with additional features, particularly focusing on access control and validation. It allows you to define your data model and access rules in a single, cohesive file.

Model Definition

In Marblism, your data models are defined in the /models/models.zmodel file. This file uses the ZenStack schema language, which is an extension of Prisma's schema definition language.

Here's a basic example of how a model might look:

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]

@@allow('create,read', true)
@@allow('update,delete', auth() == this)
}

model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int

@@allow('read', published == true)
@@allow('create,update,delete', auth() == author)
}

In this example, we define two models: User and Post. Each model has fields with types and attributes. The @@allow directives are ZenStack-specific and define access control rules.

Key Features

  1. Type Safety: ZenStack inherits Prisma's strong typing, ensuring type safety across your application.

  2. Access Control: Use @@allow and @@deny directives to define fine-grained access control rules directly in your schema.

  3. Validation: Define custom validation rules using ZenStack's enhanced schema language.

  4. Relations: Define relationships between models easily, just like in Prisma.

  5. Auto-generated CRUD Operations: Marblism automatically generates CRUD endpoints based on your ZenStack schema.

Using Your Models

Once defined, these models are used throughout your Marblism application. The ORM (Object-Relational Mapping) layer will handle database operations, and the auto-generated API endpoints will allow you to interact with your data.

For more detailed information on ZenStack's features and syntax, refer to the official ZenStack documentation.

Remember, while ZenStack provides powerful features, it's important to design your data model carefully to ensure it meets your application's needs and performance requirements.