serverpod-database

Query Serverpod Dart databases with ORM-based CRUD, filters, and relations.

3.2k|369|Updated May 22, 2021
One-click install
npx skills add https://github.com/serverpod/serverpod --skill serverpod-database
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serverpod-database
Source: https://github.com/serverpod/serverpod/tree/main/packages/serverpod/skills/serverpod-database
Command: npx skills add https://github.com/serverpod/serverpod --skill serverpod-database

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the problem of building reliable, maintainable database access layers by providing a fluent ORM for CRUD, filtering, sorting, pagination, relations, and transactions so you can query Postgres or SQLite without hand-writing repetitive SQL.

Core Features & Use Cases

  • CRUD operations: Insert, find, update, and delete rows for generated models.
  • Fluent querying with filters: Use where callbacks with typed conditions (equality, comparisons, ranges, sets, like/ilike) and logical composition.
  • Sorting and pagination: Support both offset-based (limit + offset) and cursor-based pagination patterns.
  • Relations handling: Include related objects and attach/detach related rows for one-to-one and one-to-many relationships.
  • Transactions and row locking: Run multiple operations atomically and optionally lock rows with LockMode for concurrency-safe workflows.
  • Runtime parameters and raw SQL: Tune Postgres runtime settings (like search paths) and fall back to parameterized raw SQL when needed.
  • Client-side database sessions: Enable generated client code to create a local SQLite database session for offline-capable Flutter apps.

Quick Start

Generate your ORM models from your .spy.yaml (with table: defined), then use Model.db.find/findById/find with typed where filters and include to fetch related data from Postgres or SQLite.

Frequently Asked Questions about serverpod-database

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I query related data in a Dart backend using an ORM?

You can query related data by using the include and attach features of the Serverpod ORM, which handles one-to-one and one-to-many relationships. This allows you to fetch nested related entities alongside your primary generated models.

What is the best way to handle database transactions in Dart to ensure atomic updates?

Handle database transactions in Dart by wrapping multiple write operations within a single Serverpod ORM transaction. This executes all operations atomically, and you can optionally apply row locking with LockMode for concurrency-safe workflows.

Does this ORM support both Postgres and SQLite for Flutter applications?

Yes, the ORM supports both Postgres and SQLite, enabling structured CRUD operations and filtering for backend data access. It also allows generated client code to create local SQLite database sessions for offline-capable Flutter apps.

How do I implement cursor-based pagination when listing database records?

Implement cursor-based pagination by configuring your list queries within the Serverpod ORM, which supports both offset-based and cursor-based patterns. This approach allows efficient data retrieval without the performance penalties of deep offset pagination.

Can I execute raw parameterized SQL queries when the ORM filtering is not enough?

Yes, you can fall back to parameterized raw SQL queries when the ORM filtering capabilities are insufficient for your specific needs. This allows you to execute complex custom statements while tuning Postgres runtime parameters like search paths.