v1.11.0
-
selectByQueryand its siblings gained 4 optional parameters, for pagination
and ordering:offset: the return offset.page: the 1-based page to return, an ergonomic alternative tooffset
that computes it from the page size:(page - 1) * limit.orderByID: orders the result by the table's ID column, resolved
automatically from the existing scheme machinery (TableScheme.idFieldName
→EncodingContext.tableFieldID, orEntityHandler.idFieldName).orderDirection: the newOrderDirectionenum,ascending(default) or
descending.
Semantics:
- The effective ordering is
orderByID ?? (offset != null): a non-null
offsetturns the ordering on by default, since an offset-based
pagination needs a stable order to be correct. PassorderByID: falseto
opt out and get a bareOFFSET. orderDirectionis ignored while the ordering is not active.pageis a public convenience resolved to anoffsetat the repository
layer (seeresolveSelectOffset); the adapter contract keeps taking only
offset. It throws anArgumentErrorwhen combined with anoffset(two
spellings of one thing), when there is no positivelimitto use as the
page size, or when it is< 1.page: 1resolves tooffset: 0, which
still activates the ordering, so even the first page is stable.- All 4 are optional and default to the previous behavior: with them unset the
generated SQL is character-identical to 1.10.0.
Added to
EntitySource/EntityRepository(selectByQuery,
selectFirstByQuery,select,selectIDsByQuery,selectIDsBy,
selectAll),APIRepository,IterableEntityRepository
(matches/allincluded),DBEntityRepository,DBRelationalAdapter/
DBRelationalRepositoryAdapter/DBRelationalEntityRepository,
DBAdapter.doSelectAll/doSelectByIDs,DBSQLAdapter.doSelect/
doSelectIDsBy/generateSelectSQL/generateSelectIDsSQLand
DBSQLRepositoryAdapter.generateSelectSQL. -
New
OrderDirectionenum (bones_api_types.dart), withsqlKeyword,
parseand the resolversresolveandresolveOrderByIDthat state the
semantics above exactly once. -
New
compareEntityIDsandapplySelectOrderAndPagination
(bones_api_entity.dart): the shared Dart-side "order by ID → skip → take"
used by every adapter that can't delegate the ordering to a DB engine. -
New
resolveSelectOffset(bones_api_entity.dart): resolvespageto an
offset, and states thepage/offset/limitvalidation rules once. -
SQLDialect:- New
orderBySQLandlimitOffsetSQLclause builders, so all the
dialect-specificSELECTtail syntax lives in one place. - New
offsetRequiresLimitandoffsetMaxLimitValuecapabilities. MySQL sets
offsetRequiresLimit: truesince it can't parse anOFFSETthat is not
preceded by aLIMIT; an offset-only select there emits
LIMIT 18446744073709551615 OFFSET n. PostgreSQL and thegeneric
(in-memory) dialect emit a bareOFFSET n.
- New
-
SQL: newoffset,orderByIDandorderDirectionfields (carried by
copy()), read byDBSQLMemoryAdapterto apply the same semantics in Dart. -
APIDBModule.select(/db/select/<table>): newLIMIT=<n>,OFFSET=<n>,
PAGE=<n>andORDER=asc|descquery directives
(seeAPIDBModule.selectQueryDirectives),
parsed from the queryStringalongside the pre-existingEAGER=trueand
stripped before the remainder is parsed as the entity condition query. The
endpoint no longer selects the whole table and sorts it in Dart — the ordering
is now resolved by the DB. Its output order is unchanged. An invalidPAGE
becomes an error response rather than an uncaughtArgumentError. -
Behavior change:
limitis now honored on the paths that previously
accepted and silently ignored it —DBEntityRepository.select's
ConditionID/ConditionIdIN/ConditionANY/KeyConditionEQfast paths,
DBAdapter.doSelectAll/doSelectByIDs, and theDBObjectMemoryAdapter,
DBObjectDirectoryAdapterandDBObjectGCSAdapteradapters. For example,
selectAll(limit: 2)on an object adapter returned every row before this
release; it now returns 2. -
Source-breaking for external subclasses: new named parameters were added
to abstract members (EntitySource.select/selectIDsBy/selectAll,
DBAdapter.doSelectAll/doSelectByIDs,
DBRelationalAdapter.doSelect/doSelectIDsBy). Dart requires an override to
accept every named parameter of the supertype, so third-party
EntityRepository/DBAdapterimplementations must widen their overrides. -
Known limitation: a query over a to-many relationship generates a
JOIN
without aDISTINCT, so it can return the same entity more than once
(pre-existing). Paginating such a query is therefore best-effort. -
Tests:
- New
bones_api_entity_select_order_test.dart(OrderDirection,
compareEntityIDs,applySelectOrderAndPagination,SQLDialectclause
builders),bones_api_entity_db_sql_select_test.dart(exact generated SQL
per case + end-to-end paging over the in-memory SQL adapter) and
bones_api_db_module_test.dart(first coverage ofAPIDBModule). bones_api_entity_db_tests_base.dart: 3 new tests in the shared adapter
template, so the generated SQL and real page-by-page reads are asserted for
the in-memory, PostgreSQL, MySQL, object-memory and object-directory
adapters. Verified against real PostgreSQL and MySQL containers.
- New