Elixir “exto.Schema.Metadata”的用途是什么?(即“元”字段)
我计划使用Elixir “exto.Schema.Metadata”的用途是什么?(即“元”字段),elixir,schema,ecto,Elixir,Schema,Ecto,我计划使用exto的Schema和Changeset仅用于验证,而不将任何内容持久化到数据库中,并试图弄清楚是否应该使用。根据文档,它们之间的唯一区别是“嵌入式模式不需要源名称,也不包含元数据字段。” 因此,我选择了嵌入式_schema/1,工作非常出色,但它让我想知道元数据的确切用途是什么?对于澄清这一点没有多大帮助: 存储结构的元数据 这些字段是: 状态-结构生命周期中的状态,其中一个为:build,:loaded, :删除 source—查询旁边的架构的源 前缀,默认为{nil,“sou
exto
的Schema
和Changeset
仅用于验证,而不将任何内容持久化到数据库中,并试图弄清楚是否应该使用。根据文档,它们之间的唯一区别是“嵌入式模式不需要源名称,也不包含元数据字段。”
因此,我选择了嵌入式_schema/1
,工作非常出色,但它让我想知道元数据的确切用途是什么?对于澄清这一点没有多大帮助:
存储结构的元数据
这些字段是:
- 状态-结构生命周期中的状态,其中一个为:build,:loaded, :删除
- source—查询旁边的架构的源 前缀,默认为{nil,“source”}
- context-由 数据库
嵌入式_模式/1
行中
更新 忘记了即将推出的Exto 3和Hexdocs文档仍然适用于Exto 2.2.11。在源代码中找到,但更详细:
Stores metadata of a struct.
## State
The state of the schema is stored in the `:state`
field and allows following values:
* `:built` - the struct was constructed in
memory and is not persisted
to database yet;
* `:loaded` - the struct was loaded from database
and represents persisted data;
* `:deleted` - the struct was deleted and no longer
represents persisted data.
## Source
The `:source` tracks the (table or collection) where
the struct is or should be persisted to.
## Prefix
Tracks the source prefix in the data storage.
## Context
The `:context` field represents additional state some
databases require for proper updates of data. It is
not used by the built-in adapters of `Ecto.Adapters.Postres`
and `Ecto.Adapters.MySQL`.
## Schema
The `:schema` field refers the module name for the
schema this metadata belongs to.
(同时解决我的上述困境:
An Ecto schema is used to map any data source into an Elixir struct.
The definition of the schema is possible through two main APIs:
`schema/2` and `embedded_schema/1`.
`schema/2` is typically used to map data from a persisted source,
usually a database table, into Elixir structs and vice-versa. For
this reason, the first argument of `schema/2` is the source (table)
name. Structs defined with `schema/2` also contain a `__meta__` field
with metadata holding the status of the struct, for example, if it
has been built, loaded or deleted.
On the other hand, `embedded_schema/1` is used for defining schemas
that are embedded in other schemas or only exist in-memory. For example,
you can use such schemas to receive data from a command line interface
and validate it, without ever persisting it elsewhere. Such structs
do not contain a `__meta__` field, as they are never persisted.
)EXTO内部使用
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
字段来维护有关记录、关联(如果已加载、过时或更多)的元数据
您链接的文档中的描述似乎是自给自足的:
存储结构的元数据。
这些字段是:
-结构生命周期中的状态,其中一个是状态
,:builded
,:加载的
:删除的
-查询前缀旁边架构的源, 默认值为source
{nil,“source”}
-数据库存储的上下文上下文
exto.Schema.Metadata
仅用于存储所有与数据库相关的信息
正如Jose在报告中提到的
自Ecto 2.0以来,越来越多的开发人员和团队使用Ecto进行数据映射和验证,而不需要数据库。然而,向应用程序添加EXTO仍然会带来很多SQL负担,比如适配器、沙盒和迁移,许多人认为这是一个混合消息
后者是关于元数据的
对于Ecto 2有一个经验法则:无论您是否需要后面的DB表,请使用schema
;否则请使用embedded_schema
旁注:我的一般建议是,当你想简单地理解一些东西时,不要阅读文档