sonamuFilter is a feature for type-safe filtering of Entity fields. Filterable fields and allowed operators are automatically inferred from the Entity definition, preventing invalid filtering attempts at both type level and runtime.
sonamuFilter is automatically generated based on the Entityβs props. Virtual fields are excluded
from filtering targets. Relations that create FK (BelongsToOne, OneToOne with
hasJoinColumn) can be filtered using the {relation_name}_id format.
Available operators are determined by the field type:
type FilterCondition<T> = | T // Direct value (equivalent to eq) | { eq?: T } // Equals | { ne?: T } // Not equals | { gt?: T } // Greater than | { gte?: T } // Greater than or equal | { lt?: T } // Less than | { lte?: T } // Less than or equal | { in?: T[] } // Included in | { notIn?: T[] } // Not included in | { between?: [T, T] } // Range | { contains?: string } // Contains (string) | { startsWith?: string } // Starts with (string) | { endsWith?: string } // Ends with (string) | { isNull?: boolean } // Is NULL | { isNotNull?: boolean } // Is NOT NULL | { before?: Date } // Before (date) | { after?: Date }; // After (date)
// Multiple field conditions are combined with ANDconst { rows } = await ProjectModel.findMany("A", { sonamuFilter: { status: { in: ["planning", "in_progress"] }, budget: { gt: 5000 }, name: { contains: "AI" }, },});// WHERE status IN ('planning', 'in_progress')// AND budget > 5000// AND name LIKE '%AI%'
Relations that create FK (BelongsToOne, OneToOne with hasJoinColumn) can be filtered using the {relation_name}_id format. Internally converted to a virtual integer type prop, supporting all numeric operators.
// Get projects assigned to a specific employeeconst { rows } = await ProjectModel.findMany("A", { sonamuFilter: { employee_id: 5, // FK of employee relation },});// Get projects assigned to multiple employeesconst { rows } = await ProjectModel.findMany("A", { sonamuFilter: { employee_id: { in: [1, 2, 3] }, },});// Get projects with no assigneeconst { rows } = await ProjectModel.findMany("A", { sonamuFilter: { employee_id: { isNull: true }, },});// Combine FK with other conditionsconst { rows } = await ProjectModel.findMany("A", { sonamuFilter: { employee_id: { in: [1, 2, 3] }, status: "in_progress", budget: { gt: 10000 }, },});
FK filtering requires the {relation_name}_id format, not the relation name itself. For example,
if you have an employee relation, use employee_id instead of employee for filtering.
Only fields defined in the Entityβs props can be filtered. Virtual fields are excluded from filtering targets. However, relations that create FK (BelongsToOne, OneToOne with hasJoinColumn) can be filtered using the {relation_name}_id format.
// β Relations that create FK can be filtered as {relation_name}_idawait ProjectModel.findMany("A", { sonamuFilter: { employee_id: { in: [1, 2, 3] } }, // FK of employee relation});// β Error: Field 'employee' cannot be filtered (relation name itself is not allowed)await ProjectModel.findMany("A", { sonamuFilter: { employee: { eq: 1 } },});// β Error: Field 'virtual_test' cannot be filteredawait ProjectModel.findMany("A", { sonamuFilter: { virtual_test: { eq: 1 } }, // virtual field});
If existing filters and sonamuFilter filter the same field, both conditions are applied with
AND. Avoid duplicate filtering on the same field to prevent unintended results.