The type of the fractional indexing configuration
The asynchronous Drizzle database client to use for queries
The configuration for fractional indexing
An enhanced fractional indexing utility with Drizzle-specific asynchronous methods
const db = drizzle(connection);
const taskFraci = drizzleFraci(db, defineDrizzleFraci({
fraciString({ lengthBase: BASE62, digitBase: BASE62 }),
tasks,
tasks.position,
{ userId: tasks.userId },
{ id: tasks.id }
}));
// Get indices for inserting at the beginning of a user's task list
// Note: await is needed since this is asynchronous
const [a, b] = await taskFraci.indicesForFirst({ userId: 123 });
const [newPosition] = taskFraci.generateKeyBetween(a, b);
drizzleFraciSync - The synchronous version of this function
Creates an asynchronous fractional indexing utility for Drizzle ORM. This function enhances a fractional indexing instance with Drizzle-specific methods for retrieving indices based on asynchronous database queries.
This is the asynchronous version that works with all supported database engines. For Bun SQLite, use the drizzleFraciSync function. The API is identical except that methods return Promises instead of direct values.