@farming-labs/orm

Internal Platforms

Internal platform teams often own models that many product teams consume.

These packages are a strong fit for Farming Labs ORM because the platform team usually wants one durable contract while product teams still want freedom over their final runtime stack.

Common platform-owned domains

Why a shared schema helps

Without a shared contract, every product team tends to drift:

Platform packages often have to support:

That is where the generator and runtime helper story becomes important.

Platform package example

export const orgSchema = defineSchema({
  organization: model({
    table: "organizations",
    fields: {
      id: id(),
      slug: string().unique(),
      name: string(),
      createdAt: datetime().defaultNow(),
    },
  }),
  membership: model({
    table: "memberships",
    fields: {
      id: id(),
      userId: string(),
      organizationId: string().references("organization.id"),
      role: string().default("member"),
    },
  }),
});

Multi-package generation

import { defineConfig } from "@farming-labs/orm-cli";
import { authSchema } from "@acme/auth";
import { billingSchema } from "@acme/billing";
import { orgSchema } from "@acme/org";

export default defineConfig({
  schemas: [authSchema, billingSchema, orgSchema],
  targets: {
    prisma: {
      out: "./generated/prisma/schema.prisma",
      provider: "postgresql",
    },
  },
});

If a platform team wants to render artifacts directly instead of going through the CLI, it can call the generators from the shared schema package:

import { renderDrizzleSchema, renderPrismaSchema, renderSafeSql } from "@farming-labs/orm";

const prisma = renderPrismaSchema(orgSchema, {
  provider: "postgresql",
});

const drizzle = renderDrizzleSchema(orgSchema, {
  dialect: "pg",
});

const sql = renderSafeSql(orgSchema, {
  dialect: "postgres",
});

If a platform-owned service wants to accept a raw client directly:

import { createOrmFromRuntime } from "@farming-labs/orm-runtime";

const orm = await createOrmFromRuntime({
  schema: orgSchema,
  client: database,
});

If the platform package needs to prepare a database in tests, demos, or setup flows:

import { pushSchema } from "@farming-labs/orm-runtime/setup";

await pushSchema({
  schema: orgSchema,
  client: database,
});

Helper map for internal platforms

Why platform teams care

This is one of the highest-leverage uses of the project in a monorepo.