Fields and column types
Each field of a model struct is a column of its table. rind reads the field’s Rust type and chooses the SQL type from it. This page lists every type rind knows, with the column it gives, and how its values look in JSON when a resource sends them.
All the SQL on this page was printed by rind schema from a model that
has every type:
#![allow(unused)]
fn main() {
use chrono::{DateTime, NaiveDate, NaiveDateTime, Utc};
use rind::prelude::*;
#[derive(Debug, Clone, Model)]
#[model(table = "lab_everything")]
pub struct Everything {
pub id: i64,
pub big: i64,
pub int: i32,
pub small: i16,
// … one field per type, shown below
}
}
NULL is Option
A column is NOT NULL unless its field is an Option:
#![allow(unused)]
fn main() {
pub body: String, // "body" text NOT NULL
pub maybe: Option<String>, // "maybe" text
}
This is Django’s null=True. There is no separate blank=True: what a
client may leave empty is decided by the input, not by
the model.
Option works with every type on this page, arrays included:
Option<Vec<i32>> is a nullable integer[].
Numbers
#![allow(unused)]
fn main() {
pub big: i64, // "big" bigint NOT NULL
pub int: i32, // "int" integer NOT NULL
pub small: i16, // "small" smallint NOT NULL
pub double: f64, // "double" double precision NOT NULL
pub single: f32, // "single" real NOT NULL
}
| Rust | PostgreSQL | Django | JSON |
|---|---|---|---|
i64 | bigint | BigIntegerField | 42 |
i32 | integer | IntegerField | 42 |
i16 | smallint | SmallIntegerField | 42 |
f64 | double precision | FloatField | 4.2 |
f32 | real | 4.2 |
There are no unsigned types (u32, u64): PostgreSQL has none. Use the
signed type, and a check constraint if the value
must be positive (Django’s PositiveIntegerField).
In queries, every integer column compares with any integer, and every
float column with any float: Wagon::position().eq(1) works although the
column is an i32. (The path of an integer column is a Path<i64>,
whatever its width.)
For exact decimals (prices), see Decimals below.
Booleans
#![allow(unused)]
fn main() {
pub flag: bool, // "flag" boolean NOT NULL
}
Django’s BooleanField. JSON true or false.
Texts
#![allow(unused)]
fn main() {
pub body: String, // "body" text NOT NULL
#[column(max_length = 50)]
pub short: String, // "short" character varying(50) NOT NULL
}
A String is a text column, of any length: Django’s TextField. With
max_length = n, it is a character varying(n): Django’s CharField.
In PostgreSQL the two are stored the same way and are as fast. The
length is a rule about the data, not an optimisation. Use max_length
when there is a real limit (a code, a name), and text otherwise.
The input does not read the model’s max_length: give it
there too (#[input(max_length = 50)]), so that a client gets a clear
error on the field rather than a database error.
Django’s EmailField, SlugField, URLField are all CharFields with a
validation. In rind the column is a String; the validation goes in the
input.
Dates and times
#![allow(unused)]
fn main() {
use chrono::{DateTime, NaiveDate, NaiveDateTime, Utc};
pub day: NaiveDate, // "day" date NOT NULL
pub moment: DateTime<Utc>, // "moment" timestamp with time zone NOT NULL
pub local: NaiveDateTime, // "local" timestamp without time zone NOT NULL
}
| Rust | PostgreSQL | Django | JSON |
|---|---|---|---|
chrono::NaiveDate | date | DateField | "2026-11-27" |
chrono::DateTime<Utc> | timestamp with time zone | DateTimeField with USE_TZ = True | "2026-11-27T15:48:05Z" |
chrono::NaiveDateTime | timestamp without time zone | DateTimeField with USE_TZ = False | "2026-11-27T15:48:05" |
The types come from the chrono crate. rind
re-exports it, so a models crate can use it without a dependency of its
own:
#![allow(unused)]
fn main() {
use rind::db::chrono::{DateTime, NaiveDate, Utc};
}
or add it to its Cargo.toml, as the sample does, with the serde
feature (the serializers need it):
chrono = { version = "0.4", default-features = false, features = ["std", "clock", "serde"] }
Which one to choose. A moment in time (when a row was created, when a
train leaves) is a DateTime<Utc>: PostgreSQL stores it as an instant,
and there is no doubt about its time zone. Use NaiveDateTime only to
describe an existing database whose columns have no time zone.
Not supported yet: a time of day alone (time, Django’s
TimeField, chrono::NaiveTime) and a duration (interval,
DurationField). rind can neither write them nor compare them. Store a
time as an i32 of minutes or seconds, and a duration as an i64 of
seconds.
JSON
#![allow(unused)]
fn main() {
pub data: serde_json::Value, // "data" jsonb NOT NULL
}
A serde_json::Value is a jsonb column: Django’s JSONField. It holds
any JSON value, and is sent to the client as it is.
rind::prelude has a type called Value too: it is rind’s own value of a
query parameter, not JSON. Write serde_json::Value in full in a model,
and add serde_json to the crate’s dependencies.
Queries can look inside a JSON column: see Queries.
Arrays
#![allow(unused)]
fn main() {
pub tags: Vec<String>, // "tags" text[] NOT NULL
#[column(max_length = 20)]
pub codes: Vec<String>, // "codes" character varying(20)[] NOT NULL
pub numbers: Vec<i64>, // "numbers" bigint[] NOT NULL
pub maybe_list: Option<Vec<i32>>, // "maybe_list" integer[]
}
A Vec<T> is a PostgreSQL array of the SQL type of T: Django’s
ArrayField (from django.contrib.postgres). max_length applies to
each element. Arrays of arrays are not supported.
In JSON an array is a list: ["rail", "night"].
Arrays are useful for short lists that belong to the row (tags, flags, the services of a station) and that you filter with “contains” or “overlaps”. When the elements have attributes of their own, or are shared between rows, use another model and a relation instead.
Bytes
#![allow(unused)]
fn main() {
#[column(sql = "bytea")]
pub raw: Vec<u8>, // "raw" bytea NOT NULL
}
Django’s BinaryField. rind would read a Vec<u8> as an array of small
numbers, so give the type with sql = "bytea". In JSON it is a list of
numbers: [0, 1, 255].
For files (images, documents), do not store the bytes in the table: use
a File column, below.
Types that need their SQL type
For the types below, there is more than one possible SQL type, or the
type comes from an extension. rind cannot guess, so the field says it
with #[column(sql = "…")]:
#![allow(unused)]
fn main() {
#[column(sql = "inet")]
pub address: rind::db::types::Inet, // "address" inet NOT NULL
}
If you forget it, the derive stops:
error: cannot tell the SQL type of this field: give it, #[column(sql = "…")]
|
| pub address: rind::db::types::Inet,
| ^^^^^^^^^^^^^^^^^^^^^
Each of these types reads and writes its PostgreSQL type exactly, in the binary form the server uses, in queries, inputs and updates alike.
| Rust | sql = … | Django | JSON |
|---|---|---|---|
rind::db::types::Decimal (feature decimal) | "numeric(10, 2)" | DecimalField | "1234.56" (a string, so no digit is lost) |
rind::db::types::Inet | "inet" | GenericIPAddressField | "192.168.1.7" |
rind::db::geo::Point | "geography(Point,4326)" or "geometry(Point,4326)" | GeoDjango PointField | {"lng": 2.35, "lat": 48.85} |
rind::db::geo::Polygon, MultiPolygon, Geometry | "geometry(Polygon,4326)"… | PolygonField… | GeoJSON |
rind::db::geo::Shape | any PostGIS type | GeometryField | the EWKB, in hexadecimal |
rind::db::types::Vector | "vector(3)" (pgvector) | pgvector’s VectorField | [0.5, -1.0, 2.0] |
rind::db::types::TsVector | "tsvector" | SearchVectorField | [{"word": "gare", "positions": [1]}] |
rind::db::types::EnumValue | the name of an enumerated type | "ok" (the label) |
Decimals
Decimal needs the Cargo feature decimal of rind:
rind = { workspace = true, features = ["decimal"] }
#![allow(unused)]
fn main() {
#[column(sql = "numeric(10, 2)")]
pub price: rind::db::types::Decimal,
}
numeric(10, 2) is Django’s max_digits=10, decimal_places=2. Never
store money in an f64.
Geography
Point and the shapes need the PostGIS extension, which the domain
declares so that its first migration creates it:
#![allow(unused)]
fn main() {
pub fn migrations() -> rind::migrations::Domain {
rind::migrations::domain!("network", schema()).extension("postgis")
}
}
Geography has the rest: the shapes, distances, and how a client sends a point.
Enumerated types
EnumValue holds a value of a PostgreSQL enumerated type (CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')), by its label. It is for a database
that already has such types. For a new model, a Rust enum stored as a
text is usually simpler: see Types of your own.
Files
#![allow(unused)]
fn main() {
#[column(max_length = 200)]
pub photo: Option<rind::db::types::File>, // "photo" character varying(200)
}
A File column holds the key of a file in the storage (a folder or an
S3 bucket), as Django’s FileField holds a path. The bytes are in the
storage, not in the table. In JSON it is {"url": …, "name": …, "size": …}, or null. See Files.
Names of columns
The column has the name of the field. A field whose name is a Rust
keyword is written with r#:
#![allow(unused)]
fn main() {
pub r#type: String, // the column "type"
}
Its path is then Model::type_(), with a trailing underscore, since
type() is not a valid function name.
To give a column another name than its field, there is no option: the field has the column’s name. (Models written from a database keep the database’s names.)
Doc comments
A doc comment on a field is kept by the derive. The serializers and
inputs that send or read the field use it as the field’s description in
the OpenAPI document, as Django’s help_text:
#![allow(unused)]
fn main() {
/// `active`, `maintenance` or `retired`.
#[column(max_length = 12, default = "'active'", index)]
pub status: String,
}
What is not supported
| Django | rind |
|---|---|
TimeField, DurationField | not yet: store minutes or seconds in an integer |
UUIDField | not yet: a String with sql = "uuid" can be neither read nor written (error deserializing column). Store UUIDs as text, or write a type of your own |
PositiveIntegerField | a signed integer and a check |
choices= | a String and the input’s choices(..), or an enum of your own |
db_column= | none: the field has the column’s name |
Next: Column options.