Skip to content

Support for jsonb indexable columns #3919

@borutjures

Description

@borutjures

Problem to Solve

It would be great if data for a complex type, such as another model, a List, or a Map, would be indexable at the properties level.

Currently these types are stored as a json object in the database:

Proposal

There is a jsonb type in PostgreSQL. jsonb supports indexing, which can be a significant advantage (https://www.postgresql.org/docs/current/datatype-json.html).

It would be great if jsonb was used instead of json, but it probably cannot be changed at this stage (it might be a breaking change for a small percentage of the existing data).

Is it possible to add another ColumnSerializableX column type that would use jsonb in the database?

Or could the used database type for ColumnSerializable be configurable per project (json or jsonb)?

Use Case

The Address class has state and city properties and we would like to index these in the database.

class: Company
table: company
fields:
  address: Address # This would be possible if stored as a `jsonb` instead of `json` column

Alternatives

Only ugly ones like extracting state and city properties as separate fields from the Address class.

class: Company
table: company
fields:
  address: Address # Stored as a json column
  address_state: String  # Duplicate of `Address.state`
  address_city: String  # Duplicate of `Address.city`

Additional context

No response

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this

Metadata

Metadata

Labels

area: modelsIssues related to Serverpod Models.enhancementNew feature or request

Type

No type

Projects

Status

Done 🚀

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions