EctoTablestore.Schema (ecto_tablestore v0.8.3) View Source
Defines a schema for Tablestore.
Since the atomic increment may need to return the increased value, EctoTablestore.Schema
module underlying uses Ecto.Schema, and automatically append all :integer field type with
read_after_writes: true option by default.
An Ecto schema is used to map any data source into an Elixir struct. The definition of the
schema is possible through the API: tablestore_schema/2.
tablestore_schema/2 is typically used to map data from a persisted source, usually a
Tablestore table, into Elixir structs and vice-versa. For this reason, the first argument of
tablestore_schema/2 is the source(table) name. Structs defined with tablestore_schema/2 also
contain a __meta__ field with metadata holding the status of struct, for example, if it has
bee built, loaded or deleted.
Since Tablestore is a NoSQL database service, embedded_schema/1 is not supported so far.
About timestamps
Since Tablestore's column does not support DateTime type, use UTC timestamp (:integer type) as
timestamps() macro for the generated inserted_at and updated_at fields by default.
About primary key
- The primary key supports
:id(integer()) and:binary_id(binary()). - By default the
:primary_keyoption isfalse. - The first defined primary key by the written order in the
tablestore_schemais the partition key. - Up to 4 primary key(s), it is limited by TableStore product server side.
- Up to 1 primary key with
autogenerate: trueoption, it is limited by TableStore product server side. - The primary key set with
autogenerate: truewill use the TableStore product server's AUTO_INCREMENT feature. - If the partition key set as
autogenerate: trueis not allowed to take advantage of the AUTO_INCREMENT feature which it is limited by server, but there is a built-in implement to use theSequenceto achieve the same atomic increment operation inecto_tablestorelibrary.
Example
defmodule User do
use EctoTablestore.Schema
tablestore_schema "users" do
field :outer_id, :binary_id, primary_key: true
field :internal_id, :id, primary_key: true, autogenerate: true
field :name, :string
field :desc
end
endBy default, if not explicitly set field type will process it as :string type.