-
Notifications
You must be signed in to change notification settings - Fork 0
Querying
Husnain Ali edited this page Sep 27, 2026
·
1 revision
Sort, limit and page in the store, or filter on any DTO field.
FetchOptions sorts and slices inside SQLite, so only the returned rows are decoded:
let latest = try await storage.fetch(User.self, options: FetchOptions(sort: .newestFirst, limit: 20))StorageSort orders by insertion or by last update; ties keep insertion order.
page(_:page:pageSize:sort:) returns a 1-based StoragePage with the total
count, so a list knows when to stop loading:
let page = try await storage.page(User.self, page: 1, pageSize: 50)
if page.hasNextPage { /* load page 2 */ }A closure filter works on any property. It decodes values in memory, 500 at a time, until it has
offset + limit matches:
let admins = try await storage.fetch(User.self, where: { $0.role == .admin })For large types or hot queries, declare the field as an index and filter in the store instead (see Indexed Fields).
all(_:batchSize:) returns a StorageSequence that fetches one batch at a time
as the loop advances:
for try await user in storage.all(User.self, batchSize: 200) {
process(user)
}SwiftLocalStorage, licensed under Apache 2.0. These pages cover v1.1.1.