Skip to content

Conversation

@link2xt
Copy link
Collaborator

@link2xt link2xt commented Nov 3, 2025

We use query_and_then() instead of query_map() function now. The difference is that row processing function
returns anyhow::Result, so simple fallible processing like JSON parsing can be done inside of it
when calling query_map_vec() and query_map_collect() without having to resort to query_map()
and iterating over all rows again afterwards.

@link2xt link2xt force-pushed the link2xt/query_and_then branch from 43697ce to 21f33d1 Compare November 3, 2025 16:55
@link2xt
Copy link
Collaborator Author

link2xt commented Nov 3, 2025

It is a bit strange that our query_map() function now calls query_and_then() internally and has rusqlite::AndThenRows in its type, but I don't think it justifies renaming every call across the whole codebase and rusqlite naming of these functions is not perfect anyway.

@link2xt link2xt force-pushed the link2xt/query_and_then branch 2 times, most recently from 17dd457 to 19192c7 Compare November 3, 2025 17:17
We use query_and_then() instead of query_map() function now.
The difference is that row processing function
returns anyhow::Result, so simple fallible processing
like JSON parsing can be done inside of it
when calling query_map_vec() and query_map_collect()
without having to resort to query_map()
and iterating over all rows again afterwards.
@link2xt link2xt force-pushed the link2xt/query_and_then branch from 19192c7 to e72b316 Compare November 3, 2025 19:05
@link2xt link2xt mentioned this pull request Nov 3, 2025
16 tasks
where
F: Send + FnMut(&rusqlite::Row) -> rusqlite::Result<T>,
G: Send + FnOnce(rusqlite::MappedRows<F>) -> Result<H>,
F: Send + FnMut(&rusqlite::Row) -> Result<T>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most interesting change, the Result is anyhow::Result here now.

)
.query_map_vec("SELECT entered_param FROM transports", (), |row| {
let entered_param: String = row.get(0)?;
let transport: EnteredLoginParam = serde_json::from_str(&entered_param)?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can see how this change is useful, we can now parse JSON with query_map_vec.

@link2xt link2xt requested review from Hocuri and iequidoo November 3, 2025 22:10
@link2xt link2xt merged commit b44be09 into main Nov 3, 2025
29 checks passed
@link2xt link2xt deleted the link2xt/query_and_then branch November 3, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants