Cerial
Field Types

Int

Int field type in Cerial — whole numbers only, with SurrealDB decimal truncation behavior.

The Int field type represents whole numbers. SurrealDB's int type truncates any decimal portion on storage, so 3.7 becomes 3. Use Int for counts, ages, quantities, and other integer data where fractional values don't make sense.

Schema Syntax

model Inventory {
  id Record @id
  stock Int
  rating Int?
  quantity Int @default(0)
}

Types

DirectionType
Outputnumber
Inputnumber
SurrealDBint

Both Int and Float map to TypeScript number. The difference is at the SurrealDB storage level. See the Number page for a comparison of all three numeric types.

Create & Update

const item = await client.db.Inventory.create({
  data: {
    stock: 150,
    rating: 5,
    quantity: 25,
  },
});

console.log(item.stock);    // 150
console.log(item.quantity);  // 25

// Update
await client.db.Inventory.updateUnique({
  where: { id: item.id },
  data: { stock: 200 },
});

Filtering

Int fields support all numeric comparison operators:

// Comparison
const lowStock = await client.db.Inventory.findMany({
  where: { stock: { lt: 10 } },
});

// Range
const midStock = await client.db.Inventory.findMany({
  where: { stock: { between: [50, 200] } },
});

// Set
const specific = await client.db.Inventory.findMany({
  where: { quantity: { in: [0, 10, 50, 100] } },
});

Available Operators

OperatorDescription
eqEqual to
neqNot equal to
gtGreater than
gteGreater than or equal
ltLess than
lteLess than or equal
betweenWithin a range (inclusive)
inIn a set of values
notInNot in a set of values

Conditional Operators

OperatorAvailable whenDescription
not? or @nullableNegated comparison
isNone? (optional)true = field is absent
isNull@nullabletrue = field is null
isDefinedAlwaystrue = field exists

OrderBy

Int fields support orderBy:

const sorted = await client.db.Inventory.findMany({
  orderBy: { stock: 'desc' },
});

In Objects and Tuples

object Dimensions {
  width Int
  height Int
  depth Int
}

tuple Range {
  min Int,
  max Int
}

model Package {
  id Record @id
  dimensions Dimensions
  weightRange Range
}
const pkg = await client.db.Package.create({
  data: {
    dimensions: { width: 30, height: 20, depth: 15 },
    weightRange: [1, 50],
  },
});

pkg.dimensions.width;   // 30
pkg.weightRange[0];     // 1

Arrays

model Scores {
  id Record @id
  values Int[]
  uniqueValues Int[] @set
}

Int arrays support @set for auto-deduplicated, sorted arrays. They also support @distinct and @sort decorators.

Supported Decorators

DecoratorEffect
@default(value)Default value on create
@defaultAlways(value)Reset to value on every write
@nullableAllow explicit null
@readonlyWrite-once field
@indexDatabase index
@uniqueUnique constraint

On this page