The Zuri Standard Library Zuri

Databases

sql.model.casts

import sql.model.casts
Zuri

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.model.casts.* needs import sql.model.casts.

Converts the values that an engine returns into the types that a model's fields hold.

Most values arrive as the type they were stored as. The rest depend on the engine. MySQL has no boolean type and returns 1, and MariaDB stores JSON as text. A cast declared on a field converts such a value, as it's read, into the type the field holds on every engine.

Cast The field holds
bool true or false, from a bool, a number or '0', '1', 'true' and 'false'
integer a whole number, from a number, a numeric string or a decimal
number a number, from a number, a numeric string or a decimal
decimal a sql.Decimal, from a number, a string or a decimal
string text, from anything
json a list or dictionary, from JSON text or one already decoded
date a date.Date, from a date.Date or from ISO 8601 text

A null stays nil whatever the cast, and a value that can't be converted is left as it was read, instead of being lost.

Constants

CASTS

sql.model.CASTS = [...]
Zuri

Every cast a field can declare.

Functions

check_cast()

sql.model.casts.check_cast(kind) -> string
Zuri

Checks kind is a cast there is.

Parameters

  • kind (string)

Returns string

Raises ModelError for any other.

cast()

sql.model.casts.cast(kind: string, value) -> any
Zuri

value as cast kind makes it.

Parameters

  • kind (string) — One of CASTS.
  • value (any)

Returns any


2026, Richard Ore and Zuri contributors