MongoAgile.Examples.Customer.CustomerModel (mongo_agile v0.7.0) View Source
CustomerModel Example of model using MapSchema
Link to this section Summary
Functions
Get _id value of mongo_id type.
Get contact_email value of string type.
Get contact_phone value of string type.
Get name value of string type.
Get state value of string type.
It´s will return true, if the map follow the schema.
Let decode json to Object. Checking every type following the schema.
Let decode json and mut a existing object . Checking every type following the schema.
Intenal it´s using the method put/2
.
Let encode object to Json.
mut the value of _id field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
mut the value of contact_email field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
mut the value of contact_phone field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
mut the value of name field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
mut the value of state field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
This method only create a new simple map %{}. Yes.
Put a new value in each field of the update map, in the field of the object.
Put a new value in each field of the update map, in the field of the object.
Put a new value in _id field. Before of update the valor will be check it.
Put a new value in contact_email field. Before of update the valor will be check it.
Put a new value in contact_phone field. Before of update the valor will be check it.
Put a new value in each field of the update map, in the field of the object only if exist the field in the schema (ifmatch)
Put a new value in each field of the update map, in the field of the object only if exist the field in the schema (ifmatch)
Put a new value in name field. Before of update the valor will be check it.
Put a new value in state field. Before of update the valor will be check it.
The Schema is: %{"_id" => :mongo_id, "contact" => %{"email" => :string, "phone" => :string}, "name" => :string, "state" => :string}
Get the module of type by name
Say if the schema use Atomize mode.
Map of types
Link to this section Functions
Get _id value of mongo_id type.
Get contact_email value of string type.
Get contact_phone value of string type.
Get name value of string type.
Get state value of string type.
It´s will return true, if the map follow the schema.
Let decode json to Object. Checking every type following the schema.
Note: This method use Jason library.
Specs
json_decode( any(), binary() | maybe_improper_list( binary() | maybe_improper_list(any(), binary() | []) | byte(), binary() | [] ) ) :: any()
Let decode json and mut a existing object . Checking every type following the schema.
Intenal it´s using the method put/2
.
Note: This method use Jason library.
Parameters
- mapa: Object
- json: Json object
Let encode object to Json.
Note: This method use Jason library.
mut the value of _id field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that _id is mongo_id type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.mut__id(fn(_old)-> "5fdca86a10fb18893febbea0" end)
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get__id(obj)
...> |> MongoAgile.MapSchema.IdObjectType.is_valid?()
true
mut the value of contact_email field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that contact_email is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.mut_contact_email(fn(_old)-> "Galicia" end)
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_contact_email(obj)
"Galicia"
mut the value of contact_phone field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that contact_phone is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.mut_contact_phone(fn(_old)-> "Santander" end)
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_contact_phone(obj)
"Santander"
mut the value of name field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that name is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.mut_name(fn(_old)-> "Barcelona" end)
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_name(obj)
"Barcelona"
mut the value of state field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that state is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.mut_state(fn(_old)-> "Santander" end)
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_state(obj)
"Santander"
This method only create a new simple map %{}. Yes.
Because the idea it´s the data structure will be independent of MapSchema but the module will have the schema that the maps should be follow.
Example:
iex>Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
%{}
Put a new value in each field of the update map, in the field of the object.
But before of update the values always will be check the type.
If a field dont exist in the schema throw exception. (If you need be less strict you can use put_ifmatch/1
or put_ifmatch/2
)
Put a new value in each field of the update map, in the field of the object.
But before of update the values always will be check the type.
If a field dont exist in the schema throw exception. (If you need be less strict you can use put_ifmatch/1
or put_ifmatch/2
)
Put a new value in _id field. Before of update the valor will be check it.
Remember that _id is mongo_id type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.put__id("5fdca86a10fb18893febbea0")
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get__id(obj)
...> |> MongoAgile.MapSchema.IdObjectType.is_valid?()
true
Put a new value in contact_email field. Before of update the valor will be check it.
Remember that contact_email is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.put_contact_email("Santander")
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_contact_email(obj)
"Santander"
Put a new value in contact_phone field. Before of update the valor will be check it.
Remember that contact_phone is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.put_contact_phone("Sevilla")
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_contact_phone(obj)
"Sevilla"
Put a new value in each field of the update map, in the field of the object only if exist the field in the schema (ifmatch)
But before of update the values always will be check the type.
Put a new value in each field of the update map, in the field of the object only if exist the field in the schema (ifmatch)
But before of update the values always will be check the type.
Put a new value in name field. Before of update the valor will be check it.
Remember that name is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.put_name("Santander")
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_name(obj)
"Santander"
Put a new value in state field. Before of update the valor will be check it.
Remember that state is string type.
Example:
iex>obj = Elixir.MongoAgile.Examples.Customer.CustomerModel.new()
...> |> Elixir.MongoAgile.Examples.Customer.CustomerModel.put_state("Galicia")
iex> Elixir.MongoAgile.Examples.Customer.CustomerModel.get_state(obj)
"Galicia"
The Schema is: %{"_id" => :mongo_id, "contact" => %{"email" => :string, "phone" => :string}, "name" => :string, "state" => :string}
Get the module of type by name
Say if the schema use Atomize mode.
Map of types