Code Monkey home page Code Monkey logo

boss_db's People

Contributors

brigadier avatar burbas avatar choptastic avatar cnaize avatar cstar avatar danikp avatar davidw avatar dcy avatar diamondlovesyou avatar drobakowski avatar evanmiller avatar fdevibe avatar franko-franicevich avatar fxmy avatar graeme-defty avatar gwitmond avatar jgordor avatar kostochkin avatar lucas-entronic avatar ngaranko avatar okeuday avatar qbkira avatar rambocoder avatar rtsisyk avatar runejuhl avatar solleks avatar stevepm avatar t0fik avatar vinicius73 avatar zkessin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

boss_db's Issues

last commit break compilation

i revert at previous it compile fine, but with latest version of boss_db i have this error with cb_admin app

ERROR: boss failed while processing /home/mihawk/prj/draw/apps/cb_admin: {'EXIT',
{function_clause,
[{lists,reverse,
[{badarg,
[{dict,fetch,
['RECORDS_PER_PAGE',
{dict,2,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],
[['FILE',
{string,1,
"/home/mihawk/prj/draw/apps/cb_admin/src/controller/cb_admin_model_controller.erl"}],
['MACHINE',{atom,1,'BEAM'}]],
[],[],[],[],[],[],[],[],[],[]}}}],
[{file,"dict.erl"},{line,126}]},
{aleppo,process_tree,3,
[{file,"src/aleppo.erl"},{line,102}]},
{aleppo,process_tree,2,[{file,"src/aleppo.erl"},{line,58}]},
{boss_compiler,parse_text,4,
[{file,"src/boss_compiler.erl"},{line,91}]},
{boss_compiler,compile,2,
[{file,"src/boss_compiler.erl"},{line,11}]},
{boss_load,compile_and_accumulate_errors,5,
[{file,"src/boss/boss_load.erl"},{line,146}]},
{boss_load,load_dir,4,
[{file,"src/boss/boss_load.erl"},{line,121}]},
{boss_load,load_dirs1,6,
[{file,"src/boss/boss_load.erl"},{line,106}]}]}],
[{file,"lists.erl"},{line,145}]},
{aleppo,process_tree,2,[{file,"src/aleppo.erl"},{line,62}]},
{boss_compiler,parse_text,4,
[{file,"src/boss_compiler.erl"},{line,91}]},
{boss_compiler,compile,2,[{file,"src/boss_compiler.erl"},{line,11}]},
{boss_load,compile_and_accumulate_errors,5,
[{file,"src/boss/boss_load.erl"},{line,146}]},
{boss_load,load_dir,4,[{file,"src/boss/boss_load.erl"},{line,121}]},
{boss_load,load_dirs1,6,[{file,"src/boss/boss_load.erl"},{line,106}]},
{boss_load,load_all_modules,3,
[{file,"src/boss/boss_load.erl"},{line,29}]}]}}
ERROR: Command [compile] failed!
make: *** [app] Error 1

Type discrepancy with Postgres and Datetimes

NewRecord = boss_record:new(patient, [{name, "Aaa"}, {birth_date, "1980-10-11"}]).
{patient,id,"Aaa","1980-10-11",undefined,undefined}
([email protected])3> NewRecord:save().
{ok,{patient,"patient-21","Aaa","1980-10-11",undefined,
         undefined}}
([email protected])4> ProcessedRecord = boss_db:find("patient-21").
{patient,"patient-21",<<"Aaa">>,
     {{1980,10,11},{0,0,0.0}},
     undefined,undefined}

What I get from save() and find() differs... This causes problems elsewhere.

Query

I use mongoDB.
How to query non-static keys(key-value pairs) and keys from nested levels ?

{
    "static1": "",
    "static2": "",
    "key1": "",
    "key2": "",
    ...
    "key9": "",

    "modules":{
        "static1": "",
        "static2": "",
        "key1": "",
        "key2": "",
    }
}


/admin/model/model/{{model}} throws function_clause exception exit

When a model is selected in the admin menu, a 500 error is raised. The full traceback from the shell is below for /admin/model/model/topic.

=ERROR REPORT==== 20-Aug-2012::17:41:35 ===
** Generic server <0.347.0> terminating 
** Last message in was {find,topic,[],
                             [{limit,100},{offset,0},descending],
                             0,id,str_ascending}
** When Server state == {state,boss_db_adapter_mnesia,undefined,[],
                               {dict,0,16,16,8,80,48,
                                     {[],[],[],[],[],[],[],[],[],[],[],[],[],
                                      [],[],[]},
                                     {{[],[],[],[],[],[],[],[],[],[],[],[],[],
                                       [],[],[]}}},
                               false,60,db,0}
** Reason for termination == 
** {function_clause,
       [{boss_db_adapter_mnesia,find,
            [undefined,topic,[],
             [{limit,100},{offset,0},descending],
             0,id,str_ascending],
            [{file,"src/db_adapters/boss_db_adapter_mnesia.erl"},{line,44}]},
        {boss_db_controller,handle_call,3,
            [{file,"src/boss_db_controller.erl"},{line,83}]},
        {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,588}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}

=CRASH REPORT==== 20-Aug-2012::17:41:35 ===
  crasher:
    initial call: boss_db_controller:init/1
    pid: <0.347.0>
    registered_name: []
    exception exit: {function_clause,
                        [{boss_db_adapter_mnesia,find,
                             [undefined,topic,[],
                              [{limit,100},{offset,0},descending],
                              0,id,str_ascending],
                             [{file,
                                  "src/db_adapters/boss_db_adapter_mnesia.erl"}, 
                              {line,44}]},
                         {boss_db_controller,handle_call,3,
                             [{file,"src/boss_db_controller.erl"},{line,83}]},
                         {gen_server,handle_msg,5,
                             [{file,"gen_server.erl"},{line,588}]},
                         {proc_lib,init_p_do_apply,3,
                             [{file,"proc_lib.erl"},{line,227}]}]}
      in function  gen_server:terminate/6 (gen_server.erl, line 747)
    ancestors: [<0.121.0>,boss_db_pool,boss_db_sup,boss_web,boss_sup,
                  <0.64.0>]
    messages: []
    links: [<0.121.0>,<0.120.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 987
    stack_size: 24
    reductions: 2250
  neighbours:

=SUPERVISOR REPORT==== 20-Aug-2012::17:41:35 ===
     Supervisor: {<0.121.0>,poolboy_sup}
     Context:    child_terminated
     Reason:     {function_clause,
                     [{boss_db_adapter_mnesia,find,
                          [undefined,topic,[],
                           [{limit,100},{offset,0},descending],
                           0,id,str_ascending],
                          [{file,"src/db_adapters/boss_db_adapter_mnesia.erl"},
                           {line,44}]},
                      {boss_db_controller,handle_call,3,
                          [{file,"src/boss_db_controller.erl"},{line,83}]},
                      {gen_server,handle_msg,5,
                          [{file,"gen_server.erl"},{line,588}]},
                      {proc_lib,init_p_do_apply,3,
                          [{file,"proc_lib.erl"},{line,227}]}]}
     Offender:   [{pid,<0.347.0>},
                  {name,boss_db_controller},
                  {mfargs,{boss_db_controller,start_link,undefined}},
                  {restart_type,temporary},
                  {shutdown,brutal_kill},
                  {child_type,worker}]


=ERROR REPORT==== 20-Aug-2012::17:41:35 ===
{{function_clause,
     [{boss_db_adapter_mnesia,find,
          [undefined,topic,[],
           [{limit,100},{offset,0},descending],
           0,id,str_ascending],
          [{file,"src/db_adapters/boss_db_adapter_mnesia.erl"},{line,44}]},
      {boss_db_controller,handle_call,3,
          [{file,"src/boss_db_controller.erl"},{line,83}]},
      {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,588}]},
      {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]},
 {gen_server,call,
     [<0.347.0>,
      {find,topic,[],[{limit,100},{offset,0},descending],0,id,str_ascending},
      30000]}}

Override conventions on table and primary key names

Hi,

Is it possible to override the convention where the name of the table must be plural and the primary key must be "id"? Other traditional ORMs offer this, and it's useful for dealing with DB schemas you can't change.

Derek.

Using datetime() type for ErlyDTL with mongodb

I use ::datetime() type for ErlyDTL - but mongo driver have't translate from timestamp()

I add string to boss_record_lib.erl :
convert_value_to_type({D1, D2, D3} = Val, datetime) when is_integer(D1), is_integer(D2), is_integer(D3) ->
calendar:now_to_datetime(Val);


{{,,},{,,}} = boss_record_lib:convert_value_to_type(now(), datetime).

MySQL Driver apply/3 error

I'm experiencing an issue that seems to only occurfor MySQL databases. If I create a new table like so:

CREATE TABLE demos (
id INT PRIMARY KEY AUTO_INCREMENT,
parent_id INT,
name VARCHAR(255),
updated_at DATETIME,
created_at DATETIME
);
insert into demos (parent_id, name, updated_at, created_at) values (1, "Something", NOW(), NOW());
insert into demos (parent_id, name, updated_at, created_at) values (1, "Something Else", NOW(), NOW());
insert into demos (parent_id, name, updated_at, created_at) values (1, "Something Other", NOW(), NOW());

Then create the model src/model/demo.erl in a fresh Boss project (0.8.0):

-module(demo, [Id, ParentId, Name, CreatedAt, UpdatedAt]).
-compile(export_all).

And run init-dev.sh at the prompt:

(test@Jonathan-jeffuss-iMac)1> D = boss_db:find(demo, [{id, equals, 1}]).
[{demo,"demo-1","parent-1",<<"Something">>,
       {{2012,8,28},{18,2,12}},
       {{2012,8,28},{18,2,12}}}]
(test@Jonathan-jeffuss-iMac)4> D:id().  
** exception error: bad argument
     in function  apply/3
        called as apply([{demo,"demo-1","parent-1",<<"Something">>,
                               {{2012,8,28},{18,2,12}},
                               {{2012,8,28},{18,2,12}}}],
                        id,[])
(test@Jonathan-jeffuss-iMac)5> D:name().
** exception error: bad argument
     in function  apply/3
        called as apply([{demo,"demo-1","parent-1",<<"Something">>,
                               {{2012,8,28},{18,2,12}},
                               {{2012,8,28},{18,2,12}}}],
                        name,[])

Other databases seem to work OK. It's the magical functions that seem to be broken, including set(). Here's my boss.config:

[{boss, [
    {path, "/Users/jjeffus/dev/ChicagoBoss-0.8.0"},
    {applications, [test]},
    {db_host, "localhost"},
    {db_port, 3306},
    {db_database, "demo"},
    {db_username, "root"},
    {db_password, ""},
    {db_adapter, mysql},
    {log_dir, "log"},
    {server, mochiweb},
    {port, 8001},
    {session_adapter, mock},
    {session_key, "_boss_session"},
    {session_exp_time, 525600}
]},
{ test, [
    {path, "../test"},
    {base_url, "/"}
]}
].

Argument order for proplists:get_value

I noticed a problem with two calls to proplists:get_value in boss_record_compiler.erl after the recent merge with "sql-use-full-id". Shouldn't the keys "columns" and "table" be the first arguments to those calls?

Timestamps with floats are truncated upon save.

With pgsql, the "seconds" part of a timestamp is a float, ie. {{2012,8,6},{14,21,34.277014}}. When fetching a record using boss_db and resaving it, the float part of the timestamp is truncated.

28> Post2 = boss_db:find("post-2").   
{post,"post-2",<<"d39848df-894a-419d-808b-36df42ca27e9">>,
      "muser-1",<<"f75e4cf9-0e7e-4ce2-9596-fbe297113d06">>,
      {{2012,8,6},{14,21,34.279783}},
      true}
30> Post2U = Post2:set(active, false).
{post,"post-2",<<"d39848df-894a-419d-808b-36df42ca27e9">>,
      "muser-1",<<"f75e4cf9-0e7e-4ce2-9596-fbe297113d06">>,
      {{2012,8,6},{14,21,34.279783}},
      false}
31> Post2U:save().                    
{ok,{post,"post-2",
          <<"d39848df-894a-419d-808b-36df42ca27e9">>,"muser-1",
          <<"f75e4cf9-0e7e-4ce2-9596-fbe297113d06">>,"category-1",
          {{2012,8,6},{14,21,34.279783}},
          false}}
32> boss_db:find("post-2").              
{post,"post-2",<<"d39848df-894a-419d-808b-36df42ca27e9">>,
      "muser-1",<<"f75e4cf9-0e7e-4ce2-9596-fbe297113d06">>,
      {{2012,8,6},{14,21,34.0}},
      false}
33> boss_db:execute("SELECT * FROM posts WHERE id = 2").
{ok,[{column,<<"id">>,int4,4,-1,0},
     {column,<<"uuid">>,{unknown_oid,2950},16,-1,0},
     {column,<<"muser_id">>,int4,4,-1,0},
     {column,<<"revision_prev">>,{unknown_oid,2950},16,-1,0},
     {column,<<"category_id">>,int4,4,-1,0},
     {column,<<"timestamp">>,timestamp,8,-1,0},
     {column,<<"active">>,bool,1,-1,0}],
    [{<<"2">>,<<"d39848df-894a-419d-808b-36df42ca27e9">>,
      <<"1">>,<<"f75e4cf9-0e7e-4ce2-9596-fbe297113d06">>,<<"1">>,
      <<"2012-08-06 14:21:34">>,<<"f">>}]}

Several errors on associations with graph-like models

Let's create two simple models. One model will store users:

-module(person, [Id, Name]).
-compile(export_all).

%% User-to-user relations stored in second model (person_relation)
-has({relations_in, many, [
        {module,        person_relation},
        {foreign_key,   to_person_id},
        {order_by,      from_person_id},
        {descending,    true}
    ]}).

-has({relations_out, many, [
        {module,        person_relation},
        {foreign_key,   from_person_id},
        {order_by,      to_person_id},
        {descending,    true}
    ]}).

Second model is used to store relations between people:

-module(person_relation, [Id, FromPersonId, ToPersonId]).
-compile(export_all).

-belongs_to_person(from_person).
-belongs_to_person(to_person).

Let's try to use these models. Assume, that person model already have person-1 and person-2:

> PR = person_relation:new(id, "person-1", "person-2").
{person_relation, id, "person-1", "person-2"}

> PR:save().
{ok, {person_relation, "person_relation-1", "person-1", "person-2"}}

> boss_db:find(person_relation, []).
[{person_relation, "person_relation-1", "from_person-1", "to_person-2"}].

First bug: boss_db:find returns unexpected values in from_person_id and to_person_id attrs. In other words, these values are useless. Should be "person-1" and "person-2" as I saved earlier.


Lets find something in relations:

> boss_db:find(person_relation, [{from_person_id, equals, "person-1"}]).
{error,{error,error,<<"22P02">>,
              <<"invalid input syntax for integer: \"person-1\"">>,
              [{position,<<"52">>}]}}

> boss_db:find(person_relation, [{to_person_id, equals, "to_person-1"}]).
{error,{error,error,<<"22P02">>,
              <<"invalid input syntax for integer: \"to_person-1\"">>,
              [{position,<<"52">>}]}}

In PostgreSQL logs this strings:

ERROR:  invalid input syntax for integer: "person-1" at character 52
STATEMENT:  SELECT * FROM people_relation WHERE to_person_id = 'person-1' AND  TRUE ORDER BY id ASC

ERROR:  invalid input syntax for integer: "to_person-1" at character 52
STATEMENT:  SELECT * FROM people_relation WHERE to_person_id = 'to_person-1' AND  TRUE ORDER BY id ASC

So, this is a second bug.

erlydtl rebar dependency

PostgreSQL and MySQL adapters use erlydtl_filters:date but erlydtl dependency not present in rebar.config

Boss_news

Hi,

In the Usage section of the README file you say that:

boss_news:start() % If you want events

As if starting boss_news was optional. But It seems to be mandatory because after saving a record boss_record_lib:run_after_hooks is called which calls boss_news:update.

I didn't have boss_news gen_server running so I got an error. This one:

error,
     {exit,
         {noproc,
             {gen_server,call,
                 [{global,boss_news},
                  {created,"device_user-0",
                      [{id,"device_user-0"},{email,[]},{password,[]}]}]}},
         [{gen_server,call,2,[{file,"gen_server.erl"},{line,180}]},
          {boss_record_lib,run_after_hooks,3,
              [{file,"src/boss_record_lib.erl"},{line,20}]},
          {boss_db,save_record,1,[{file,"src/boss_db.erl"},{line,227}]},

Please change the README file so it makes clear that boss_news must be running or make it optional.

boss_compiler missing export with R15B02/R15B03

I have a strength issue with an erlang R15B02/R15B03 on my machine:

If I compile a models, I get only this functions exported:
before_create/1 before_update/1 instance/5 module_info/0 module_info/1 new/5

I have added a -compile([export_all]) directive, and it works.
Debugging of a boss_compiler:compile_forms/3 shows, that in a form code, that are comming to this function, doesn't exists a {attribute, {X,Y},export, [{Func, Arity}]} for all generated functions.
Simply adding of -compile([export_all]) can temporary fix a problem.

Have anybody same issue with boss_db with a R15B02/R15B03?

boss_db does not support binaries

If the underlying adapter for a database uses binaries, it would be helpful if we could do boss_db:find(<<"keyname">>) instead of db:find("keyname").

Are there any plans to support binaries in boss_db interface?

A release of an application that depends on boss_db can break on boss_db dependencies

I have had problems building a release with a normal rebar generate using the latest tagged version of rebar. I was able to use a simple release script which goes through the same rebar generate process which created a release without any problems. This might require further attention or usage of the release script. It seems like rebar dislikes creating a release for application dependencies it has not built. The release script is here https://github.com/okeuday/reltool_util/blob/master/release

abstract code missing from boss record modules compiled with the boss_record_compiler

I am not sure if this was already reported, but I see it as a major problem because it breaks dialyzer and cover. Using the debug_info compile option with boss_record_compiler does not add the abstract code since the compilation is from forms. It seems like this requires modifying boss_compiler.erl and the forms it produces. Not quite sure how to do that.

boss_db can not sort on more than one criteria

The current implementation of boss_db allows only a single sort criteria.

That's a major limitation to use boss_db.

It would be great to have the ability to sort like this:

[{order_by,
      [{firstname, [{direction, ascending}]},
       {lastname, [{direction, descending}]},
       {uid, unique}]}]

Rules for IDs

  1. Are there any rules saying what characters are allowed in an id? We have stumbled upon problems when using "-" or "." characters in ids (the "." character causes problems with boss_news).

  2. Is it recommended to use automatically generated ids? or is it idiomatic in boss_db to use ids we created on our own? (i.e. model:new("some_id_we_created", Field1Value, Field2Value)).

@nivertech

Infinite loop on start-up with sharding enabled

The sharding init API seems to have changed but the database adapters don't seem to have been updated to reflect this yet. This fix can workaround the problem until the db adapters are updated. Tested on postgres 9.1

Thanks,

James

--- a/src/boss_db_controller.erl
+++ b/src/boss_db_controller.erl
@@ -243,7 +243,12 @@ handle_cast({try_connect, Options}, State) when State#state.connection_state /=
                                undefined -> ShardOptions ++ proplists:delete(db_replication_set, Options);
                                _ -> ShardOptions ++ Options
                                end,
-                       {ok, {ShardRead, ShardWrite}} = ShardAdapter:init(MergedOptions),
+                       case ShardAdapter:init(MergedOptions) of
+                       {ok, {ShardRead, ShardWrite}} -> 
+                           noop;
+                       {ok, Conn} ->
+                           [ShardRead, ShardWrite] = [Conn, Conn]
+                       end,
                        Index = erlang:length(ShardAcc),
                        NewDict = lists:foldr(fun(ModelAtom, Dict) ->
                                      dict:store(ModelAtom, Index, Dict)

Return values for boss_db:execute

By my reading of the code, boss_db:execute simple returns whatever it gets from the database handler in question. While it's good to have that information, it'd also be nice to have something higher level to match on: was this db call successful?

Tests don't run for Postgres

I created the boss_test database as per the config files, and ran the make line to run those tests. It just sat there. So I tried running things by hand:

2> boss_db_test:start().
{error,{"no such file or directory","boss_db_test.app"}}

Not sure how to get it to create an .app file, seeing as how there's already one there, for boss_db itself.

MongoDB: Four tuple 'matches' failure

boss_db:find(forum, [{description, 'matches', "cloud", ["i"]}]). 
** exception error: no function clause matching boss_db:normalize_conditions([{description,matches,"cloud",["i"]}],[]) (src/boss_db.erl, line 393)
     in function  boss_db:find/3 (src/boss_db.erl, line 136)

{error,invalid_id} retriving model associations only on production mode - code:is_loaded problem

Hi Evan,

I'm getting crazy debugging this problem, I'm facing intermitent exceptions retrieving model associations (belongs_to, and has) => {error,invalid_id} only on production mode.

I found that the problem is in boss_sql_lib:is_foreign_key(Key), code:is_loaded(list_to_atom(Module)) is returning false:
Code:

is_foreign_key(Key) when is_atom(Key) ->
    KeyTokens = string:tokens(atom_to_list(Key), "_"),
    LastToken = hd(lists:reverse(KeyTokens)),
        error_logger:info_msg("is_foreign_key(~p) -> LastToken=~p", [Key, LastToken]),
    case (length(KeyTokens) > 1 andalso LastToken == "id") of
        true -> 
            Module = join(lists:reverse(tl(lists:reverse(KeyTokens))), "_"),
                        error_logger:info_msg("is_foreign_key(~p) -> Module=~p", [Key, Module]),
                    case code:is_loaded(list_to_atom(Module)) of
                   {file, _Loaded} -> true;
                   false -> false
                     end;
        false -> false
    end;

Res:

=ERROR REPORT==== 25-Jan-2013::16:52:21 ===
activate_record - Type=ma_user Key=ma_center_id foreig?=false
=INFO REPORT==== 25-Jan-2013::16:52:21 ===
is_foreign_key(ma_center_id) -> LastToken="id"
=INFO REPORT==== 25-Jan-2013::16:52:21 ===
is_foreign_key(ma_center_id) -> Module="ma_center"

The record is not returning a valid id "ma_center-xxxx", so, with the integer representation the association fails.

Code is compiled succefully on ebin:

ll ebin/ | grep ma_center
-rw-rw-r--  1 jose.gordo jose.gordo 12448 ene 25 16:34 ma_center.beam

And tested that the init.sh scritps includes the path on ebin.

So, why is code:is_loaded returning false?

Thanks in advance!

Proposal for alternatives to delete/1

I'm currently doing some development on the DynamoDB-adapter and since the introduction of alternative primary_key I'm having some troubles using delete/1.

I suggest that a new function is added. I'm having two suggestion of how such a function could look like:

Alternative1: Conditional deletion
I think this is a good solution. Today you can get the "same" functionality with a list comprehension, but you'll have to do N+1 calls. (Eg [ boss_db:delete(X:id()) || X <- boss_db:find(some_model, [{some_condition, ...}]) ].

My propsal would look something like this:

delete(ModelName :: atom(), [{Field1 :: atom(), Val :: any()}]) -> ok || {error, Reason}

Alternative2: Delete with models
This solution is more a replacement of the existing delete/1 function. The idea is that you send in an existing model and the function determines how to remove it (Based on the primary_key).
The function would look something like this:

-spec delete(Model :: tuple) -> ok || {error, Reason}
delete(Model) when is_tuple(Model) ->
    Rec = element(1, Model),
    [PrimaryKey] = proplists:get_value(primary_key, Rec:module_info(attributes), [id]),
    ...

What do you think?

boss_compiler has problems with file.hrl

I get this when trying to do:

 -include("include/file.hrl").

In a file in src/lib

/home/davidw/projects/my_app: {'EXIT',
    {function_clause,
        [{erl_parse,abstract,
             [undefined,{25,10}],
             [{file,"erl_parse.yrl"},{line,882}]},
         {erl_parse,record_fields,1,[{file,"erl_parse.yrl"},{line,754}]},
         {erl_parse,build_typed_attribute,2,
             [{file,"erl_parse.yrl"},{line,587}]},
         {erl_parse,yeccpars2_445,7,[{file,"erl_parse.yrl"},{line,78}]},
         {erl_parse,yeccpars0,5,
             [{file,

"/home/vagrant/otp-support/bootstrap/lib/parsetools/include/yeccpre.hrl"},
              {line,56}]},
         {boss_compiler,parse_tokens,5,
             [{file,"src/boss_compiler.erl"},{line,116}]},
         {boss_compiler,parse_text,4,
             [{file,"src/boss_compiler.erl"},{line,93}]},
         {boss_compiler,compile,2,
             [{file,"src/boss_compiler.erl"},{line,11}]}]}}

When I move file.hrl to $MY_APP/include/file.hrl the problem persists.

However, when I remove the dialyzer information in file.hrl to make it look like:

-record(file_info,
        {size   ,
         type   ,
         access ,
         atime  ,
                                     % The local time the file was last read:
                                     % {{Year, Mon, Day}, {Hour, Min, Sec}}.
                                     % atime, ctime, mtime may also be unix epochs()
         mtime  ,
                                     % The local time the file was last written.
         ctime  ,
                                     % The interpretation of this time field
                                     % is dependent on operating system.
                                     % On Unix it is the last time the file
                                     % or the inode was changed.  On Windows,
                                     % it is the creation time.
         mode   ,
                                     % the owner permissions will be
                                     % duplicated for group and user.
         links  ,
                                     % Number of links to the file (1 if the
                                     % filesystem doesn't support links).
         major_device ,
                                     % Identifies the file system (Unix),
                                     % or the drive number (A: = 0, B: = 1)
                                     % (Windows).
         %% The following are Unix specific.
         %% They are set to zero on other operating systems.
         minor_device ,
         inode   ,
         uid     ,
         gid    }).     % Group id for owner.

Things work

boss_db depends on boss_news

The dependency on boss_news is unnecessary and can cause problems due to global name registration. Would you mind if I added a way of preventing boss_news usage within the boss_db_controller? (probably through the boss_db configuration, or through a boss_db app env setting)

Inconsistent id's when using boss_db:find

When using boss_db:find to look for entries with specific id's, boss_db requires the use of integers only (e.g. 2, clashing with the standard type-integer string (e.g. "tag-2") naming scheme.

15> Tag = boss_db:find("tag-2").  
{tag,"tag-2","page",true}
16> Tag:id().                   
"tag-2"
17> boss_db:find(tag, [{id, in, ["tag-2"]}]).
{error,{error,error,<<"22P02">>,
              <<"invalid input syntax for integer: \"tag-2\"">>,
              [{position,<<"33">>}]}}
18> boss_db:find(tag, [{id, in, [2]}]).      
[{tag,"tag-2","page",true}]

So far I've only tried with the pgsql adapter -- I'll try with the mock adapter tomorrow and update the issue accordingly.

boss_db should have an additional configuration option for db driver options

I am not sure about all the other db driver usage, but I do know that the epgsql takes an additional configuration parameter that can be useful ({async, Pid}) and there are probably other drivers that would benefit from providing an additional list of options that don't relate to boss_db usage of the driver. I was going to add the changes for this, and can add it to all the drivers, but the changes would go to the older pull request (#68).

Make clear the requirement of -belongs_to

After the change entered in 7c60586 if a module takes part of a has_many relation it's required to include a -belongs_to attribute.

Prior to this commit this would work:

-module(a, [Id]).
-has({bs, many}).

%%%%%

-module(b, [Id,AId]).

But after that commit it's required (or in other case when saving the id of the related a record won't be correct) that the b module has a -belongs_to(a) :

-module(a, [Id]).
-has({bs, many}).

%%%%%

-module(b, [Id,AId]).
-belongs_to(a).

It would be nice if the documentation made this clear.

Riakc version

Hi,

The dependency of riakc is pulled from the tag "01a2d3770a". On that revision the riack application has a dependency with erlang protbuffs with a version guard of "0.6.*". On master riakc doesn't have that dependency.

That causes me a problem because I'm already using protobuffs but on version 0.7 which ends up in a conflict.

I imagine that you set that tag on riakc for a reason but otherwise I would be great if you could "update" it.

boss_db:save_record does an extra find

I have a change so that boss_db:delete avoids the extra find call as part of the other issue (#68), but boss_db:save_record also does a find to try and get a more recent copy of the old record. I was hoping to add an option to the boss_db:save_record function which can avoid the extra find call and just utilize the provided old record. I was thinking about a options list parameter with an atom like "use_old" or "stale".

bytea postgres type storage failure

When attempting to use a table with the bytea type in a column, the data storage does not occur properly. Currently, all binary types are assumed to be text, so it is impossible to pass <<16#de,16#ad,16#be,16#ef>> and expect it to be stored (it generates an epgsql error about the query not being in UTF8 format, the string escaping that is expected is here: http://www.postgresql.org/docs/current/static/datatype-binary.html). When attempting to provide the binary string in the escaped format, it also fails to be stored, but without an error: <<"\\xDEADBEEF">> is stored, and a find will return <<"ޭ��">>, which is <<16#AD,16#FD,16#FD>>. I am not quite sure about how this might be solved with the current situation, due to the way boss_db has used binaries in the past. I also wonder if it would just be better to be using pgsql:equery parameter substitution support, to avoid some of the type problems.

boss_db:count() works on database tables w/o table definition

Example:

ls src/model:

dummy.erl
participant.erl

These files are holding normal boss_db database model definitions.

I start up the project and I type in dev mode:

boss_db:count( melon, []).
12

even though I have no model named melon.erl in my src/model directory.
I recieve no error message that the model doesn't exist and get a count of the rows in the table should it exist.

How to find data where field is empty?

Let say the model is 'something' have field 'id' & 'anything',

A = something:new(id, []),
A:save().

boss_db:find(something, [{anything, []}]) or boss_db:find(something, [{anything, ""}]) does not return anything, just an empty list

I've tried the 'equals' & 'matches' also the same.

automatic way to fetch types from the model definitions

That would be cool... open an issue against BossDB on GitHub if you
don't want me to forget about it.

Evan

On Tue, Mar 5, 2013 at 3:38 PM, Alex Shneyderman
[email protected] wrote:

-model(us_state,[Id, Name::string(), Abrreviation::string()]).

when I do

boss_record:new(us_state,[]).

I get back #us_record{}

Is there a way to automatically export this as type of some sort?
So that it can be used to create -spec's?

Cheers,
Alex.

Problem with date() and Postgres

P =  boss_record:new(student, [{name, "Sneezy Dwarf"}, {birth_date, {1980,1,2}}]).

Yields

select * from students;

14 | Sneezy Dwarf      | 2032-09-28 |     | 2013-06-26 12:17:36

The first date column is not correct! It seems to be accepting a timestamp like the output of erlang:now(), rather than an actual date.

Minus in key name

Currently it is impossible to have a table key with a "-" in it, i.e. "table-key-1" (where the key is named "key-1"). This is easy to fix, one just needs to replace the calls to string:tokens with something that only splits on the first "-".

Also, is it possible to replace "-" with some -define so that in a forkers can replace "-" with another character if they need to.

@nivertech

Can't compile if I add typespecs to module params

I have added typspec to the params in one of my modules. It seems that doing this break compilation.

My module is defined like this:

  -module(device_user,[Id, Email::string(), Password::string(), ConfirmationToken::string(), ConfirmationSentAt::datetime(), ConfirmedAt::datetime(), Locked::string()]).

And this is the output I got:

src/model/device_user.erl:1: syntax error before: '::' 
src/model/device_user.erl:3: no module definition
... (more errors)

I'm using R15B01

Count always returns 0 with mnesia adapter

The mnesia adapter passes wrong parameters to find/7 in count/3, and as a result it always reports 0 matches. Here's a diff of the fix:

index 24089eb..b9c7309 100644
--- a/src/db_adapters/boss_db_adapter_mnesia.erl
+++ b/src/db_adapters/boss_db_adapter_mnesia.erl
@@ -160,7 +160,7 @@ test_rec(Rec,{Key, 'contains_none', Values}) when is_list(Values) ->

 % -----
 count(Conn, Type, Conditions) ->
-    length(find(Conn, Type, Conditions,0,0,id,ascending)).
+    length(find(Conn, Type, Conditions,all,0,id,ascending)).

 % -----
 counter(Conn, Id) when is_list(Id) ->

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.