📏 Rules
Remult - core
You are a full-stack expert using remult with: - TypeScript Key Principles - Remult is the single source of truth for your application. ## Entities are the SSoT ```ts filename=src/shared/Task.ts imp
Description
You are a full-stack expert using remult with:
- TypeScript
Key Principles
- Remult is the single source of truth for your application.
Entities are the SSoT
import { Entity, Fields } from 'remult'
@Entity('tasks', {
allowApiCrud: true,
})
export class Task {
@Fields.cuid()
id!: string
@Fields.string()
title: string = ''
@Fields.boolean()
completed: boolean = false
@Fields.createdAt()
createdAt?: Date
}
In the backend and the frontend you can do Pagination, Sorting, Filtering and Aggregation
import { repo } from 'remult'
repo(Task)
.find({
limit: 20,
orderBy: { createdAt: "asc" },
where: { completed: true }
})
All CRUD operations are available in frontend and backend
// create
await repo(Task).insert({ title: newTaskTitle });
// update
await repo(Task).update(taskId, { title: newTaskTitle });
// delete
await repo(Task).delete(taskId);
Add validation to your entities
@Entity('tasks', {
allowApiCrud: true,
})
export class Task {
import { Validators } from 'remult';
@Fields.string({
validate: Validators.required
})
title: string = '';
}
Live Queries
repo(Task)
.liveQuery({ where: { completed: true } })
.subscribe((info) => {
tasks = info.applyChanges(tasks);
});
Database
By default Remult use JSON database, but you can use any database listed here: https://remult.dev/docs/installation/database/ example for PostgreSQL:
import { createPostgresDataProvider } from 'remult/postgres'
// Server options
{
// ...
entities: [Task],
dataProvider: DATABASE_URL
? createPostgresDataProvider({ connectionString: DATABASE_URL })
: undefined,
// ...
}
Documentation
- Remult Documentation: https://remult.dev/docs
Reviews (0)
Sign in to write a review.
No reviews yet. Be the first to review!
Comments (0)
No comments yet. Be the first to share your thoughts!