Skip to content

Working without decorators

If you prefer to work without decorators, or use remult in a javascript project (without typescript) you can use the following:

Entity

ts
import { Entity, Fields, describeEntity } from 'remult'

export class Task {
  id!: string
  title = ''
  completed = false
}
describeEntity(
  Task,
  'tasks',
  {
    allowApiCrud: true,
  },
  {
    id: Fields.uuid(),
    title: Fields.string(),
    completed: Fields.boolean(),
  },
)
js
import { Entity, Fields, describeEntity } from 'remult'

export class Task {
  id
  title = ''
  completed = false
}
describeEntity(
  Task,
  'tasks',
  {
    allowApiCrud: true,
  },
  {
    id: Fields.uuid(),
    title: Fields.string(),
    completed: Fields.boolean(),
  },
)

This is the same entity that is detailed in the Entities section of the tutorial

Static BackendMethod

ts
import { BackendMethod, describeBackendMethods, remult } from "remult";
import { Task } from "./Task";

export class TasksController {
  static async setAll(completed: boolean) {
    const taskRepo = remult.repo(Task);
    for (const task of await taskRepo.find()) {
      await taskRepo.save({ ...task, completed });
    }
  }
}
describeBackendMethods(TasksController, {
  setAll: { allowed: "admin" }
})

This is the same backend method that is detailed in the Backend methods of the tutorial

MIT Licensed | Made by the Remult team with ❤️