Fields
Number Fields Integer, float, and decimal field types
VibORM provides three number field types with different precision characteristics.
Field TypeScript Use Case s.int()numberWhole numbers, counts, IDs s.float()numberFloating-point, approximate decimals s.decimal()numberExact decimals, money, precision math
s. int (); // Required integer
s. int (). nullable (); // Integer | null
s. int (). array (); // Integer[] (native on PG, JSON on MySQL/SQLite)
s. int (). id (). increment (); // Auto-incrementing primary key
s. float (); // Required float
s. float (). nullable (); // Float | null
s. decimal (); // Required decimal
s. decimal (). nullable (); // Decimal | null
All number types share these methods:
s. int ()
. nullable () // Allow NULL
. array () // Array type (native on PG, JSON on MySQL/SQLite)
. id () // Primary key
. unique () // Unique constraint
. default ( 0 ) // Static default
. default (() => 0 ) // Runtime default
. map ( "column_name" ); // Custom column name
PostgreSQL MySQL SQLite
import { TYPES } from "viborm" ;
// Integer types
s. int ( TYPES . PG . INT . SMALLINT ) // -32,768 to 32,767
s. int ( TYPES . PG . INT . INTEGER ) // -2B to 2B (default)
s. int ( TYPES . PG . INT . OID ) // Object identifier
// Float types
s. float ( TYPES . PG . FLOAT . REAL ) // 6 decimal precision
s. float ( TYPES . PG . FLOAT . DOUBLE_PRECISION ) // 15 decimal precision
// Decimal types
s. decimal ( TYPES . PG . DECIMAL . DECIMAL ( 10 , 2 )) // DECIMAL(10,2)
s. decimal ( TYPES . PG . DECIMAL . NUMERIC ( 10 , 2 )) // NUMERIC(10,2)
s. decimal ( TYPES . PG . DECIMAL . MONEY ) // Currency type import { TYPES } from "viborm" ;
// Integer types
s. int ( TYPES . MYSQL . INT . TINYINT ) // -128 to 127
s. int ( TYPES . MYSQL . INT . TINYINT_UNSIGNED ) // 0 to 255
s. int ( TYPES . MYSQL . INT . SMALLINT ) // -32,768 to 32,767
s. int ( TYPES . MYSQL . INT . MEDIUMINT ) // -8M to 8M
s. int ( TYPES . MYSQL . INT . INT ) // -2B to 2B
s. int ( TYPES . MYSQL . INT . INT_UNSIGNED ) // 0 to 4B
s. int ( TYPES . MYSQL . INT . YEAR ) // Year values
// Float types
s. float ( TYPES . MYSQL . FLOAT . FLOAT ) // Single precision
s. float ( TYPES . MYSQL . FLOAT . DOUBLE ) // Double precision
// Decimal types
s. decimal ( TYPES . MYSQL . DECIMAL . DECIMAL ( 10 , 2 )) // DECIMAL(10,2) import { TYPES } from "viborm" ;
s. int ( TYPES . SQLITE . INT . INTEGER ) // INTEGER
s. float ( TYPES . SQLITE . FLOAT . REAL ) // REAL
s. decimal ( TYPES . SQLITE . DECIMAL . REAL ) // REAL (no exact decimal)
Modifier TypeScript PostgreSQL MySQL SQLite s.int()numberINTEGERINTINTEGER.nullable()number | nullINTEGER NULLINT NULLINTEGER NULL.array()number[]INTEGER[]JSONJSON
Modifier TypeScript PostgreSQL MySQL SQLite s.float()numberDOUBLE PRECISIONDOUBLEREAL.nullable()number | nullDOUBLE PRECISION NULLDOUBLE NULLREAL NULL.array()number[]DOUBLE PRECISION[]JSONJSON
Modifier TypeScript PostgreSQL MySQL SQLite s.decimal()numberDECIMAL(65,30)DECIMAL(65,30)REAL.nullable()number | nullDECIMAL NULLDECIMAL NULLREAL NULL.array()number[]DECIMAL[]JSONJSON
// Auto-incrementing ID
const id = s. int (). id (). increment ();
// Age with validation
const age = s. int (). validator (z. number (). min ( 0 ). max ( 150 ));
// Price with exact precision
const price = s. decimal ( TYPES . PG . DECIMAL . DECIMAL ( 10 , 2 ));
// Rating between 1-5
const rating = s. float ()
. nullable ()
. validator (z. number (). min ( 1 ). max ( 5 ));
// View counter with default
const views = s. int (). default ( 0 );
// Latitude/Longitude
const lat = s. float ();
const lng = s. float ();
Use Case Recommended IDs, counts s.int()Money, currency s.decimal() with precisionScientific data s.float()Coordinates s.float()Ratings s.float() or s.decimal()Percentages s.decimal(TYPES.PG.DECIMAL.DECIMAL(5, 2))