Formatting fixed

This commit is contained in:
Alexey Romanov
2010-10-12 10:08:52 +04:00
parent 0669e26175
commit cb2f1c9121
2 changed files with 100 additions and 99 deletions

View File

@@ -53,8 +53,9 @@
%% To open multiple dbases on the same node use open/1 or open/2.
%% @end
%%--------------------------------------------------------------------
-type(result() :: {'ok', pid()} | 'ignore' | {'error', any()}).
-spec(start_link/1::(atom()) -> result()).
-type result() :: {'ok', pid()} | 'ignore' | {'error', any()}.
-spec start_link(atom()) -> result().
start_link(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.
%% @end
%%--------------------------------------------------------------------
-spec(start_link/2::(atom(), [{atom(), any()}]) -> result()).
-spec start_link(atom(), [{atom(), any()}]) -> result().
start_link(Db, Options) ->
Opts = case proplists:get_value(db, Options) of
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
@@ -92,7 +93,7 @@ start_link(Db, Options) ->
%% and drop_table/2.
%% @end
%%--------------------------------------------------------------------
-spec(open/1::(atom()) -> result()).
-spec open(atom()) -> result().
open(Db) ->
?MODULE:open(Db, [{db, "./" ++ atom_to_list(Db) ++ ".db"}]).
@@ -108,7 +109,7 @@ open(Db) ->
%% and drop_table/2.
%% @end
%%--------------------------------------------------------------------
-spec(open/2::(atom(), [{atom(), any()}]) -> result()).
-spec open(atom(), [{atom(), any()}]) -> result().
open(Db, Options) ->
gen_server:start_link({local, Db}, ?MODULE, Options, []).
@@ -118,7 +119,7 @@ open(Db, Options) ->
%% Closes the Db sqlite3 dbase.
%% @end
%%--------------------------------------------------------------------
-spec(close/1::(atom()) -> 'ok').
-spec close(atom()) -> 'ok'.
close(Db) ->
gen_server:call(Db, close).
@@ -128,7 +129,7 @@ close(Db) ->
%% Closes the sqlite3 dbase.
%% @end
%%--------------------------------------------------------------------
-spec(stop/0::() -> 'ok').
-spec stop() -> 'ok'.
stop() ->
?MODULE:close(?MODULE).
@@ -138,7 +139,7 @@ stop() ->
%% Executes the Sql statement directly.
%% @end
%%--------------------------------------------------------------------
-spec(sql_exec/1::(string()) -> any()).
-spec sql_exec(string()) -> any().
sql_exec(SQL) ->
?MODULE:sql_exec(?MODULE, SQL).
@@ -149,7 +150,7 @@ sql_exec(SQL) ->
%% result of the Sql call.
%% @end
%%--------------------------------------------------------------------
-spec(sql_exec/2::(atom(), string()) -> any()).
-spec sql_exec(atom(), string()) -> any().
sql_exec(Db, SQL) ->
gen_server:call(Db, {sql_exec, SQL}).
@@ -163,7 +164,7 @@ sql_exec(Db, SQL) ->
%% Returns the result of the create table call.
%% @end
%%--------------------------------------------------------------------
-spec(create_table/2::(atom(), [tuple()]) -> any()).
-spec create_table(atom(), [tuple()]) -> any().
create_table(Tbl, Options) ->
?MODULE:create_table(?MODULE, Tbl, Options).
@@ -177,7 +178,7 @@ create_table(Tbl, Options) ->
%% Returns the result of the create table call.
%% @end
%%--------------------------------------------------------------------
-spec(create_table/3::(atom(), atom(), [{atom(), any()}]) -> any()).
-spec create_table(atom(), atom(), [{atom(), any()}]) -> any().
create_table(Db, Tbl, Options) ->
gen_server:call(Db, {create_table, Tbl, Options}).
@@ -187,7 +188,7 @@ create_table(Db, Tbl, Options) ->
%% Returns a list of tables.
%% @end
%%--------------------------------------------------------------------
-spec(list_tables/0::() -> [atom()]).
-spec list_tables() -> [atom()].
list_tables() ->
?MODULE:list_tables(?MODULE).
@@ -197,7 +198,7 @@ list_tables() ->
%% Returns a list of tables for Db.
%% @end
%%--------------------------------------------------------------------
-spec(list_tables/1::(atom()) -> [atom()]).
-spec list_tables(atom()) -> [atom()].
list_tables(Db) ->
gen_server:call(Db, list_tables).
@@ -207,7 +208,7 @@ list_tables(Db) ->
%% Returns table schema for Tbl.
%% @end
%%--------------------------------------------------------------------
-spec(table_info/1::(atom()) -> [any()]).
-spec table_info(atom()) -> [any()].
table_info(Tbl) ->
?MODULE:table_info(?MODULE, Tbl).
@@ -217,7 +218,7 @@ table_info(Tbl) ->
%% Returns table schema for Tbl in Db.
%% @end
%%--------------------------------------------------------------------
-spec(table_info/2::(atom(), atom()) -> [any()]).
-spec table_info(atom(), atom()) -> [any()].
table_info(Db, Tbl) ->
gen_server:call(Db, {table_info, Tbl}).
@@ -229,7 +230,7 @@ table_info(Db, Tbl) ->
%% determined from table_info/2.
%% @end
%%--------------------------------------------------------------------
-spec(write/2::(atom(), [{atom(), any()}]) -> any()).
-spec write(atom(), [{atom(), any()}]) -> any().
write(Tbl, Data) ->
?MODULE:write(?MODULE, Tbl, Data).
@@ -241,7 +242,7 @@ write(Tbl, Data) ->
%% same type as determined from table_info/3.
%% @end
%%--------------------------------------------------------------------
-spec(write/3::(atom(), atom(), [{atom(), any()}]) -> any()).
-spec write(atom(), atom(), [{atom(), any()}]) -> any().
write(Db, 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.
%% @end
%%--------------------------------------------------------------------
-spec(read/2::(atom(), {atom(), any()}) -> any()).
-spec read(atom(), {atom(), any()}) -> any().
read(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.
%% @end
%%--------------------------------------------------------------------
-spec(read/3::(atom(), atom(), {atom(), any()}) -> any()).
-spec read(atom(), atom(), {atom(), any()}) -> any().
read(Db, 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.
%% @end
%%--------------------------------------------------------------------
-spec(delete/2::(atom(), {atom(), any()}) -> any()).
-spec delete(atom(), {atom(), any()}) -> any().
delete(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.
%% @end
%%--------------------------------------------------------------------
-spec(delete/3::(atom(), atom(), {atom(), any()}) -> any()).
-spec delete(atom(), atom(), {atom(), any()}) -> any().
delete(Db, Tbl, Key) ->
gen_server:call(Db, {delete, Tbl, Key}).
@@ -349,7 +350,7 @@ delete(Db, Tbl, Key) ->
%% Drop the table Tbl.
%% @end
%%--------------------------------------------------------------------
-spec(drop_table/1::(atom()) -> any()).
-spec drop_table(atom()) -> any().
drop_table(Tbl) ->
?MODULE:drop_table(?MODULE, Tbl).
@@ -359,7 +360,7 @@ drop_table(Tbl) ->
%% Drop the table Tbl from Db dbase.
%% @end
%%--------------------------------------------------------------------
-spec(drop_table/2::(atom(), atom()) -> any()).
-spec drop_table(atom(), atom()) -> any().
drop_table(Db, Tbl) ->
gen_server:call(Db, {drop_table, Tbl}).
@@ -371,7 +372,7 @@ drop_table(Db, Tbl) ->
%%
%% @end
%%--------------------------------------------------------------------
-spec(create_function/3::(atom(), atom(), function()) -> any()).
-spec create_function(atom(), atom(), function()) -> any().
create_function(Db, 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.
%% @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).
%%--------------------------------------------------------------------
@@ -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.
%% @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).
%%====================================================================
@@ -421,8 +422,8 @@ value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
%% @end
%% @hidden
%%--------------------------------------------------------------------
-type(init_return() :: {'ok', tuple()} | {'ok', tuple(), integer()} | 'ignore' | {'stop', any()}).
-spec(init/1::([any()]) -> init_return()).
-type init_return() :: {'ok', tuple()} | {'ok', tuple(), integer()} | 'ignore' | {'stop', any()}.
-spec init([any()]) -> init_return().
init(Options) ->
Dbase = proplists:get_value(db, Options),
{?MODULE, _, FileName} = code:get_object_code(?MODULE),
@@ -447,10 +448,10 @@ init(Options) ->
%% @end
%% @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()} |
{stop, any(), any(), tuple()} | {stop, any(), tuple()}).
-spec(handle_call/3::(any(), pid(), tuple()) -> handle_call_return()).
{stop, any(), any(), tuple()} | {stop, any(), tuple()}.
-spec handle_call(any(), pid(), tuple()) -> handle_call_return().
handle_call(close, _From, State) ->
Reply = ok,
{stop, normal, Reply, State};
@@ -514,9 +515,9 @@ handle_call(_Request, _From, State) ->
%% @end
%% @hidden
%%--------------------------------------------------------------------
-type(handle_cast_return() :: {noreply, tuple()} | {noreply, tuple(), integer()} |
{stop, any(), tuple()}).
-spec(handle_cast/2::(any(), tuple()) -> handle_cast_return()).
-type handle_cast_return() :: {noreply, tuple()} | {noreply, tuple(), integer()} |
{stop, any(), tuple()}.
-spec handle_cast(any(), tuple()) -> handle_cast_return().
handle_cast(_Msg, State) ->
{noreply, State}.
@@ -528,7 +529,7 @@ handle_cast(_Msg, State) ->
%% @end
%% @hidden
%%--------------------------------------------------------------------
-spec(handle_info/2::(any(), tuple()) -> handle_cast_return()).
-spec handle_info(any(), tuple()) -> handle_cast_return().
handle_info(_Info, State) ->
{noreply, State}.
@@ -541,7 +542,7 @@ handle_info(_Info, State) ->
%% @end
%% @hidden
%%--------------------------------------------------------------------
-spec(terminate/2::(atom(), tuple()) -> atom()).
-spec terminate(atom(), tuple()) -> atom().
terminate(normal, #state{port = Port}) ->
port_command(Port, term_to_binary({close, nop})),
port_close(Port),

View File

@@ -25,7 +25,7 @@
%% @doc Maps sqlite3 column type.
%% @end
%%--------------------------------------------------------------------
-spec(col_type_to_string/1::(atom()) -> string()).
-spec col_type_to_string(atom()) -> string().
col_type_to_string(integer) ->
"INTEGER";
col_type_to_string(text) ->
@@ -40,7 +40,7 @@ col_type_to_string(real) ->
%% @doc Maps sqlite3 column type.
%% @end
%%--------------------------------------------------------------------
-spec(col_type_to_atom/1::(string()) -> atom()).
-spec col_type_to_atom(string()) -> atom().
col_type_to_atom("INTEGER") ->
integer;
col_type_to_atom("TEXT") ->
@@ -61,7 +61,7 @@ col_type_to_atom("REAL") ->
%% single quotes (e.g. can be entered by users).
%% @end
%%--------------------------------------------------------------------
-spec(value_to_sql_unsafe/1::(sql_value()) -> iodata()).
-spec value_to_sql_unsafe(sql_value()) -> iodata().
value_to_sql_unsafe(X) ->
if
is_integer(X) -> integer_to_list(X);
@@ -80,7 +80,7 @@ value_to_sql_unsafe(X) ->
%% All single quotes (') will be replaced with ''.
%% @end
%%--------------------------------------------------------------------
-spec(value_to_sql/1::(sql_value()) -> iolist()).
-spec value_to_sql(sql_value()) -> iolist().
value_to_sql(X) ->
if
is_integer(X) -> integer_to_list(X);
@@ -95,7 +95,7 @@ value_to_sql(X) ->
%% Creates the values portion of the sql stmt.
%% @end
%%--------------------------------------------------------------------
-spec(write_value_sql/1::(any()) -> string()).
-spec write_value_sql(any()) -> string().
write_value_sql(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.
%% @end
%%--------------------------------------------------------------------
-spec(write_col_sql/1::([atom()]) -> string()).
-spec write_col_sql([atom()]) -> string().
write_col_sql(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 '
%% @end
%%--------------------------------------------------------------------
-spec (replace/1::(string ()) -> string ()).
-spec replace(string()) -> string().
replace([]) -> [];
replace([$" | T]) ->
[$' | replace(T)];
@@ -127,7 +127,7 @@ replace([H | T]) ->
%% @doc Returns copy of IoData with all ' replaced by ''
%% @end
%%--------------------------------------------------------------------
-spec(escape/1::(iodata()) -> iodata()).
-spec escape(iodata()) -> iodata().
escape(IoData) -> re:replace(IoData, "'", "''", [global]).
%%--------------------------------------------------------------------
@@ -140,7 +140,7 @@ escape(IoData) -> re:replace(IoData, "'", "''", [global]).
%% For strings \" replaced with '.
%% @end
%%--------------------------------------------------------------------
-spec (update_set_sql/1::(any ()) -> string ()).
-spec update_set_sql(any()) -> string().
update_set_sql(Data) ->
ColValueToSqlFun =
fun({Col, Value}) ->
@@ -154,7 +154,7 @@ update_set_sql (Data) ->
%% Creates list of columns for select stmt.
%% @end
%%--------------------------------------------------------------------
-spec (read_cols_sql/1::([atom ()]) -> string ()).
-spec read_cols_sql([atom()]) -> string().
read_cols_sql(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.
%% @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]) ->
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
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.
%% @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 ", atom_to_list(Tbl), " SET ", update_set_sql(Data),
" WHERE ", atom_to_list(Key), " = ", value_to_sql(Value), ";"].
@@ -202,7 +202,7 @@ update_sql (Tbl, Key, Value, Data) ->
%% proper insertion SQL stmt.
%% @end
%%--------------------------------------------------------------------
-spec(write_sql/2::(atom(), [{atom(), sql_value()}]) -> string()).
-spec write_sql(atom(), [{atom(), sql_value()}]) -> string().
write_sql(Tbl, Data) ->
{Cols, Values} = lists:unzip(Data),
["INSERT INTO ", atom_to_list(Tbl), " (", sqlite3_lib:write_col_sql(Cols),
@@ -217,7 +217,7 @@ write_sql(Tbl, Data) ->
%% matching Value.
%% @end
%%--------------------------------------------------------------------
-spec(read_sql/3::(atom(), atom(), sql_value()) -> string()).
-spec read_sql(atom(), atom(), sql_value()) -> string().
read_sql(Tbl, Key, Value) ->
["SELECT * FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
" = ", value_to_sql(Value), ";"].
@@ -233,7 +233,7 @@ read_sql(Tbl, Key, Value) ->
%% matching Value and returns only specified columns Columns.
%% @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) ->
["SELECT ", sqlite3_lib:read_cols_sql(Columns), " FROM ",
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.
%% @end
%%--------------------------------------------------------------------
-spec(delete_sql/3::(atom(), atom(), sql_value()) -> string()).
-spec delete_sql(atom(), atom(), sql_value()) -> string().
delete_sql(Tbl, Key, Value) ->
["DELETE FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
" = ", value_to_sql(Value), ";"].
@@ -259,7 +259,7 @@ delete_sql(Tbl, Key, Value) ->
%% @doc Drop the table Tbl from the database
%% @end
%%--------------------------------------------------------------------
-spec(drop_table/1::(atom()) -> string()).
-spec drop_table(atom()) -> string().
drop_table(Tbl) ->
["DROP TABLE ", atom_to_list(Tbl), ";"].