从表面上看CB功能很强大。也许。。。
版本0.7.2
以前 太乐观,以为 出了riak其它支持的数据库都能随意切换,说想的美一点都不错。
我们开始开发用的是mock,测试方便,不需要创建表。
开发完了,切换到mysql上问题来了阿阿阿阿阿。
1、如果每个table名必须是复数形式 如account module必须用accounts表名(其它的测试)。
2、Id 需要设置为自动增长我采用biginit(11),如果采用其它类型 只能插入NULL
3、字段名称也需要注意不能随便用"_id"结尾否则会认为"_id"前面是表名。如send_user_id 会认为send_user是表,其实可能不是此时会出错。
4、继续说明'test_id' 此字段必须与test表的id类型一致。s
查询错误与区别
([email protected])54>
([email protected])54> boss_db:find("account-1").
* 5: syntax error before: boss_db
([email protected])54> boss_db:find("account-1").
{account,"account-1",<<"jason">>,
<<"[email protected]">>,undefined,undefined,<<"1234">>,
<<"2012-03-15 01:51:34">>,<<"jason">>,<<"13105322554">>,
undefined,undefined}
([email protected])55> boss_db:find(account,[{id,"1"}]).
[{account,"account-1",<<"jason">>,
<<"[email protected]">>,undefined,undefined,<<"1234">>,
<<"2012-03-15 01:51:34">>,<<"jason">>,<<"13105322554">>,
undefined,undefined}]
([email protected])56> boss_db:find(account,[{id,"account-1"}]).
[]
([email protected])57> boss_db:find("1").
** exception exit: {{{badmatch,["1"]},
[{boss_db_adapter_mysql,infer_type_from_id,1},
{boss_db_adapter_mysql,find,2},
{boss_db_controller,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]},
{gen_server,call,[<0.12572.0>,{find,"1"},30000]}}
in function gen_server:call/3
in call from boss_pool:call/3
([email protected])58>
=ERROR REPORT==== 15-Mar-2012::17:11:48 ===
** Generic server <0.12572.0> terminating
** Last message in was {find,"1"}
** When Server state == {state,boss_db_adapter_mysql,<0.12573.0>,[],
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[],[]}}},
false,60,db,0}
** Reason for termination ==
** {{badmatch,["1"]},
[{boss_db_adapter_mysql,infer_type_from_id,1},
{boss_db_adapter_mysql,find,2},
{boss_db_controller,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}