-
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
Examples for OidMap & Custom types support is sql queries #288
Comments
Hi Neo!
Hope that helps. |
Sergey, Thanks for the answers! About point 1: struct my_row {
std::int64_t id;
std::optional<std::string> name;
};
BOOST_HANA_ADAPT_STRUCT(my_row, id, name);
OZO_PG_DEFINE_CUSTOM_TYPE(my_row, "t_my_row");
...
std::vector<my_row> elements = {my_row{.id = 1, .name = "One"}, my_row{.id = 2, .name = "Two"}, my_row{.id = 3, .name = "Three"}};
auto sql = ozo::make_query("CALL test($1::t_my_row[])", std::move(elements)); doesn't compile:
Connection Pool creates with type aliases: using OzoOidMap = ozo::oid_map_t<Types...>;
using OzoConnectionInfo = ozo::connection_info<OzoOidMap>;
using OzoConnectionPoolConfig = ozo::connection_pool_config;
using OzoConnectionPool = ozo::connection_pool<OzoConnectionInfo>;
OzoConnectionPool connectionPool = ozo::make_connection_pool(
OzoConnectionInfo("..."),
OzoConnectionPoolConfig{...}) |
This might be not obvious, but the user should register the array type of the custom type too. So in your case |
@thed636 Thanks for the answers! Do you plan to implement a proper builder pattern for SQL? auto query = Query().select("*").from("users").where(...); Not sure if this will be |
Well, I have no such plans. I do not realize the problem that such a builder may solve. The library is not an ORM regarding reflecting high-level database entities with their relations into an application code. It is a middleware for handling IO-related issues like type safety, high availability, and performance. I suppose it would be nice to have an ORM, but it should be a different project IMO. Regarding the Query concept. Any product of custom query builder may be adopted via ozo::get_query_text_impl and ozo::get_query_params_impl specialization. So you do not need to use library builders to get a query. This is a customization point that users may use with any different model of the Query concept. And it is very simple to integrate into the library. |
Can't found any examples or docs about types system
Example from docs:
This is enough to do select queries like this:
1. Question 1: How to pass this struct and(or) vector of that structs as SQL param to stored procedure/function:
For example I have custom user-defined type in Postgres:
And Stored Procedure:
that take an array of records like this:
What will the calling code look like from the ozo side?
2. Question 2: What's the difference between a type resulting from a _SQL literal
like this:
and a type resulting from a call
make_query
It is clear that in one case the request is constexpr, and in the other constexpr is only part without parameters, but this is completely unclear from the documentation and there is some confusion in the interface of these types, since one has
text
as string_view member and another has text() constexpr method from boost::hana...The text was updated successfully, but these errors were encountered: