|
32 | 32 |
|
33 | 33 | namespace oatpp { namespace postgresql { namespace mapping { |
34 | 34 |
|
| 35 | +/** |
| 36 | + * Mapper from PostgreSQL result to oatpp objects. |
| 37 | + */ |
35 | 38 | class ResultMapper { |
36 | 39 | public: |
37 | 40 |
|
| 41 | + /** |
| 42 | + * Result data. |
| 43 | + */ |
38 | 44 | struct ResultData { |
39 | 45 |
|
| 46 | + /** |
| 47 | + * Constructor. |
| 48 | + * @param pDbResult |
| 49 | + * @param pTypeResolver |
| 50 | + */ |
40 | 51 | ResultData(PGresult* pDbResult, const std::shared_ptr<const data::mapping::TypeResolver>& pTypeResolver); |
41 | 52 |
|
| 53 | + /** |
| 54 | + * PGResult. |
| 55 | + */ |
42 | 56 | PGresult* dbResult; |
43 | 57 |
|
| 58 | + /** |
| 59 | + * &id:oatpp::data::mapping::TypeResolver;. |
| 60 | + */ |
44 | 61 | std::shared_ptr<const data::mapping::TypeResolver> typeResolver; |
45 | 62 |
|
| 63 | + /** |
| 64 | + * Column names. |
| 65 | + */ |
46 | 66 | std::vector<oatpp::String> colNames; |
| 67 | + |
| 68 | + /** |
| 69 | + * Column indices. |
| 70 | + */ |
47 | 71 | std::unordered_map<data::share::StringKeyLabel, v_int32> colIndices; |
| 72 | + |
| 73 | + /** |
| 74 | + * Column count. |
| 75 | + */ |
48 | 76 | v_int64 colCount; |
| 77 | + |
| 78 | + /** |
| 79 | + * Current row index. |
| 80 | + */ |
49 | 81 | v_int64 rowIndex; |
| 82 | + |
| 83 | + /** |
| 84 | + * Row count. |
| 85 | + */ |
50 | 86 | v_int64 rowCount; |
51 | 87 |
|
52 | 88 | }; |
@@ -129,12 +165,55 @@ class ResultMapper { |
129 | 165 | std::vector<ReadRowsMethod> m_readRowsMethods; |
130 | 166 | public: |
131 | 167 |
|
| 168 | + /** |
| 169 | + * Default constructor. |
| 170 | + */ |
132 | 171 | ResultMapper(); |
133 | 172 |
|
| 173 | + /** |
| 174 | + * Set "read one row" method for class id. |
| 175 | + * @param classId |
| 176 | + * @param method |
| 177 | + */ |
134 | 178 | void setReadOneRowMethod(const data::mapping::type::ClassId& classId, ReadOneRowMethod method); |
| 179 | + |
| 180 | + /** |
| 181 | + * Set "read rows" method for class id. |
| 182 | + * @param classId |
| 183 | + * @param method |
| 184 | + */ |
135 | 185 | void setReadRowsMethod(const data::mapping::type::ClassId& classId, ReadRowsMethod method); |
136 | 186 |
|
| 187 | + /** |
| 188 | + * Read one row to oatpp object or collection. <br> |
| 189 | + * Allowed output type classes are: |
| 190 | + * |
| 191 | + * - &id:oatpp::Vector; |
| 192 | + * - &id:oatpp::List; |
| 193 | + * - &id:oatpp::UnorderedSet; |
| 194 | + * - &id:oatpp::Fields; |
| 195 | + * - &id:oatpp::UnorderedFields; |
| 196 | + * - &id:oatpp::Object; |
| 197 | + * |
| 198 | + * @param dbData |
| 199 | + * @param type |
| 200 | + * @return |
| 201 | + */ |
137 | 202 | oatpp::Void readOneRow(ResultData* dbData, const Type* type, v_int64 rowIndex); |
| 203 | + |
| 204 | + /** |
| 205 | + * Read `count` of rows to oatpp collection. <br> |
| 206 | + * Allowed collections to store rows are: |
| 207 | + * |
| 208 | + * - &id:oatpp::Vector; |
| 209 | + * - &id:oatpp::List; |
| 210 | + * - &id:oatpp::UnorderedSet;. |
| 211 | + * |
| 212 | + * @param dbData |
| 213 | + * @param type |
| 214 | + * @param count |
| 215 | + * @return |
| 216 | + */ |
138 | 217 | oatpp::Void readRows(ResultData* dbData, const Type* type, v_int64 count); |
139 | 218 |
|
140 | 219 | }; |
|
0 commit comments