InsForge
InsForge
Section titled “InsForge”The InsForge adapter wraps the official @insforge/sdk in the same Safe Result
contract as the rest of the toolkit: every input is validated, every call
returns FetchResult<T>, and mass writes are refused — update and delete
require a non-empty filter, so a forgotten where cannot wipe a table. It is
published only as katanakit-js/adapters/insforge.
InsForge covers database, object storage and edge functions. In this project it is the database fallback (the primary data layer is Cloudflare) and an optional peer: install it only when you use the adapter.
1. Install and connect
Section titled “1. Install and connect”bun add @insforge/sdkimport { defineInsforgeConfig } from "katanakit-js/adapters/insforge";
// Server-only admin client (apiKey), or the browser-safe client (anonKey)defineInsforgeConfig({ baseUrl: process.env.INSFORGE_URL!, apiKey: process.env.INSFORGE_API_KEY!,});2. Query and write rows
Section titled “2. Query and write rows”import { useIfSelect, useIfInsert, useIfUpdate, useIfDelete, useIfRpc,} from "katanakit-js/adapters/insforge";
// SELECT — filters, order and limit are typedconst posts = await useIfSelect<{ id: number; title: string }>({ table: "posts", filters: { author_id: 7 }, order: { column: "created_at", ascending: false }, limit: 10,});if (posts.ok) console.log(posts.data);
// INSERT — one or many rowsconst created = await useIfInsert("posts", [{ title: "Hello" }]);
// UPDATE / DELETE — filters are required; a missing filter is a validation errorawait useIfUpdate({ table: "posts", filters: { id: 7 } }, { title: "Updated" });const deleted = await useIfDelete({ table: "posts", filters: { id: 7 } });
// RPC — call a Postgres functionconst total = await useIfRpc<number>({ name: "count_posts", params: { author_id: 7 },});3. Storage buckets
Section titled “3. Storage buckets”import { useIfUpload, useIfDownload, useIfRemove, useIfListObjects, useIfGetPublicUrl,} from "katanakit-js/adapters/insforge";
const ref = { bucket: "covers", path: "post-7.webp" };
const uploaded = await useIfUpload(ref, file); // File / Blob; same path replacesconst blob = await useIfDownload(ref);const objects = await useIfListObjects("covers", { prefix: "post-", limit: 50,});const publicUrl = useIfGetPublicUrl(ref); // synchronous, returns FetchResultif (publicUrl.ok) console.log(publicUrl.data.publicUrl);await useIfRemove(ref);4. Edge functions
Section titled “4. Edge functions”import { useIfInvokeFunction } from "katanakit-js/adapters/insforge";
const result = await useIfInvokeFunction<{ processed: number }>({ name: "resize-images", body: { postId: 7 },});if (result.ok) console.log(result.data.processed);Related
Section titled “Related”- HTTP Client — the shared Safe Result shape.
- Error Handling — normalizing edge-function failures.
- Assistant — the Prisma persistence path when you own the database.