Skip to main content

Runtime Overview

Use this section when you are already past installation and want the actual runtime contract. The runtime surface should be read as:
  • new User() for a transient in-memory model instance
  • User.create(...) for one-shot persistence
  • User.createMany(...) for explicit bulk inserts
  • User.find(...), User.findOneBy(...), and safe-finder chains for reads
  • loaded-instance update(...); save() and patch(...) for readable mutation
  • User.updateMany(...), User.patchMany(...), User.deleteMany(...), and User.restoreMany(...) for explicit bulk writes
  • User.updateById(...), User.deleteById(...), and User.restoreById(...) for explicit low-level by-id service paths

Start with these pages

Practical rule

If the code is application-facing and should stay readable:
  1. query first
  2. mutate the loaded instance
  3. persist with save() or patch()
If the code is an intentionally thin service helper and already has the primary key:
  1. use User.updateById(...)
  2. use User.deleteById(...)
  3. use User.restoreById(...)
If the code is an explicit bulk service flow and already has the target ids or rows:
  1. use User.createMany(...)
  2. use User.updateMany(...) or User.patchMany(...)
  3. use User.deleteMany(...) or User.restoreMany(...)

Quick example

const created = await User.create({
  name: "Alice",
  email: "alice@example.com",
});

const found = await User.find(created.id as number);
if (found) {
  found.update({ name: "Alice Updated" });
  await found.save();
}