Skip to content

Instantly share code, notes, and snippets.

@zkessin
Created January 29, 2014 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkessin/8686881 to your computer and use it in GitHub Desktop.
Save zkessin/8686881 to your computer and use it in GitHub Desktop.
Proposed new model structure
-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