Created
January 29, 2014 12:24
-
-
Save zkessin/8686881 to your computer and use it in GitHub Desktop.
Proposed new model structure
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
-include_lib("boss_db/include/cb_model.hrl"). | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
-type opt(X) :: X| undefined. | |
-type opt_list(L) :: L|[L]. | |
-type count() :: pos_integer() | many. | |
-type direction() :: assending|descending. | |
-type sort() :: {order_by, atom()} | {order_by, atom(), descending|assending}. | |
-type assoc() :: {module, atom()}. | |
-type fk() :: {foreign_key, atom()}. | |
% Redefine this as a record? | |
-define(has_assoc, { | |
field :: atom(), | |
sort :: opt(atom()), | |
assoc :: opt(atom()), | |
fk :: opt(atom()) | |
}). | |
-type has() :: #has_assoc{}. | |
-type field() :: {atom(), string()}. | |
-record(cb_model, | |
{ | |
model :: atom(), | |
belongs_to :: opt(atom()), | |
has :: opt(opt_list(has())), | |
counter :: opt(opt_list(atom())), | |
db_table :: opt(string()), | |
db_fields :: opt([field()]) | |
}). | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
-record(new_model, { | |
id ::uuid(), | |
name ::string(), | |
address ::address() | |
}). | |
model_def() -> | |
{ok, #cb_model{model = mew_model | |
belongs_to = model | |
}}. | |
MyModel:name() | |
MyMode:name(foo). | |
MyModel:get(name). | |
MyModel:set(name, Value). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment