Database Adapters
Chainbox is built to be database-agnostic. It provides high-level adapters that inject a scoped database client directly into your execution context.
By using ctx.db, you don't have to worry about connection strings, environment variable
management, or client initialization in your logic. Chainbox handles it all for you.
Supabase
PostgreSQL with Row Level Security (RLS) support. Best for SQL-heavy applications.
Firebase
Google Cloud Firestore support. Best for real-time, NoSQL document storage.
Configuration
You can choose your provider in chainbox.config.ts:
export default Config({
database: "firebase" // or "supabase" (default)
});
Database Adapters
When using Supabase, Chainbox forwards the user's JWT to enforce **Row Level Security** at the database level.
Requirements
CHAINBOX_SUPABASE_URLCHAINBOX_SUPABASE_SECRET_KEY
Example Usage
export default async function getTodos(input, ctx) {
const { data } = await ctx.db.from("todos").select("*");
return data;
}
Firebase Adapter (Firestore)
Firebase support uses firebase-admin under the hood to provide secure, administrative
access to your Firestore collections.
Requirements
FIREBASE_PROJECT_IDFIREBASE_CLIENT_EMAILFIREBASE_PRIVATE_KEY
Example Usage
export default async function getDocs(input, ctx) {
const snapshot = await ctx.db.from("my-collection").get();
return snapshot.docs.map(doc => doc.data());
}
Note: While Supabase uses RLS, Firebase in Chainbox currently provides administrative access. You should implement your own identity-based filtering using
ctx.identitywhen needed.