MongoAgile.Examples.Schema.SchemaModel (mongo_agile v0.7.0) View Source

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.

Link to this function

get_schema_version(arg1)

View Source

Get schema_version value of integer type.

Link to this function

get_timestamp_created(arg1)

View Source

Get timestamp_created value of integer type.

Link to this function

get_timestamp_last_updated(arg1)

View Source

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.

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.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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_name(fn(_old)-> "Sevilla" end)
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_name(obj)
  "Sevilla"
Link to this function

mut_schema_version(arg1, arg2)

View Source

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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_schema_version(fn(_old)-> 20 end)
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_schema_version(obj)
  20
Link to this function

mut_timestamp_created(arg1, arg2)

View Source

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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_timestamp_created(fn(_old)-> 5 end)
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_created(obj)
  5
Link to this function

mut_timestamp_last_updated(arg1, arg2)

View Source

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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.mut_timestamp_last_updated(fn(_old)-> 1 end)
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_last_updated(obj)
  1

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.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:

  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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_name("Santiago")
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_name(obj)
  "Santiago"
Link to this function

put_schema_version(arg1, arg2)

View Source

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:

  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
Link to this function

put_timestamp_created(arg1, arg2)

View Source

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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_timestamp_created(40)
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_created(obj)
  40
Link to this function

put_timestamp_last_updated(arg1, arg2)

View Source

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:

  iex>obj = Elixir.MongoAgile.Examples.Schema.SchemaModel.new()
  ...> |> Elixir.MongoAgile.Examples.Schema.SchemaModel.put_timestamp_last_updated(40)
  iex> Elixir.MongoAgile.Examples.Schema.SchemaModel.get_timestamp_last_updated(obj)
  40

The Schema is: %{"_id" => :mongo_id, "name" => :string, "schema_version" => :integer, "timestamp" => %{"created" => :integer, "last_updated" => :integer}}

Link to this function

schema_get_type_module(arg)

View Source

Get the module of type by name

Say if the schema use Atomize mode.

Map of types