Skip to content
id

Database Optimization & Binary Conversion

Zero-copy 16-byte Uint8Array binary conversions for MySQL BINARY(16), PostgreSQL UUID, and time-sorted B-Tree index optimization.

1 min read87 words

Storing UUIDs or ULIDs as 36-character strings wastes storage and memory. Converting them to 16-byte binary buffers (BINARY(16) or BYTEA) cuts index size by over 55%, dramatically improves CPU cache locality, and boosts query throughput.

toBinary(id)

Converts a string UUID or ULID into a 16-byte Uint8Array:

js

import { toBinary, uuidv7 } from '@readytools/id';

const id = uuidv7();
const binaryBuffer = toBinary(id);
// Returns: Uint8Array(16) [1, 143, 111, 137, ...]

fromBinary(bytes, type?)

Converts a 16-byte Uint8Array back into a standard formatted string:

js

import { fromBinary } from '@readytools/id';

const uuidString = fromBinary(binaryBuffer, 'uuid');
// Returns: "018f6f89-8d2a-7140-9a3b-586b9e248b11"

const ulidString = fromBinary(binaryBuffer, 'ulid');
// Returns: "01ARZ3NDEKTSV4RRFFQ69G5FAV"

dbId(type?)

Convenience shortcut for generating time-ordered, index-friendly primary keys:

js

import { dbId } from '@readytools/id';

const id1 = dbId('uuidv7'); // Default
const id2 = dbId('ulid');

Previous

Readable Human-Friendly IDs

Next

Collision Risk & Entropy Calculation


Top tools

WorkspaceLinksySEO AnalyzerChromoQR Code Generator

ReadyTools

CareersContactTools
Pricing7 days free
SupportSecurityGuidesDocsBlogUpdatesLaraVault

Select Language

Set theme

ReadyTools

© 2026 ReadyTools. All rights reserved.