Peewee 简明教程
Peewee - Using CockroachDB
CockroachDB 或蟑螂数据库 (CRDB) 是由计算机软件公司 Cockroach Labs 开发的。它是一个可扩展的、持续复制的事务性数据存储,旨在将数据副本存储在多个位置,以提供快速访问。
CockroachDB or Cockroach Database (CRDB) is developed by computer software company Cockroach Labs. It is a scalable, consistently-replicated, transactional datastore which is designed to store copies of data in multiple locations in order to deliver speedy access.
Peewee 通过 playhouse.cockroachdb 扩展模块中定义的 CockroachDatabase 类提供对该数据库的支持。该模块包含 CockroachDatabase 的定义,它是核心模块中 PostgresqlDatabase 类的子类。
Peewee provides support to this database by way of CockroachDatabase class defined in playhouse.cockroachdb extension module. The module contains definition of CockroachDatabase as subclass of PostgresqlDatabase class from the core module.
此外,还有 run_transaction() 方法,它在事务内运行一个函数并提供自动客户端重试逻辑。
Moreover, there is run_transaction() method which runs a function inside a transaction and provides automatic client-side retry logic.
Field Classes
该扩展还具有某些特殊字段类,可用作 CRDB 兼容模型中的属性。
The extension also has certain special field classes that are used as attribute in CRDB compatible model.
-
UUIDKeyField - A primary-key field that uses CRDB’s UUID type with a default randomly-generated UUID.
-
RowIDField - A primary-key field that uses CRDB’s INT type with a default unique_rowid().
-
JSONField - Same as the Postgres BinaryJSONField.
-
ArrayField - Same as the Postgres extension, but does not support multi-dimensional arrays.