-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using custom struct that models hana sequence #270
Comments
Hi Neel. Could you please clarify using a class instead of a tuple for what case? For a data row representation or a composite type representation or something else? |
This is what I am doing currently. I have a fields namespace to specify all column names that will be used in where clauses in the query.
Based on this I am designing a fieldset type
While generating the where clauses of the of the sql; query I am using this class and accessing the attributes. This saves me from writting too many getters, setters and member variables to hold the values for the where clause like the following example.
So far I am using If all selects for a single table uses the same row schema then the benefit is negligible. However If there are different select queries on the same table selecting varying combinations of columns then its painful and laborious to write a different struct for all the queries. |
Well, looks like for your case it is better to handle query result as In pseudo-code it will look like this: namespace fields {
constexpr auto field1 = boost::hana::make_pair("field1", boost::hana::type_c<int>);
constexpr auto field2 = boost::hana::make_pair("field2", boost::hana::type_c<std::string>);
constexpr auto field3 = boost::hana::make_pair("field3", boost::hana::type_c<std::string>);
}
//...
ozo::result res;
ozo::request(conn, query, std::ref(res), yield);
for(auto& row: res) {
auto row_map = instantiate_row(field1, field3); // some stuff to convert pair of hana::string, hana::type to pair of hana::string and typed object
boost::hana::for_each(boost::hana::keys(row_map), [&](auto key) {
ozo::recv(row.at(key.c_str()), conn.oid_map(), row_map[key]);
});
}; |
@thed636 I could have started in that way. But my objective was to keep ozo untouched. Instead make the data struct workable with it. However its working now after modeling the |
I've a custom tuple like class that models, hana
Comparable
,Foldable
, andIterable
. I want to use that instead of usingtuple
. Do I need to implement any other concept if I want only index based access ? What do I need to do to tell ozo to use that class instead of usingtuple
?The text was updated successfully, but these errors were encountered: