#3205·sea-orm

Per-backend column type overrides, e.g. json on mysql / jsonb on postgres

Author: xue-ding-eCreated Sep 17, 2026Updated Sep 26, 2026
LabelsArea:entity-first

Motivation

SeaORM/sea-query already map abstract column types for each database. JsonBinary renders as jsonb on PostgreSQL and json on MySQL; TinyInteger renders as smallint on PostgreSQL. The original description incorrectly presented those cases as unsupported.

This proposal concerns explicit per-backend type choices beyond the built-in mappings, such as a backend-specific Custom SQL type with a fallback for other databases. Overrides must remain compatible with the field's value conversion and query behavior.

Proposed Solutions

The sketch below is superseded by the draft implementation in #3206; it is not an available API.

I'd like to start a discussion on a per-backend column type override, roughly:

rust
ColumnDef::new(Column::Payload)
    .string() // abstract fallback for backends without an override
    .per_backend(|backend| match backend {
        Backend::MySql => ColumnType::Json,
        Backend::Postgres => ColumnType::JsonB,
        _ => ColumnType::String(None),
    })

(or any equivalent shape — a map from backend to ColumnType, an extension of ColumnType::Custom, or derivable helpers; the ergonomics are for maintainers to steer).

The semantics that have proven themselves in other ORMs: the backend-specific type wins on that backend, other backends fall back to the abstract type, and columns without overrides render exactly as today.

  • ent (Go) has field.String("s").SchemaType(map[string]string{dialect.MySQL: "varchar(255)", dialect.Postgres: "text"}) as a built-in
  • SQLAlchemy has String(255).with_variant(VARCHAR(255, charset="utf8"), "mysql")
  • gorm has an open proposal for dialect-qualified type tags (go-gorm/gorm#7867); it has not been merged

Happy to collaborate on a design and implementation if maintainers think this fits sea-query/SeaORM's direction.

Additional Information

The same need shows up across ecosystems; the ent and SQLAlchemy links above are the closest prior art. No behavior would change for existing entities — the fallback path is the current rendering.

AI disclosure: AI assistants prepared the original proposal and this factual correction. The author's own explanation requested by the maintainer is still pending.