### What?
Allows to query on JSON / Rich Text fields in Postgres the same way as
in Mongodb with any nesting level.
Example:
Data:
```js
{
json: {
array: [
{
text: 'some-text', // nested to array + object
object: {
text: 'deep-text', // nested to array + 2x object
array: [10], // number is nested to array + 2x object + array
},
},
],
}
}
```
Query:
```ts
payload.find({
collection: 'json-fields',
where: {
and: [
{
'json.array.text': {
equals: 'some-text',
},
},
{
'json.array.object.text': {
equals: 'deep-text',
},
},
{
'json.array.object.array': {
in: [10, 20],
},
},
{
'json.array.object.array': {
exists: true,
},
},
{
'json.array.object.notexists': {
exists: false,
},
},
],
},
})
```
### How?
Utilizes [the `jsonb_path_exists` postgres
function](https://www.postgresql.org/docs/current/functions-json.html)
Payload Postgres Adapter
Vercel Postgres adapter for Payload.
Installation
npm install @payloadcms/db-vercel-postgres
Usage
Explicit Connection String
import { buildConfig } from 'payload'
import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'
export default buildConfig({
db: vercelPostgresAdapter({
pool: {
connectionString: process.env.DATABASE_URI,
},
}),
// ...rest of config
})
Automatic Connection String Detection
Have Vercel automatically detect from environment variable (typically process.env.POSTGRES_URL)
export default buildConfig({
db: postgresAdapter(),
// ...rest of config
})
More detailed usage can be found in the Payload Docs.