View Source MongoAgile.Examples.Schema.SchemaModel (mongo_agile v0.8.1-rc)
SchemaModel Example of model, have some example of using before and after methods.
- Schema versioning
- timestamp
Link to this section Summary
Functions
Get _id value of mongo_id type.
Get name value of string type.
Get schema_version value of integer type.
Get timestamp_created value of integer type.
Get timestamp_last_updated value of integer 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 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 schema_version 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 timestamp_created 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 timestamp_last_updated 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 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 schema_version field. Before of update the valor will be check it.
Put a new value in timestamp_created field. Before of update the valor will be check it.
Put a new value in timestamp_last_updated field. Before of update the valor will be check it.
The Schema is: %{"_id" => :mongo_id, "name" => :string, "schema_version" => :integer, "timestamp" => %{"created" => :integer, "last_updated" => :integer}}
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 name value of string type.
Get schema_version value of integer type.
Get timestamp_created value of integer type.
Get timestamp_last_updated value of integer 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.
@spec 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
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
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut__id(fn(_old)-> "5fdca86a10fb18893febbea0" end)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get__id(obj)
...> |> MongoAgile.MapSchema.IdObjectType.is_valid?()
true
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
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_name(fn(_old)-> "Santander" end)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_name(obj)
"Santander"
mut the value of schema_version field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that schema_version is integer type.
example
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_schema_version(fn(_old)-> 40 end)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_schema_version(obj)
40
mut the value of timestamp_created field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that timestamp_created is integer type.
example
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_timestamp_created(fn(_old)-> 20 end)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_created(obj)
20
mut the value of timestamp_last_updated field, using a mut_fn.(actualValue)
that will recive the actual value.
Before of update the valor will be check it.
Remember that timestamp_last_updated is integer type.
example
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_timestamp_last_updated(fn(_old)-> 50 end)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_last_updated(obj)
50
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
Example:
iex>Elixir.MongoAgile.Examples.Schema.SchemaModel.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
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put__id("5fdca86a10fb18893febbea0")
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get__id(obj)
...> |> MongoAgile.MapSchema.IdObjectType.is_valid?()
true
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
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_name("Santander")
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_name(obj)
"Santander"
Put a new value in schema_version field. Before of update the valor will be check it.
Remember that schema_version is integer type.
example
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_schema_version(1)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_schema_version(obj)
1
Put a new value in timestamp_created field. Before of update the valor will be check it.
Remember that timestamp_created is integer type.
example
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_timestamp_created(1)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_created(obj)
1
Put a new value in timestamp_last_updated field. Before of update the valor will be check it.
Remember that timestamp_last_updated is integer type.
example
Example:
iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_timestamp_last_updated(10)
iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_last_updated(obj)
10
The Schema is: %{"_id" => :mongo_id, "name" => :string, "schema_version" => :integer, "timestamp" => %{"created" => :integer, "last_updated" => :integer}}
Get the module of type by name
Say if the schema use Atomize mode.
Map of types