Identifiers
This page discusses the concepts of identifiers in relational models within Better-Core.
Identifier Algorithm
After evaluating UUID v4, UUID v7, Snowflake IDs, and sequential identifiers, and others, we selected ULID as the standard for our database software.
We chose ULID because it delivers sortable, timestamp-aware IDs that cluster sequential writes on disk for better insert performance, requires zero coordination unlike Snowflake IDs, embeds queryable creation time without extra columns,and presents a cleaner, more URL-safe format than UUID v7 - all while being battle-tested in production systems like Discord and Auth0 since 2015.
Branded Identifiers Types
Better-Core provides branded identifier types to help create a type-safe identifier for your models.
import type { } from "better-core";
export type = {
: <"user">;
: string;
: string;
: boolean;
: Date;
: Date;
};
export type = {
: <"session">;
: <"user">;
: Date;
: Date;
: Date;
: string;
: string;
: string;
};Branded identifiers are useful as they provide a type-safe way to identify models, which means that the compiler will show type errors when you try to use an identifier of the wrong type.
// Function that expects a user id
function (: <"user">) {}
// Works!
(.);
// Error!
(session.id);// Function that expects a user or session id
function (: <"user" | "session">) {}
// Works!
(.);
// Works!
(.);
// Error!
('some-random-id');