PocketBase combines a SQLite database, authentication, file storage, and a real-time REST API in a single Go binary. Its default record IDs are 15-character random alphanumeric strings — not chronologically ordered. UUID v7 as a custom ID gives PocketBase records time-ordered, globally unique identifiers compatible with any UUID-aware tooling. See UUID v7 in PocketBase for the full guide.
JavaScript SDK — create with UUID v7 ID
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 client-generated UUID v7 ID
async function createOrder(customerId: string, total: number) {
const id = uuidv7(); // UUID v7 — encodes creation time
const record = await pb.collection('orders').create({
id, // Custom UUID v7 ID
customer_id: customerId,
total,
status: 'pending',
});
return record;
}
Cursor pagination via REST API
// UUID v7 cursor pagination — no created timestamp 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 lexicographic = 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
pb.collection('orders').subscribe('*', (e) => {
if (e.action === 'create') {
const record = e.record;
// UUID v7 string comparison = chronological ordering
if (!lastSeenId || record.id > lastSeenId) {
lastSeenId = record.id;
processNewOrder(record);
}
}
});
// Extract creation time from UUID v7 ID
function getCreationTime(uuidV7: string): Date {
const hex = uuidV7.replace(/-/g, '').slice(0, 12);
return new Date(parseInt(hex, 16));
}
Go hooks — UUID v7 on server side
// main.go — PocketBase with UUID v7 hook
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 each order create
app.OnRecordCreateRequest("orders").BindFunc(func(e *core.RecordCreateRequestEvent) error {
// Only assign if no custom ID provided
if e.Record.Id == "" {
id, _ := uuid.NewV7()
e.Record.Id = id.String()
}
return e.Next()
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
Further reading
- UUID v7 in PocketBase — Full Guide
- UUID v7 for Cursor Pagination
- UUID v7 in Supabase Realtime
- UUID in SQLite
- UUID in Go
External references
Frequently asked questions
Can I use custom UUID v7 IDs in PocketBase?
Yes. PocketBase allows custom record IDs when creating records via the API. Pass your UUID v7 string as the id field in the request body: pb.collection('orders').create({ id: uuidv7(), ...data }). PocketBase validates that the ID is unique but does not enforce a specific format. See UUID v7 in PocketBase for the full guide.
How does UUID v7 cursor pagination work in PocketBase?
PocketBase's REST API supports filter and sort query parameters. Use filter=id>'cursor_uuid_v7'&sort=id for cursor pagination. UUID v7 is lexicographically ordered, so id > cursor equals created_after(cursor). PocketBase's default @collectionId IDs do not sort chronologically — UUID v7 does. See UUID v7 for Cursor Pagination.
How do I use UUID v7 in PocketBase real-time subscriptions?
PocketBase real-time events include the full record with its id. Subscribe to a collection and filter incoming events by UUID v7 range: if (record.id > lastSeenId) { process(record) }. This gives chronological event processing without a separate created timestamp comparison. See UUID v7 in Supabase Realtime for a comparable real-time pattern.