1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
*
* *
* * Copyright (c) 2018-2025, SnackCloud All rights reserved.
* *
* * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions are met:
* *
* * Redistributions of source code must retain the above copyright notice,
* * this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* * notice, this list of conditions and the following disclaimer in the
* * documentation and/or other materials provided with the distribution.
* * Neither the name of the www.snackcloud.cn developer nor the names of its
* * contributors may be used to endorse or promote products derived from
* * this software without specific prior written permission.
* * Author: SnackCloud
* *
*
*/
//! Shared mapper utilities for both sync and async implementations.
//!
//! This module contains helper functions and types that are common to both
//! `AkitaMapper` (blocking) and `AsyncAkitaMapper` (non-blocking) traits.
use cratedata_err;
use crate;
use ;
/// Process raw rows into a vector of deserialized objects.
///
/// Each row is converted from its `AkitaValue` representation into the target
/// type `R` using the `FromAkitaValue` trait. This is the core logic shared by
/// both sync and async `exec_raw` implementations.
///
/// # Parameters
/// - `rows`: The raw rows returned from a query.
///
/// # Returns
/// A `Vec<R>` of deserialized objects, one per input row.
/// Extract a single record from rows, returning an error if empty or multiple.
///
/// Expects exactly one row in the result set. Returns an error if zero rows or
/// more than one row is returned. This is the core logic shared by both sync
/// and async `exec_first` implementations.
///
/// # Parameters
/// - `rows`: The raw rows returned from a query.
///
/// # Returns
/// `Ok(R)` with the single deserialized record, or an `Err` if the result set
/// does not contain exactly one row.
/// Extract an optional single record from rows.
///
/// Returns `Ok(None)` if the result set is empty, `Ok(Some(value))` if exactly
/// one row is present, or an error if multiple records are found. This is the
/// core logic shared by both sync and async `exec_first_opt` implementations.
///
/// # Parameters
/// - `rows`: The raw rows returned from a query.
///
/// # Returns
/// `Ok(None)` when no rows are found, `Ok(Some(R))` when exactly one row is
/// found, or an `Err` when more than one row is returned.
/// Fold (reduce) rows using a function and an initial accumulator value.
///
/// Each row is deserialized to type `T` and then folded into the accumulator
/// of type `U` using the provided closure. This is the core logic shared by
/// both sync and async `query_fold` implementations.
///
/// # Parameters
/// - `rows`: The raw rows returned from a query.
/// - `init`: The initial accumulator value.
/// - `f`: A closure that combines the accumulator with each deserialized row.
///
/// # Returns
/// The final accumulated value after processing all rows.
/// Map rows through a transformation function.
///
/// Each row is deserialized to type `T` and then transformed into type `U`
/// using the provided closure. This is the core logic shared by both sync and
/// async `query_map` implementations.
///
/// # Parameters
/// - `rows`: The raw rows returned from a query.
/// - `f`: A closure that transforms each deserialized row.
///
/// # Returns
/// A `Vec<U>` of transformed values, one per input row.