Moved documentation for sql_value() type to correct place

This commit is contained in:
Alexey Romanov
2010-10-12 11:42:23 +04:00
parent 3f2ea22ca3
commit 7629e1f38c
3 changed files with 28 additions and 24 deletions

View File

@@ -1,10 +1,2 @@
-define(NULL_ATOM, null). -define(NULL_ATOM, null).
-type(sql_value() :: number() | ?NULL_ATOM | iodata()). -type(sql_value() :: number() | ?NULL_ATOM | iodata()).
%%--------------------------------------------------------------------
%% @type sql_value() :: number() | 'null' | iodata().
%%
%% Values accepted in SQL statements include numbers, atom 'null',
%% and iodata().
%% @end
%%--------------------------------------------------------------------

View File

@@ -605,3 +605,10 @@ build_table_info([[ColName, ColType] | Tl], Acc) ->
build_table_info([[ColName, ColType, "PRIMARY", "KEY"] | Tl], Acc) -> build_table_info([[ColName, ColType, "PRIMARY", "KEY"] | Tl], Acc) ->
build_table_info(Tl, [{list_to_atom(ColName), primary_key} | Acc]). build_table_info(Tl, [{list_to_atom(ColName), primary_key} | Acc]).
%%--------------------------------------------------------------------
%% @type sql_value() = number() | 'null' | iodata().
%%
%% Values accepted in SQL statements include numbers, atom 'null',
%% and io:iolist().
%% @end
%%--------------------------------------------------------------------

View File

@@ -49,7 +49,7 @@ col_type_to_atom("REAL") ->
double. double.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec value_to_sql_unsafe(Value :: sql_value()) -> iodata() %% @spec value_to_sql_unsafe(Value :: sql_value()) -> iolist()
%% @doc %% @doc
%% Converts an Erlang term to an SQL string. %% Converts an Erlang term to an SQL string.
%% Currently supports integers, floats, 'null' atom, and iodata %% Currently supports integers, floats, 'null' atom, and iodata
@@ -71,7 +71,7 @@ value_to_sql_unsafe(X) ->
end. end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec value_to_sql(Value :: sql_value()) -> iodata() %% @spec value_to_sql(Value :: sql_value()) -> iolist()
%% @doc %% @doc
%% Converts an Erlang term to an SQL string. %% Converts an Erlang term to an SQL string.
%% Currently supports integers, floats, 'null' atom, and iodata %% Currently supports integers, floats, 'null' atom, and iodata
@@ -118,16 +118,13 @@ write_col_sql(Cols) ->
escape(IoData) -> re:replace(IoData, "'", "''", [global]). escape(IoData) -> re:replace(IoData, "'", "''", [global]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec update_set_sql([{Col, Value}]) -> iolist() %% @spec update_set_sql([{Column :: atom(), Value :: sql_value()}]) -> iolist()
%% Col = atom()
%% Value = number() | atom() | string()
%% @doc %% @doc
%% Creates update set stmt. %% Creates update set stmt.
%% Currently supports integer, double/float and strings. %% Currently supports integer, double/float and strings.
%% For strings \" replaced with '.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec update_set_sql(any()) -> iolist(). -spec update_set_sql([{atom(), sql_value()}]) -> iolist().
update_set_sql(Data) -> update_set_sql(Data) ->
ColValueToSqlFun = ColValueToSqlFun =
fun({Col, Value}) -> fun({Col, Value}) ->
@@ -146,9 +143,9 @@ read_cols_sql(Columns) ->
map_intersperse(fun atom_to_list/1, Columns, ", "). map_intersperse(fun atom_to_list/1, Columns, ", ").
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec create_table_sql(Tbl, [{ColName, Type}]) -> iolist() %% @spec create_table_sql(Tbl :: atom(), [{Column, Type}]) -> iolist()
%% Tbl = atom() %% Tbl = atom()
%% ColName = atom() %% Column = atom()
%% Type = atom() %% Type = atom()
%% @doc Generates a table create stmt in SQL. %% @doc Generates a table create stmt in SQL.
%% First column listed is considered the primary key. %% First column listed is considered the primary key.
@@ -168,15 +165,15 @@ create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
%% @spec update_sql(Tbl, Key, Value, Data) -> iolist() %% @spec update_sql(Tbl, Key, Value, Data) -> iolist()
%% Tbl = atom() %% Tbl = atom()
%% Key = atom() %% Key = atom()
%% Value = atom() %% Value = sql_value()
%% Data = [{ColName :: atom(), Value :: string() | integer() | float()}] %% Data = [{Column :: atom(), Value :: sql_value()}]
%% @doc %% @doc
%% Using Key as the column name and Data as list of column names %% Using Key as the column name and Data as list of column names
%% and values pairs it creates the proper update SQL stmt for the %% and values pairs it creates the proper update SQL stmt for the
%% record with matching Value. %% record with matching Value.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec update_sql(atom(), atom(), atom(), [{atom(), sql_value()}]) -> iolist(). -spec update_sql(atom(), atom(), sql_value(), [{atom(), sql_value()}]) -> iolist().
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), ";"].
@@ -184,7 +181,7 @@ update_sql(Tbl, Key, Value, Data) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec write_sql(Tbl, Data) -> iolist() %% @spec write_sql(Tbl, Data) -> iolist()
%% Tbl = atom() %% Tbl = atom()
%% Data = [{ColName :: atom(), Value :: string() | integer() | float()}] %% Data = [{ColName :: atom(), Value :: sql_value()}]
%% @doc Taking Data as list of column names and values pairs it creates the %% @doc Taking Data as list of column names and values pairs it creates the
%% proper insertion SQL stmt. %% proper insertion SQL stmt.
%% @end %% @end
@@ -199,7 +196,7 @@ write_sql(Tbl, Data) ->
%% @spec read_sql(Tbl, Key, Value) -> iolist() %% @spec read_sql(Tbl, Key, Value) -> iolist()
%% Tbl = atom() %% Tbl = atom()
%% Key = atom() %% Key = atom()
%% Value = string() | integer() | float() %% Value = sql_value()
%% @doc Using Key as the column name searches for the record with %% @doc Using Key as the column name searches for the record with
%% matching Value. %% matching Value.
%% @end %% @end
@@ -213,7 +210,7 @@ read_sql(Tbl, Key, Value) ->
%% @spec read_sql(Tbl, Key, Value, Columns) -> iolist() %% @spec read_sql(Tbl, Key, Value, Columns) -> iolist()
%% Tbl = atom() %% Tbl = atom()
%% Key = atom() %% Key = atom()
%% Value = string() | integer() | float() %% Value = sql_value()
%% Columns = [atom()] %% Columns = [atom()]
%% @doc %% @doc
%% Using Key as the column name searhces for the record with %% Using Key as the column name searhces for the record with
@@ -230,7 +227,7 @@ read_sql(Tbl, Key, Value, Columns) ->
%% @spec delete_sql(Tbl, Key, Value) -> iolist() %% @spec delete_sql(Tbl, Key, Value) -> iolist()
%% Tbl = atom() %% Tbl = atom()
%% Key = atom() %% Key = atom()
%% Value = string() | integer() | float() %% Value = sql_value()
%% @doc Using Key as the column name searches for the record with %% @doc Using Key as the column name searches for the record with
%% matching Value then deletes that record. %% matching Value then deletes that record.
%% @end %% @end
@@ -260,3 +257,11 @@ drop_table(Tbl) ->
map_intersperse(_Fun, [], _Sep) -> []; map_intersperse(_Fun, [], _Sep) -> [];
map_intersperse(Fun, [Elem], _Sep) -> [Fun(Elem)]; map_intersperse(Fun, [Elem], _Sep) -> [Fun(Elem)];
map_intersperse(Fun, [Head | Tail], Sep) -> [Fun(Head), Sep | map_intersperse(Fun, Tail, Sep)]. map_intersperse(Fun, [Head | Tail], Sep) -> [Fun(Head), Sep | map_intersperse(Fun, Tail, Sep)].
%%--------------------------------------------------------------------
%% @type sql_value() = number() | 'null' | iodata().
%%
%% Values accepted in SQL statements include numbers, atom 'null',
%% and io:iolist().
%% @end
%%--------------------------------------------------------------------