Repository navigation
Description
Problem to Solve
Currently, Serverpod does not support typed filtering for model properties that are stored in fields and are not represented as relations. This makes it difficult to select rows based on sub-properties of embedded objects, leading to increased reliance on raw queries and decreased type safety.
Proposal
Introduce a typed filtering interface for model properties stored in non-relational fields. The interface should:
- Allow typed, ergonomic filtering on serialized fields and their sub-properties
- Integrate seamlessly with Serverpod's code generation and conventions
- Enable developers to filter/query based on values inside embedded objects or lists using a type-safe builder API
- Include comprehensive documentation and usage examples
- Optionally support integration tests to validate filtering behavior across embedded objects/lists
Model Example (Serverpod YAML):
class: Settings
fields:
notificationsEnabled: bool
theme: String
class: User
table: users
fields:
name: String
settings: SettingsAPI Example:
Suppose you want to filter users whose embedded settings.notificationsEnabled value is true:
final filteredUsers = await User.db.find(
session,
where: (u) => u.settings.notificationsEnabled.equals(true),
);This would translate to a type-safe query, finding all users whose settings.notificationsEnabled sub-property is true.
Use Case
A real-world use case is filtering a list of users based on roles and preferences stored in a JSON column; e.g., retrieve all users with role == "admin" or a specific setting enabled. With typed filtering, developers can construct queries without writing raw SQL or manual deserialization, making code safer and more maintainable.
Alternatives
Alternatives considered include writing custom SQL queries or using generic JSON operations. These methods lose type safety, increase boilerplate, and require manual maintenance as models evolve. Another alternative is mapping the embedded properties to their own tables, but this adds schema complexity when strict relational mapping isn’t necessary.
Additional context
This proposal builds on the discussion in #1591 and aims to extend filtering capabilities beyond only checking for nullness. A robust filtering API for embedded/serialized model data improves discoverability and code quality across larger codebases, especially where rich models aren’t easily normalized.
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog 🗂️
Activity
ColumnSerializableimplementation is incomplete #1591iampopal commentedon Apr 15, 2026
@SandPod this is a great place to start it..