Repository navigation
Description
Problem to Solve
TypeDefinition.databaseType (serverpod_cli/lib/src/generator/types.dart:549-581) maps scalar Dart types to column types (int → bigint at line 559, further scalars, vectors, geography) and everything else, including List<int>, List<String> and List<UuidValue>, to json (or jsonb): if (isJsonbSerialized) return 'jsonb'; return 'json'; (lines 579-580). The column takes exactly this type (serverpod_cli/lib/src/database/create_definition.dart:33-43). ColumnType (serverpod_database/lib/src/models/column_type.spy.yaml: text, boolean, integer, doublePrecision, timestampWithoutTimeZone, bytea, bigint, uuid, json, unknown, vector, halfvec, sparsevec, bit, jsonb, geography, ...) has no array type, so a model cannot declare a native array column, and the migration generator cannot create one. Today List<int> is always a json/jsonb column.
Native arrays matter for compact storage of id sets (bigint[] is 8 bytes per element plus a small header, JSON text is several times larger and goes through TOAST earlier), for = ANY(column) and && queries, and for GIN indexes on the array.
Proposal
An opt-in per field, keeping today's default:
fields:
holes: List<int>, array # bigint[]
tags: List<String>, array # text[]with a new ColumnType per element type (or an isArray flag on the column definition), migration support, and query operators such as t.holes.contains(x) (= ANY) and t.holes.overlaps([...]) (&&).
Start with List<int>, List<String>, List<UuidValue>, List<double>, List<bool> as bigint[], text[], uuid[], double precision[], boolean[] on PostgreSQL behind an explicit field keyword; SQLite keeps json.
Use Case
A job-run table that tracks the gaps in a sequence of event ids, and lists of id pairs, both designed as bigint[]. As JSON, 10,000 gaps are roughly 70 to 110 KB per row (estimated, not measured), so TOAST and WAL on every run.
Alternatives
What we do today: store as json/jsonb, lower the cap on the number of gaps, and select with an array parameter (id = ANY($1::bigint[]) through unsafeQuery; the postgres package encodes a List<int> parameter as an array). Arrays as query parameters work; only array columns are missing. The JSON column stays larger, and it cannot be indexed or queried with array operators.
Additional context
- Checked against
serverpod_cli 4.1.0andserverpod_database 4.1.0; unchanged in 4.1.1. - Related: #4284 (open; query interface for json/jsonb fields), #5094 (open; native jsonb for opaque JSON).
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
Assignees
Labels
Type
Projects
- StatusShow more project fieldsInbox 📫
Activity