PocketBase stores all data in SQLite, making UUID v7 TEXT primary keys efficient — lexicographic ordering aligns with SQLite B-tree layout. See UUID v7 in PocketBase for a feature overview and UUID in SQLite for the storage mechanics.

JavaScript SDK — create with UUID v7

import PocketBase from 'pocketbase';
import { v7 as uuidv7 } from 'uuid';

const pb = new PocketBase('http://127.0.0.1:8090');

// Create a record with a UUID v7 custom ID
async function createOrder(customerId: string, total: number) {
  return pb.collection('orders').create({
    id:          uuidv7(),  // UUID v7 — time-ordered, RFC 9562
    customer_id: customerId,
    total,
    status:     'pending',
  });
}

Cursor pagination via REST API

// Keyset pagination on UUID v7 id — no created_at column needed
async function listOrders(cursor?: string, limit = 20) {
  const filter = cursor ? `id > '${cursor}'` : '';
  const result = await pb.collection('orders').getList(1, limit, {
    filter,
    sort: 'id',  // UUID v7 lex sort = chronological
  });

  const nextCursor = result.items.length === limit
    ? result.items.at(-1)?.id
    : null;

  return { items: result.items, nextCursor };
}

Real-time subscription with UUID v7 ordering

let lastSeenId = '';

pb.collection('orders').subscribe('*', (e) => {
  if (e.action === 'create' && e.record.id > lastSeenId) {
    lastSeenId = e.record.id;
    processNewOrder(e.record);
  }
});

// Extract creation time from UUID v7 record ID
function createdAt(id: string): Date {
  const hex = id.replace(/-/g, '').slice(0, 12);
  return new Date(parseInt(hex, 16));
}

Go hook — server-side UUID v7 enforcement

package main

import (
    "log"

    "github.com/google/uuid"
    "github.com/pocketbase/pocketbase"
    "github.com/pocketbase/pocketbase/core"
)

func main() {
    app := pocketbase.New()

    // Assign UUID v7 before creating any orders record
    app.OnRecordCreateRequest("orders").BindFunc(func(e *core.RecordCreateRequestEvent) error {
        if e.Record.Id == "" {
            id, _ := uuid.NewV7()
            e.Record.Id = id.String()
        }
        return e.Next()
    })

    if err := app.Start(); err != nil {
        log.Fatal(err)
    }
}

go.mod dependencies

require (
    github.com/google/uuid          v1.6.0
    github.com/pocketbase/pocketbase v0.22.0
)

UUID v7 vs PocketBase default ID

PropertyUUID v7PocketBase default ID
Format36-char UUID string15-char alphanumeric
Time-orderedYes (millisecond)No (random)
RFC standardRFC 9562Proprietary
Cursor paginationNative (lex sort)Requires created field
Cross-serviceAny UUID systemPocketBase-only

Further reading

External references

Frequently asked questions

Does PocketBase validate custom record IDs?

PocketBase validates that a custom id field is unique but does not enforce a specific format. UUID v7 strings (36 characters, hyphenated) are accepted. PocketBase's own IDs are 15-character alphanumeric strings — UUID v7 custom IDs coexist with the default format; you choose per collection. See UUID v7 in PocketBase.

Can I use UUID v7 for PocketBase cursor pagination?

Yes. PocketBase's getList API accepts filter and sort parameters. Use filter=id>'cursor'&sort=id for cursor pagination. UUID v7 is lexicographically time-ordered — id > cursor is equivalent to created_after(cursor). No separate timestamp column is needed. See UUID v7 for Cursor Pagination.

How do I enforce UUID v7 on the server in PocketBase?

Use PocketBase Go hooks: app.OnRecordCreateRequest("collection").BindFunc(...). In the handler, check if e.Record.Id is empty; if so, generate a UUID v7 with github.com/google/uuid and assign it. This enforces server-side ID generation regardless of client behavior.