VibORM
Fields

BigInt Field

BigInt field type for large integers

BigInt Field

The BigInt field type represents integers larger than JavaScript's Number.MAX_SAFE_INTEGER (2^53 - 1).

Basic Usage

import { s } from "viborm";

s.bigInt()               // Required bigint
s.bigInt().nullable()    // BigInt | null

Chainable Methods

s.bigInt()
  .nullable()           // Allow NULL
  .id()                 // Primary key
  .unique()             // Unique constraint
  .default(0n)          // Static default
  .default(() => 0n)    // Runtime default
  .map("column_name")   // Custom column name

Native Database Types

import { TYPES } from "viborm";

s.bigInt(TYPES.PG.BIGINT.BIGINT)  // BIGINT
import { TYPES } from "viborm";

s.bigInt(TYPES.MYSQL.BIGINT.BIGINT)           // BIGINT (signed)
s.bigInt(TYPES.MYSQL.BIGINT.BIGINT_UNSIGNED)  // BIGINT UNSIGNED
import { TYPES } from "viborm";

s.bigInt(TYPES.SQLITE.BIGINT.INTEGER)  // INTEGER

Type Mapping

ModifierTypeScriptPostgreSQLMySQLSQLite
s.bigInt()bigintBIGINTBIGINTINTEGER
.nullable()bigint | nullBIGINT NULLBIGINT NULLINTEGER NULL
.array()bigint[]BIGINT[]JSONJSON

Range

TypeRange
BIGINT-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
BIGINT UNSIGNED (MySQL)0 to 18,446,744,073,709,551,615

Examples

// Large counter
const viewCount = s.bigInt().default(0n);

// Twitter-style snowflake ID
const snowflakeId = s.bigInt().id();

// Unix timestamp in milliseconds
const timestampMs = s.bigInt();

// Cryptocurrency amount (in smallest unit)
const satoshis = s.bigInt().default(0n);

Working with BigInt

// Create with bigint literal
await client.post.create({
  data: {
    id: 1234567890123456789n,
    viewCount: 0n,
  }
});

// Filter with bigint
await client.post.findMany({
  where: {
    viewCount: { gte: 1000000n },
  }
});

// Update with bigint
await client.post.update({
  where: { id: 1n },
  data: {
    viewCount: { increment: 1n },
  }
});

When to Use BigInt

Use CaseRecommended
Counts < 9 quadrillions.int() is sufficient
Twitter/Discord IDss.bigInt()
Cryptocurrency amountss.bigInt()
Nanosecond timestampss.bigInt()
Scientific computings.bigInt()

On this page