Skip to main content
findMany is a method that retrieves multiple records matching conditions. It supports pagination, search, filtering, and sorting, returning results along with the total count.
findMany is not defined in BaseModelClass. It’s a standard pattern automatically generated by the Syncer in each Model class when you create an Entity.

Type Signature

Auto-Generated Code

Sonamu automatically generates the following code based on your Entity:
How it works:
  1. getSubsetQueries(): Gets subset query builder from BaseModelClass method
  2. Add conditions: Add WHERE, search, and sorting conditions
  3. createEnhancers(): Creates virtual field calculation functions from BaseModelClass method
  4. executeSubsetQuery(): Executes actual query from BaseModelClass method
    • COUNT query (total)
    • SELECT query (rows)
    • Loader execution (load relationship data)
    • Hydrate (flat β†’ nested objects)
    • Apply enhancers (calculate virtual fields)

Parameters

subset

Specifies the subset of data to retrieve. Type: SubsetKey (e.g., "A", "B", "C")

params

Query conditions and pagination settings. Type: ListParams (optional)

Default Values

Return Value

Type: Promise<ListResult<LP, SubsetMapping[T]>>
When semanticQuery is provided, a similarity field (a score between 0 and 1) is automatically added to each row.

rows

Array of retrieved records.

total

Total number of records matching the conditions.

Pagination

num (Items per page)

Number of records to display per page. Default: 24

page (Page number)

Page number to fetch (starts from 1). Default: 1

Filtering

ID Filter

Custom Filters

Additional filters available depending on Entity definition.

search + keyword

Implementation Example

Generated Model code:

Sorting

orderBy

Implementation Example

Query Mode

queryMode: β€œboth” (default)

Returns both list and total count.

queryMode: β€œlist”

Returns list only (skips COUNT query).
Use queryMode: "list" for performance improvement when COUNT query is heavy.

queryMode: β€œcount”

Returns total count only (skips SELECT query).

Basic Usage

Simple List

Filtering + Pagination

Search + Sorting

Practical Examples

Using BaseModelClass Methods

findMany internally uses the following BaseModelClass methods:

getSubsetQueries()

Gets subset query builder.

createEnhancers()

Creates virtual field calculation functions.

executeSubsetQuery()

Executes query and returns results.

Type Safety

Subset Type Inference

ListParams Type

queryMode Type Inference

Performance Optimization

1. Use queryMode: β€œlist”

When COUNT query is heavy:

2. Use Indexes

Add indexes on frequently filtered fields:

3. Minimize Subsets

Use subsets that include only necessary fields:

4. Limit num

Prevent fetching too much data at once:

Cautions

1. Caution with num: 0

num: 0 fetches all records, use carefully.

2. page Starts from 1

3. Subset Selection

Next Steps

findById

Retrieve single record by ID

save

Save and update records

Subset

Understanding subsets

Puri Query Builder

Advanced query building