使用 Peewee ORM 加入对 Postgres 9.4 JSONB 字段的查询

Join query for Postgres 9.4 JSONB field using Peewee ORM

我在我的一个项目中使用 peewee 并且来自 Django 背景,我非常喜欢它。

我计划在 postgres 9.4 中广泛使用新引入的 JSONB。但是,我不知道如何使用 JSONB 键执行连接操作。

我假设一个例子对整个社区来说都是极好的。

你可以这样写:

User.select().join(Metadata, on=Metadata.data['user_id'] == User.id)

其中 Metadata.data 是一个 JSON 字段。