-
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.
- Loading branch information
1 parent
d21eb5d
commit 6ce5112
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
-module(mongoose_rdbms_mysql). | ||
-author('[email protected]'). | ||
-behaviour(mongoose_rdbms). | ||
-behaviour(mongoose_rdbms_backend). | ||
|
||
-include("mongoose.hrl"). | ||
|
||
|
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
-module(mongoose_rdbms_odbc). | ||
-author('[email protected]'). | ||
-behaviour(mongoose_rdbms). | ||
-behaviour(mongoose_rdbms_backend). | ||
-include("mongoose_logger.hrl"). | ||
|
||
-export([escape_binary/1, escape_string/1, | ||
|
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
-module(mongoose_rdbms_pgsql). | ||
-author('[email protected]'). | ||
-behaviour(mongoose_rdbms). | ||
-behaviour(mongoose_rdbms_backend). | ||
|
||
-include_lib("epgsql/include/epgsql.hrl"). | ||
|
||
|
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