PocketBase

PocketBase is a lightweight, open-source database backend. It’s a great choice for small to medium-sized projects. It runs on a local SQLite database. It comes with a built-in admin interface and a REST API.

In Vela, the PocketBase database is configured in hooks.server.ts:

import { handlePocketbase } from '@velastack/pocketbase';
import {
  POCKETBASE_URL,
  POCKETBASE_SUPERUSER_EMAIL,
  POCKETBASE_SUPERUSER_PASSWORD,
} from '$env/static/private';

export const handle = handlePocketbase({
  pocketbaseUrl: POCKETBASE_URL,
  superuserEmail: POCKETBASE_SUPERUSER_EMAIL,
  superuserPassword: POCKETBASE_SUPERUSER_PASSWORD,
})

When running the project, the PocketBase admin interface is available at /admin. The public REST API (if enabled) is available at /api.

Two different clients are available for interacting with the PocketBase database: the admin API and the user-scoped API. These are provided in the locals object in the SvelteKit server context.

export const load = async ({ locals }) => {
  const posts = await locals.admin.collection('posts').getFullList();
  const posts = await locals.pb.collection('posts').getFullList();
  return { posts };
};