2019-12-05



I'm pleased to announce that Peewee now supports CockroachDB
(CRDB), the distributed, horizontally-scalable SQL database. I'm excited about
this release, because it's now quite easy to get up-and-running with a robust
SQL database that can scale out with minimal effort (documentation).

Here is how you configure a CockroachDatabase instance:

CRDB conveniently provides a very similar SQL dialect to Postgres, which has been
well-supported in Peewee for many years, allowing you to use features like jsonb
and arrays,
in addition to the regular complement of field-types. Additionally, CRDB speaks
the same wire-protocol as Postgres, so it works out-of-the-box using the
popular psycopg2 driver.

Example model class using jsonb and CRDB's UUID primary-key type:

CRDB provides a client-side transaction retry API, which Peewee supports using
a helper-method. To use client-side retries with Peewee and CRDB, provide a
callable that executes your transactional SQL and pass it to the
run_transaction()
method:

Check out the CockroachDB installation docs
for instructions on getting up-and-running.

Links

CockroachDB documentation

Using CockroachDB with Peewee

Show more