Kolaybase + SvelteKit: Backend for Svelte Apps
SvelteKit covers routing and rendering; Kolaybase covers the backend. Use kolaybase-js in load functions and server endpoints to fetch and mutate data.
Install
npm install kolaybase-jsCreate the client
// src/lib/kolaybase.ts
import { createClient } from "kolaybase-js";
import { PUBLIC_KOLAYBASE_PROJECT_ID, PUBLIC_KOLAYBASE_ANON_KEY } from "$env/static/public";
export const kb = createClient({
projectId: PUBLIC_KOLAYBASE_PROJECT_ID,
apiKey: PUBLIC_KOLAYBASE_ANON_KEY,
});Use PUBLIC_ env variables with the anon key for client/load code. Keep service keys in private env variables for server-only logic.
Load data for a route
// src/routes/posts/+page.ts
import { kb } from "$lib/kolaybase";
export async function load() {
const { data } = await kb.from("posts").select("id, title");
return { posts: data ?? [] };
}Works in load functions
Fetch data during SSR or on the client with the same SDK call.
No backend boilerplate
Skip writing endpoints for basic data access — query the database directly.
Auth and storage included
kb.auth and kb.storage cover sign-in and file uploads out of the box.
Frequently asked questions
- Can I use Kolaybase in SvelteKit server endpoints?
- Yes. Create a server-side client with a service key in +server.ts or +page.server.ts for trusted operations, and a public client for the browser.
- Does row-level security still apply?
- Yes. With the anon key, every query is constrained by your PostgreSQL row-level security policies.
Other integrations
Build your SvelteKit backend on Kolaybase
PostgreSQL, auth, storage, and a REST API — running in minutes.