Skip to content

Commit 9c28890

Browse files
committed
Document fcpp::vector query results in the README
Adds a "Working with query results" section showing a filter/map chain, notes that batch writes accept an fcpp::vector, and adds a migration note: auto call sites are unaffected, explicit std::vector bindings need iterator construction, and indexing is bounds-checked (aborts instead of UB). Updates the one example that bound a fetch result to std::vector, and lists functional_cpp as a dependency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLXHcZjrnrdhRZAgqDh6kd
1 parent c24bec8 commit 9c28890

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A C++ wrapper for SQLite that provides compile-time checked CRUD operations for
1313
- [Opening and closing the database](#opening-and-closing-the-database)
1414
- [Saving records](#saving-records)
1515
- [Fetching records](#fetching-records)
16+
- [Working with query results](#working-with-query-results)
1617
- [Updating records](#updating-records)
1718
- [Deleting records](#deleting-records)
1819
- [Date and time fields](#date-and-time-fields)
@@ -346,6 +347,38 @@ Available predicate helpers include:
346347

347348
Predicate values are bound with SQLite prepared statements. Text payloads are treated as values, not SQL syntax.
348349

350+
## Working with query results
351+
352+
`FetchAll` and `Fetch` return an [`fcpp::vector<T>`](https://github.com/jkalias/functional_cpp)
353+
rather than a `std::vector<T>`, so functional operations can be chained directly on the result
354+
without wrapping it yourself:
355+
356+
```c++
357+
// Full names of every adult, straight off the query result.
358+
const auto adult_names = db->FetchAll<Person>()
359+
.filter([](const Person& p) { return p.age >= 18; })
360+
.map<std::wstring>([](const Person& p) { return p.GetFullName(); });
361+
362+
// Predicate-style checks are available too.
363+
const bool everyone_is_adult = db->FetchAll<Person>()
364+
.all_of([](const Person& p) { return p.age >= 18; });
365+
```
366+
367+
`fcpp::vector` also supports `map`, `all_of`/`any_of`/`none_of`, `sort`, `distinct`, `zip`, and lazy
368+
pipelines via `.lazy()`; see the [functional_cpp](https://github.com/jkalias/functional_cpp)
369+
documentation. The batch `Save`, `SaveAutoIncrement`, and `Update` overloads accept an
370+
`fcpp::vector<T>` as well.
371+
372+
**Migration note.** Because the result type changed from `std::vector<T>` to `fcpp::vector<T>`:
373+
374+
- `auto` call sites, range-`for` loops, indexing (`result[i]`), and `size()` are unaffected.
375+
- Code that binds a result to a `std::vector<T>` explicitly no longer compiles, because there is no
376+
implicit conversion back. Iterate the result directly, keep it as `fcpp::vector` (or `auto`), or
377+
construct a `std::vector` from its iterators: `std::vector<Person>(result.begin(), result.end())`.
378+
- Indexing is **always bounds-checked**, in release builds too: `result[i]` for an out-of-range `i`
379+
calls `std::abort()` instead of being undefined behavior (unless the library is built with
380+
`FCPP_NO_PRECONDITION_CHECKS`).
381+
349382
## Updating records
350383
351384
Fetch or construct a record, change its fields, and pass it to `Update`. The `id` identifies the row to update.
@@ -363,7 +396,7 @@ Multiple records can be updated in one call:
363396

364397
```c++
365398
// Update each record in the vector by its id.
366-
std::vector<Person> people = db->FetchAll<Person>();
399+
auto people = db->FetchAll<Person>(); // fcpp::vector<Person>
367400
people[0].last_name = L"Rambo";
368401
people[1].age = 20;
369402

@@ -494,6 +527,8 @@ You can also open the generated `build/sqlite-cpp-reflection.sln` in Visual Stud
494527

495528
- CMake 3.14 or newer
496529
- A C++11-compatible compiler
530+
- [functional_cpp](https://github.com/jkalias/functional_cpp) for `fcpp::vector` (query results) and
531+
`fcpp::optional_t` (nullable fields), header-only, fetched by CMake
497532
- GoogleTest for tests, fetched by CMake
498533
- SQLite, vendored in `src/sqlite3.c` and `src/internal/sqlite3.h`
499534

0 commit comments

Comments
 (0)