Formatting fixed
This commit is contained in:
@@ -53,8 +53,9 @@
|
|||||||
%% To open multiple dbases on the same node use open/1 or open/2.
|
%% To open multiple dbases on the same node use open/1 or open/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(result() :: {'ok', pid()} | 'ignore' | {'error', any()}).
|
-type result() :: {'ok', pid()} | 'ignore' | {'error', any()}.
|
||||||
-spec(start_link/1::(atom()) -> result()).
|
|
||||||
|
-spec start_link(atom()) -> result().
|
||||||
|
|
||||||
start_link(Db) ->
|
start_link(Db) ->
|
||||||
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
||||||
@@ -74,7 +75,7 @@ start_link(Db) ->
|
|||||||
%% To open multiple dbases on the same node use open/1 or open/2.
|
%% To open multiple dbases on the same node use open/1 or open/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(start_link/2::(atom(), [{atom(), any()}]) -> result()).
|
-spec start_link(atom(), [{atom(), any()}]) -> result().
|
||||||
start_link(Db, Options) ->
|
start_link(Db, Options) ->
|
||||||
Opts = case proplists:get_value(db, Options) of
|
Opts = case proplists:get_value(db, Options) of
|
||||||
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
|
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
|
||||||
@@ -92,7 +93,7 @@ start_link(Db, Options) ->
|
|||||||
%% and drop_table/2.
|
%% and drop_table/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(open/1::(atom()) -> result()).
|
-spec open(atom()) -> result().
|
||||||
open(Db) ->
|
open(Db) ->
|
||||||
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ open(Db) ->
|
|||||||
%% and drop_table/2.
|
%% and drop_table/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(open/2::(atom(), [{atom(), any()}]) -> result()).
|
-spec open(atom(), [{atom(), any()}]) -> result().
|
||||||
open(Db, Options) ->
|
open(Db, Options) ->
|
||||||
gen_server:start_link({local, Db}, ?MODULE, Options, []).
|
gen_server:start_link({local, Db}, ?MODULE, Options, []).
|
||||||
|
|
||||||
@@ -118,7 +119,7 @@ open(Db, Options) ->
|
|||||||
%% Closes the Db sqlite3 dbase.
|
%% Closes the Db sqlite3 dbase.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(close/1::(atom()) -> 'ok').
|
-spec close(atom()) -> 'ok'.
|
||||||
close(Db) ->
|
close(Db) ->
|
||||||
gen_server:call(Db, close).
|
gen_server:call(Db, close).
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ close(Db) ->
|
|||||||
%% Closes the sqlite3 dbase.
|
%% Closes the sqlite3 dbase.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(stop/0::() -> 'ok').
|
-spec stop() -> 'ok'.
|
||||||
stop() ->
|
stop() ->
|
||||||
?MODULE:close(?MODULE).
|
?MODULE:close(?MODULE).
|
||||||
|
|
||||||
@@ -138,7 +139,7 @@ stop() ->
|
|||||||
%% Executes the Sql statement directly.
|
%% Executes the Sql statement directly.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(sql_exec/1::(string()) -> any()).
|
-spec sql_exec(string()) -> any().
|
||||||
sql_exec(SQL) ->
|
sql_exec(SQL) ->
|
||||||
?MODULE:sql_exec(?MODULE, SQL).
|
?MODULE:sql_exec(?MODULE, SQL).
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ sql_exec(SQL) ->
|
|||||||
%% result of the Sql call.
|
%% result of the Sql call.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(sql_exec/2::(atom(), string()) -> any()).
|
-spec sql_exec(atom(), string()) -> any().
|
||||||
sql_exec(Db, SQL) ->
|
sql_exec(Db, SQL) ->
|
||||||
gen_server:call(Db, {sql_exec, SQL}).
|
gen_server:call(Db, {sql_exec, SQL}).
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ sql_exec(Db, SQL) ->
|
|||||||
%% Returns the result of the create table call.
|
%% Returns the result of the create table call.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_table/2::(atom(), [tuple()]) -> any()).
|
-spec create_table(atom(), [tuple()]) -> any().
|
||||||
create_table(Tbl, Options) ->
|
create_table(Tbl, Options) ->
|
||||||
?MODULE:create_table(?MODULE, Tbl, Options).
|
?MODULE:create_table(?MODULE, Tbl, Options).
|
||||||
|
|
||||||
@@ -177,7 +178,7 @@ create_table(Tbl, Options) ->
|
|||||||
%% Returns the result of the create table call.
|
%% Returns the result of the create table call.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_table/3::(atom(), atom(), [{atom(), any()}]) -> any()).
|
-spec create_table(atom(), atom(), [{atom(), any()}]) -> any().
|
||||||
create_table(Db, Tbl, Options) ->
|
create_table(Db, Tbl, Options) ->
|
||||||
gen_server:call(Db, {create_table, Tbl, Options}).
|
gen_server:call(Db, {create_table, Tbl, Options}).
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ create_table(Db, Tbl, Options) ->
|
|||||||
%% Returns a list of tables.
|
%% Returns a list of tables.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(list_tables/0::() -> [atom()]).
|
-spec list_tables() -> [atom()].
|
||||||
list_tables() ->
|
list_tables() ->
|
||||||
?MODULE:list_tables(?MODULE).
|
?MODULE:list_tables(?MODULE).
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ list_tables() ->
|
|||||||
%% Returns a list of tables for Db.
|
%% Returns a list of tables for Db.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(list_tables/1::(atom()) -> [atom()]).
|
-spec list_tables(atom()) -> [atom()].
|
||||||
list_tables(Db) ->
|
list_tables(Db) ->
|
||||||
gen_server:call(Db, list_tables).
|
gen_server:call(Db, list_tables).
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ list_tables(Db) ->
|
|||||||
%% Returns table schema for Tbl.
|
%% Returns table schema for Tbl.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(table_info/1::(atom()) -> [any()]).
|
-spec table_info(atom()) -> [any()].
|
||||||
table_info(Tbl) ->
|
table_info(Tbl) ->
|
||||||
?MODULE:table_info(?MODULE, Tbl).
|
?MODULE:table_info(?MODULE, Tbl).
|
||||||
|
|
||||||
@@ -217,7 +218,7 @@ table_info(Tbl) ->
|
|||||||
%% Returns table schema for Tbl in Db.
|
%% Returns table schema for Tbl in Db.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(table_info/2::(atom(), atom()) -> [any()]).
|
-spec table_info(atom(), atom()) -> [any()].
|
||||||
table_info(Db, Tbl) ->
|
table_info(Db, Tbl) ->
|
||||||
gen_server:call(Db, {table_info, Tbl}).
|
gen_server:call(Db, {table_info, Tbl}).
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ table_info(Db, Tbl) ->
|
|||||||
%% determined from table_info/2.
|
%% determined from table_info/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write/2::(atom(), [{atom(), any()}]) -> any()).
|
-spec write(atom(), [{atom(), any()}]) -> any().
|
||||||
write(Tbl, Data) ->
|
write(Tbl, Data) ->
|
||||||
?MODULE:write(?MODULE, Tbl, Data).
|
?MODULE:write(?MODULE, Tbl, Data).
|
||||||
|
|
||||||
@@ -241,7 +242,7 @@ write(Tbl, Data) ->
|
|||||||
%% same type as determined from table_info/3.
|
%% same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write/3::(atom(), atom(), [{atom(), any()}]) -> any()).
|
-spec write(atom(), atom(), [{atom(), any()}]) -> any().
|
||||||
write(Db, Tbl, Data) ->
|
write(Db, Tbl, Data) ->
|
||||||
gen_server:call(Db, {write, Tbl, Data}).
|
gen_server:call(Db, {write, Tbl, Data}).
|
||||||
|
|
||||||
@@ -284,7 +285,7 @@ update (Db, Tbl, Key, Value, Data) ->
|
|||||||
%% have the same type as determined from table_info/2.
|
%% have the same type as determined from table_info/2.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(read/2::(atom(), {atom(), any()}) -> any()).
|
-spec read(atom(), {atom(), any()}) -> any().
|
||||||
read(Tbl, Key) ->
|
read(Tbl, Key) ->
|
||||||
?MODULE:read(?MODULE, Tbl, Key).
|
?MODULE:read(?MODULE, Tbl, Key).
|
||||||
|
|
||||||
@@ -297,7 +298,7 @@ read(Tbl, Key) ->
|
|||||||
%% ColValue must have the same type as determined from table_info/3.
|
%% ColValue must have the same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(read/3::(atom(), atom(), {atom(), any()}) -> any()).
|
-spec read(atom(), atom(), {atom(), any()}) -> any().
|
||||||
read(Db, Tbl, Key) ->
|
read(Db, Tbl, Key) ->
|
||||||
gen_server:call(Db, {read, Tbl, Key}).
|
gen_server:call(Db, {read, Tbl, Key}).
|
||||||
|
|
||||||
@@ -326,7 +327,7 @@ read (Db, Tbl, Key, Columns) ->
|
|||||||
%% ColValue must have the same type as determined from table_info/3.
|
%% ColValue must have the same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(delete/2::(atom(), {atom(), any()}) -> any()).
|
-spec delete(atom(), {atom(), any()}) -> any().
|
||||||
delete(Tbl, Key) ->
|
delete(Tbl, Key) ->
|
||||||
?MODULE:delete(?MODULE, Tbl, Key).
|
?MODULE:delete(?MODULE, Tbl, Key).
|
||||||
|
|
||||||
@@ -339,7 +340,7 @@ delete(Tbl, Key) ->
|
|||||||
%% ColValue must have the same type as determined from table_info/3.
|
%% ColValue must have the same type as determined from table_info/3.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(delete/3::(atom(), atom(), {atom(), any()}) -> any()).
|
-spec delete(atom(), atom(), {atom(), any()}) -> any().
|
||||||
delete(Db, Tbl, Key) ->
|
delete(Db, Tbl, Key) ->
|
||||||
gen_server:call(Db, {delete, Tbl, Key}).
|
gen_server:call(Db, {delete, Tbl, Key}).
|
||||||
|
|
||||||
@@ -349,7 +350,7 @@ delete(Db, Tbl, Key) ->
|
|||||||
%% Drop the table Tbl.
|
%% Drop the table Tbl.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(drop_table/1::(atom()) -> any()).
|
-spec drop_table(atom()) -> any().
|
||||||
drop_table(Tbl) ->
|
drop_table(Tbl) ->
|
||||||
?MODULE:drop_table(?MODULE, Tbl).
|
?MODULE:drop_table(?MODULE, Tbl).
|
||||||
|
|
||||||
@@ -359,7 +360,7 @@ drop_table(Tbl) ->
|
|||||||
%% Drop the table Tbl from Db dbase.
|
%% Drop the table Tbl from Db dbase.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(drop_table/2::(atom(), atom()) -> any()).
|
-spec drop_table(atom(), atom()) -> any().
|
||||||
drop_table(Db, Tbl) ->
|
drop_table(Db, Tbl) ->
|
||||||
gen_server:call(Db, {drop_table, Tbl}).
|
gen_server:call(Db, {drop_table, Tbl}).
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ drop_table(Db, Tbl) ->
|
|||||||
%%
|
%%
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_function/3::(atom(), atom(), function()) -> any()).
|
-spec create_function(atom(), atom(), function()) -> any().
|
||||||
create_function(Db, FunctionName, Function) ->
|
create_function(Db, FunctionName, Function) ->
|
||||||
gen_server:call(Db, {create_function, FunctionName, Function}).
|
gen_server:call(Db, {create_function, FunctionName, Function}).
|
||||||
|
|
||||||
@@ -390,7 +391,7 @@ create_function(Db, FunctionName, Function) ->
|
|||||||
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql_unsafe/1::(sql_value()) -> iodata()).
|
-spec value_to_sql_unsafe(sql_value()) -> iodata().
|
||||||
value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -405,7 +406,7 @@ value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
|||||||
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
%% Reexported from sqlite3_lib:value_to_sql/1 for user convenience.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql/1::(sql_value()) -> iolist()).
|
-spec value_to_sql(sql_value()) -> iolist().
|
||||||
value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
@@ -421,8 +422,8 @@ value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(init_return() :: {'ok', tuple()} | {'ok', tuple(), integer()} | 'ignore' | {'stop', any()}).
|
-type init_return() :: {'ok', tuple()} | {'ok', tuple(), integer()} | 'ignore' | {'stop', any()}.
|
||||||
-spec(init/1::([any()]) -> init_return()).
|
-spec init([any()]) -> init_return().
|
||||||
init(Options) ->
|
init(Options) ->
|
||||||
Dbase = proplists:get_value(db, Options),
|
Dbase = proplists:get_value(db, Options),
|
||||||
{?MODULE, _, FileName} = code:get_object_code(?MODULE),
|
{?MODULE, _, FileName} = code:get_object_code(?MODULE),
|
||||||
@@ -447,10 +448,10 @@ init(Options) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(handle_call_return() :: {reply, any(), tuple()} | {reply, any(), tuple(), integer()} |
|
-type handle_call_return() :: {reply, any(), tuple()} | {reply, any(), tuple(), integer()} |
|
||||||
{noreply, tuple()} | {noreply, tuple(), integer()} |
|
{noreply, tuple()} | {noreply, tuple(), integer()} |
|
||||||
{stop, any(), any(), tuple()} | {stop, any(), tuple()}).
|
{stop, any(), any(), tuple()} | {stop, any(), tuple()}.
|
||||||
-spec(handle_call/3::(any(), pid(), tuple()) -> handle_call_return()).
|
-spec handle_call(any(), pid(), tuple()) -> handle_call_return().
|
||||||
handle_call(close, _From, State) ->
|
handle_call(close, _From, State) ->
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{stop, normal, Reply, State};
|
{stop, normal, Reply, State};
|
||||||
@@ -514,9 +515,9 @@ handle_call(_Request, _From, State) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-type(handle_cast_return() :: {noreply, tuple()} | {noreply, tuple(), integer()} |
|
-type handle_cast_return() :: {noreply, tuple()} | {noreply, tuple(), integer()} |
|
||||||
{stop, any(), tuple()}).
|
{stop, any(), tuple()}.
|
||||||
-spec(handle_cast/2::(any(), tuple()) -> handle_cast_return()).
|
-spec handle_cast(any(), tuple()) -> handle_cast_return().
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
@@ -528,7 +529,7 @@ handle_cast(_Msg, State) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(handle_info/2::(any(), tuple()) -> handle_cast_return()).
|
-spec handle_info(any(), tuple()) -> handle_cast_return().
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
@@ -541,7 +542,7 @@ handle_info(_Info, State) ->
|
|||||||
%% @end
|
%% @end
|
||||||
%% @hidden
|
%% @hidden
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(terminate/2::(atom(), tuple()) -> atom()).
|
-spec terminate(atom(), tuple()) -> atom().
|
||||||
terminate(normal, #state{port = Port}) ->
|
terminate(normal, #state{port = Port}) ->
|
||||||
port_command(Port, term_to_binary({close, nop})),
|
port_command(Port, term_to_binary({close, nop})),
|
||||||
port_close(Port),
|
port_close(Port),
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
%% @doc Maps sqlite3 column type.
|
%% @doc Maps sqlite3 column type.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(col_type_to_string/1::(atom()) -> string()).
|
-spec col_type_to_string(atom()) -> string().
|
||||||
col_type_to_string(integer) ->
|
col_type_to_string(integer) ->
|
||||||
"INTEGER";
|
"INTEGER";
|
||||||
col_type_to_string(text) ->
|
col_type_to_string(text) ->
|
||||||
@@ -40,7 +40,7 @@ col_type_to_string(real) ->
|
|||||||
%% @doc Maps sqlite3 column type.
|
%% @doc Maps sqlite3 column type.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(col_type_to_atom/1::(string()) -> atom()).
|
-spec col_type_to_atom(string()) -> atom().
|
||||||
col_type_to_atom("INTEGER") ->
|
col_type_to_atom("INTEGER") ->
|
||||||
integer;
|
integer;
|
||||||
col_type_to_atom("TEXT") ->
|
col_type_to_atom("TEXT") ->
|
||||||
@@ -61,7 +61,7 @@ col_type_to_atom("REAL") ->
|
|||||||
%% single quotes (e.g. can be entered by users).
|
%% single quotes (e.g. can be entered by users).
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql_unsafe/1::(sql_value()) -> iodata()).
|
-spec value_to_sql_unsafe(sql_value()) -> iodata().
|
||||||
value_to_sql_unsafe(X) ->
|
value_to_sql_unsafe(X) ->
|
||||||
if
|
if
|
||||||
is_integer(X) -> integer_to_list(X);
|
is_integer(X) -> integer_to_list(X);
|
||||||
@@ -80,7 +80,7 @@ value_to_sql_unsafe(X) ->
|
|||||||
%% All single quotes (') will be replaced with ''.
|
%% All single quotes (') will be replaced with ''.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(value_to_sql/1::(sql_value()) -> iolist()).
|
-spec value_to_sql(sql_value()) -> iolist().
|
||||||
value_to_sql(X) ->
|
value_to_sql(X) ->
|
||||||
if
|
if
|
||||||
is_integer(X) -> integer_to_list(X);
|
is_integer(X) -> integer_to_list(X);
|
||||||
@@ -95,7 +95,7 @@ value_to_sql(X) ->
|
|||||||
%% Creates the values portion of the sql stmt.
|
%% Creates the values portion of the sql stmt.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_value_sql/1::(any()) -> string()).
|
-spec write_value_sql(any()) -> string().
|
||||||
write_value_sql(Values) ->
|
write_value_sql(Values) ->
|
||||||
map_intersperse(fun value_to_sql/1, Values, ",").
|
map_intersperse(fun value_to_sql/1, Values, ",").
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ write_value_sql(Values) ->
|
|||||||
%% @doc Creates the column/data stmt for SQL.
|
%% @doc Creates the column/data stmt for SQL.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_col_sql/1::([atom()]) -> string()).
|
-spec write_col_sql([atom()]) -> string().
|
||||||
write_col_sql(Cols) ->
|
write_col_sql(Cols) ->
|
||||||
map_intersperse(fun atom_to_list/1, Cols, ",").
|
map_intersperse(fun atom_to_list/1, Cols, ",").
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ write_col_sql(Cols) ->
|
|||||||
%% @doc Returns copy of String for which \" replaced with '
|
%% @doc Returns copy of String for which \" replaced with '
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (replace/1::(string ()) -> string ()).
|
-spec replace(string()) -> string().
|
||||||
replace([]) -> [];
|
replace([]) -> [];
|
||||||
replace([$" | T]) ->
|
replace([$" | T]) ->
|
||||||
[$' | replace(T)];
|
[$' | replace(T)];
|
||||||
@@ -127,7 +127,7 @@ replace([H | T]) ->
|
|||||||
%% @doc Returns copy of IoData with all ' replaced by ''
|
%% @doc Returns copy of IoData with all ' replaced by ''
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(escape/1::(iodata()) -> iodata()).
|
-spec escape(iodata()) -> iodata().
|
||||||
escape(IoData) -> re:replace(IoData, "'", "''", [global]).
|
escape(IoData) -> re:replace(IoData, "'", "''", [global]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@@ -140,7 +140,7 @@ escape(IoData) -> re:replace(IoData, "'", "''", [global]).
|
|||||||
%% For strings \" replaced with '.
|
%% For strings \" replaced with '.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (update_set_sql/1::(any ()) -> string ()).
|
-spec update_set_sql(any()) -> string().
|
||||||
update_set_sql(Data) ->
|
update_set_sql(Data) ->
|
||||||
ColValueToSqlFun =
|
ColValueToSqlFun =
|
||||||
fun({Col, Value}) ->
|
fun({Col, Value}) ->
|
||||||
@@ -154,7 +154,7 @@ update_set_sql (Data) ->
|
|||||||
%% Creates list of columns for select stmt.
|
%% Creates list of columns for select stmt.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (read_cols_sql/1::([atom ()]) -> string ()).
|
-spec read_cols_sql([atom()]) -> string().
|
||||||
read_cols_sql(Columns) ->
|
read_cols_sql(Columns) ->
|
||||||
map_intersperse(fun atom_to_list/1, Columns, ", ").
|
map_intersperse(fun atom_to_list/1, Columns, ", ").
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ read_cols_sql (Columns) ->
|
|||||||
%% First column listed is considered the primary key.
|
%% First column listed is considered the primary key.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(create_table_sql/2::(atom(), [{atom(), string()}]) -> string()).
|
-spec create_table_sql(atom(), [{atom(), string()}]) -> string().
|
||||||
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
||||||
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
|
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
|
||||||
Start = ["(", atom_to_list(ColName), " ", col_type_to_string(Type), " PRIMARY KEY, "],
|
Start = ["(", atom_to_list(ColName), " ", col_type_to_string(Type), " PRIMARY KEY, "],
|
||||||
@@ -189,7 +189,7 @@ create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
|
|||||||
%% record with matching Value.
|
%% record with matching Value.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (update_sql/4::(atom (), atom (), atom (), [{atom (), sql_value ()}]) -> string ()).
|
-spec update_sql(atom(), atom(), atom(), [{atom(), sql_value()}]) -> string().
|
||||||
update_sql(Tbl, Key, Value, Data) ->
|
update_sql(Tbl, Key, Value, Data) ->
|
||||||
["UPDATE ", atom_to_list(Tbl), " SET ", update_set_sql(Data),
|
["UPDATE ", atom_to_list(Tbl), " SET ", update_set_sql(Data),
|
||||||
" WHERE ", atom_to_list(Key), " = ", value_to_sql(Value), ";"].
|
" WHERE ", atom_to_list(Key), " = ", value_to_sql(Value), ";"].
|
||||||
@@ -202,7 +202,7 @@ update_sql (Tbl, Key, Value, Data) ->
|
|||||||
%% proper insertion SQL stmt.
|
%% proper insertion SQL stmt.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(write_sql/2::(atom(), [{atom(), sql_value()}]) -> string()).
|
-spec write_sql(atom(), [{atom(), sql_value()}]) -> string().
|
||||||
write_sql(Tbl, Data) ->
|
write_sql(Tbl, Data) ->
|
||||||
{Cols, Values} = lists:unzip(Data),
|
{Cols, Values} = lists:unzip(Data),
|
||||||
["INSERT INTO ", atom_to_list(Tbl), " (", sqlite3_lib:write_col_sql(Cols),
|
["INSERT INTO ", atom_to_list(Tbl), " (", sqlite3_lib:write_col_sql(Cols),
|
||||||
@@ -217,7 +217,7 @@ write_sql(Tbl, Data) ->
|
|||||||
%% matching Value.
|
%% matching Value.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(read_sql/3::(atom(), atom(), sql_value()) -> string()).
|
-spec read_sql(atom(), atom(), sql_value()) -> string().
|
||||||
read_sql(Tbl, Key, Value) ->
|
read_sql(Tbl, Key, Value) ->
|
||||||
["SELECT * FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
["SELECT * FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
||||||
" = ", value_to_sql(Value), ";"].
|
" = ", value_to_sql(Value), ";"].
|
||||||
@@ -233,7 +233,7 @@ read_sql(Tbl, Key, Value) ->
|
|||||||
%% matching Value and returns only specified columns Columns.
|
%% matching Value and returns only specified columns Columns.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec (read_sql/4::(atom (), atom (), sql_value (), [atom ()]) -> string ()).
|
-spec read_sql(atom(), atom(), sql_value(), [atom()]) -> string().
|
||||||
read_sql(Tbl, Key, Value, Columns) ->
|
read_sql(Tbl, Key, Value, Columns) ->
|
||||||
["SELECT ", sqlite3_lib:read_cols_sql(Columns), " FROM ",
|
["SELECT ", sqlite3_lib:read_cols_sql(Columns), " FROM ",
|
||||||
atom_to_list(Tbl), " WHERE ", atom_to_list(Key), " = ",
|
atom_to_list(Tbl), " WHERE ", atom_to_list(Key), " = ",
|
||||||
@@ -248,7 +248,7 @@ read_sql (Tbl, Key, Value, Columns) ->
|
|||||||
%% matching Value then deletes that record.
|
%% matching Value then deletes that record.
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(delete_sql/3::(atom(), atom(), sql_value()) -> string()).
|
-spec delete_sql(atom(), atom(), sql_value()) -> string().
|
||||||
delete_sql(Tbl, Key, Value) ->
|
delete_sql(Tbl, Key, Value) ->
|
||||||
["DELETE FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
["DELETE FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
|
||||||
" = ", value_to_sql(Value), ";"].
|
" = ", value_to_sql(Value), ";"].
|
||||||
@@ -259,7 +259,7 @@ delete_sql(Tbl, Key, Value) ->
|
|||||||
%% @doc Drop the table Tbl from the database
|
%% @doc Drop the table Tbl from the database
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec(drop_table/1::(atom()) -> string()).
|
-spec drop_table(atom()) -> string().
|
||||||
drop_table(Tbl) ->
|
drop_table(Tbl) ->
|
||||||
["DROP TABLE ", atom_to_list(Tbl), ";"].
|
["DROP TABLE ", atom_to_list(Tbl), ";"].
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user