Created
November 21, 2014 16:42
-
-
Save skalee/63aa4d1de32fbeeb1028 to your computer and use it in GitHub Desktop.
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
table_exists(Pid, Type) -> | |
TableName = boss_record_lib:database_table(Type), | |
Res = fetch(Pid, ["SELECT 1 FROM ", TableName," LIMIT 1"]), | |
case Res of | |
{updated, _} -> | |
ok; | |
{error, MysqlRes} -> {error, mysql:get_result_reason(MysqlRes)} | |
end. |
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
table_exists(Conn, TableName) when is_atom(TableName) -> | |
Res = pgsql:squery(Conn, ["SELECT COUNT(tablename) FROM PG_TABLES WHERE SCHEMANAME='public' AND TABLENAME = '", atom_to_list(TableName), "'"]), | |
case Res of | |
{ok, _, [{Count}]} -> | |
list_to_integer(binary_to_list(Count)) > 0; | |
{error, Reason} -> | |
{error, Reason} | |
end. |
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
Searching 9 files for "database_table" in /src/db_adapters | |
/Users/skale/Projekty/Chicago/boss_db/src/db_adapters/boss_db_adapter_mysql.erl: | |
92 count(Pid, Type, Conditions) -> | |
93 ConditionClause = build_conditions(Type, Conditions), | |
94: TableName = boss_record_lib:database_table(Type), | |
95 Res = fetch(Pid, ["SELECT COUNT(*) AS count FROM ", TableName, " WHERE ", ConditionClause]), | |
96 case Res of | |
.. | |
103 | |
104 table_exists(Pid, Type) -> | |
105: TableName = boss_record_lib:database_table(Type), | |
106 Res = fetch(Pid, ["SELECT 1 FROM ", TableName," LIMIT 1"]), | |
107 case Res of | |
... | |
299 build_insert_query(Record) -> | |
300 Type = element(1, Record), | |
301: TableName = boss_record_lib:database_table(Type), | |
302 AttributeColumns = Record:database_columns(), | |
303 {Attributes, Values} = lists:foldl(fun | |
... | |
352 | |
353 build_select_query(Type, Conditions, Max, Skip, Sort, SortOrder) -> | |
354: TableName = boss_record_lib:database_table(Type), | |
355 ["SELECT * FROM ", TableName, | |
356 " WHERE ", build_conditions(Type, Conditions), | |
/Users/skale/Projekty/Chicago/boss_db/src/db_adapters/boss_db_adapter_pgsql.erl: | |
91 count(Conn, Type, Conditions) -> | |
92 ConditionClause = build_conditions(Type, Conditions), | |
93: TableName = boss_record_lib:database_table(Type), | |
94 {ok, _, [{Count}]} = pgsql:equery(Conn, | |
95 ["SELECT COUNT(*) AS count FROM ", TableName, " WHERE ", ConditionClause]), | |
.. | |
264 build_insert_query(Record) -> | |
265 Type = element(1, Record), | |
266: TableName = boss_record_lib:database_table(Type), | |
267 | |
268 {Attributes, Values} = make_insert_attributes(Record, Type), | |
... | |
342 | |
343 build_select_query(Type, Conditions, Max, Skip, Sort, SortOrder) -> | |
344: TableName = boss_record_lib:database_table(Type), | |
345 ["SELECT * FROM ", TableName, | |
346 " WHERE ", build_conditions(Type, Conditions), | |
7 matches across 2 files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment