-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3390 from esl/wdbm-mongoose_rdbms
With the changes done in #3386, this turned out to be really easy. Before that, I tried to make mongoose_rdbms_backend expose its API with HostTypes, but it was a bit messy. I think it's better to do it in a separate PR (after the whole without-dynamic-backend-modules branch is merged), to keep this already big diff smaller and more focused. Other issue is that mongoose_rdbms has many functions exported, which seem to be not used, mainly for escaping different types. This could be revisited, but, in similar fashion, I left this as is for now. What's left to do is remove dynamic mongoose_rdbms_type, but it will be done in a separate PR.
- Loading branch information
Showing
9 changed files
with
103 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @copyright 2021, Erlang Solutions Ltd. | ||
%%% @doc Proxy module for rdbms backends. | ||
%%% | ||
%%% @end | ||
%%%------------------------------------------------------------------- | ||
-module(mongoose_rdbms_backend). | ||
-export([escape_binary/1, | ||
escape_string/1, | ||
unescape_binary/1, | ||
connect/2, | ||
disconnect/1, | ||
query/3, | ||
prepare/5, | ||
execute/4]). | ||
|
||
-define(MAIN_MODULE, mongoose_rdbms). | ||
|
||
|
||
-callback escape_binary(binary()) -> mongoose_rdbms:sql_query_part(). | ||
-callback escape_string(binary()|list()) -> mongoose_rdbms:sql_query_part(). | ||
|
||
-callback unescape_binary(binary()) -> binary(). | ||
-callback connect(Args :: any(), QueryTimeout :: non_neg_integer()) -> | ||
{ok, Connection :: term()} | {error, Reason :: any()}. | ||
-callback disconnect(Connection :: term()) -> any(). | ||
-callback query(Connection :: term(), Query :: any(), Timeout :: infinity | non_neg_integer()) -> | ||
mongoose_rdbms:query_result(). | ||
-callback prepare(Connection :: term(), Name :: atom(), | ||
Table :: binary(), Fields :: [binary()], Statement :: iodata()) -> | ||
{ok, Ref :: term()} | {error, Reason :: any()}. | ||
-callback execute(Connection :: term(), Ref :: term(), Parameters :: [term()], | ||
Timeout :: infinity | non_neg_integer()) -> mongoose_rdbms:query_result(). | ||
|
||
%% If not defined, generic escaping is used | ||
-optional_callbacks([escape_string/1]). | ||
|
||
|
||
-spec escape_binary(binary()) -> mongoose_rdbms:sql_query_part(). | ||
escape_binary(Binary) -> | ||
Args = [Binary], | ||
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec escape_string(binary() | list()) -> mongoose_rdbms:sql_query_part(). | ||
escape_string(String) -> | ||
Args = [String], | ||
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec unescape_binary(binary()) -> binary(). | ||
unescape_binary(Binary) -> | ||
Args = [Binary], | ||
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec connect(Settings :: any(), QueryTimeout :: non_neg_integer()) -> | ||
{ok, Connection :: term()} | {error, Reason :: any()}. | ||
connect(Settings, QueryTimeout) -> | ||
Args = [Settings, QueryTimeout], | ||
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec disconnect(Connection :: term()) -> any(). | ||
disconnect(Connection) -> | ||
Args = [Connection], | ||
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec query(Connection :: term(), Query :: any(), Timeout :: infinity | non_neg_integer()) -> | ||
mongoose_rdbms:query_result(). | ||
query(Connection, Query, Timeout) -> | ||
Args = [Connection, Query, Timeout], | ||
mongoose_backend:call_tracked(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec prepare(Connection :: term(), Name :: atom(), | ||
Table :: binary(), Fields :: [binary()], Statement :: iodata()) -> | ||
{ok, Ref :: term()} | {error, Reason :: any()}. | ||
prepare(Connection, Name, Table, Fields, Statement) -> | ||
Args = [Connection, Name, Table, Fields, Statement], | ||
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec execute(Connection :: term(), Ref :: term(), Parameters :: [term()], | ||
Timeout :: infinity | non_neg_integer()) -> mongoose_rdbms:query_result(). | ||
execute(Connection, Ref, Parameters, Timeout) -> | ||
Args = [Connection, Ref, Parameters, Timeout], | ||
mongoose_backend:call_tracked(global, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters