EctoTablestore.Schema (ecto_tablestore v0.7.0) View Source
Defines a schema for Tablestore.
Since the atomic increment may need to return the increased value,
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 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
__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.
Since Tablestore's column does not support
DateTime type, use UTC timestamp (:integer type) as
timestamps() macro for the generated
updated_at fields by default.
- The primary key supports
- By default the
- 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 the
Sequenceto achieve the same atomic increment operation in
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 end
By default, if not explicitly set field type will process it as