npm package: @tako./resume-builder-prisma
Description: Prisma schema and types for Resume persistence
Latest version: 1.0.2

# @tako./resume-builder-prisma

Prisma schema and helpers for persisting Resume data (aligned with [@tako./resume-builder-core](https://www.npmjs.com/package/@tako./resume-builder-core)).

## Install

```bash
npm install @tako./resume-builder-prisma @prisma/client
npm install -D prisma
```

## Adicionar modelos ao seu schema

Para injetar os modelos Resume, Basics, Work, etc. **no schema do seu projeto** (um único schema com seus modelos + resume-builder):

1. Instale o pacote (acima).
2. No diretório raiz do seu projeto, rode:

```bash
npx resume-builder-prisma-add
```

O script detecta seu schema em `prisma/schema.prisma`, `schema.prisma` ou a pasta `prisma/schema/` (multi-file). Em schema único, os modelos são anexados dentro de um bloco marcado com `// @@resume-builder-prisma start` / `end`; em multi-file, é criado `prisma/schema/resume-builder.prisma`.

3. Gere o client e rode as migrações como de costume:

```bash
npx prisma generate
npx prisma migrate dev
```

Assim você usa um único schema no projeto e `prisma generate` / `prisma migrate` normalmente.

## Generate the client (schema separado no pacote)

Point Prisma at this package's schema (from your app root):

```bash
npx prisma generate --schema=node_modules/@tako./resume-builder-prisma/schema.prisma
```

Or use the path helper in code:

```ts
import { getSchemaPath } from "@tako./resume-builder-prisma"
// getSchemaPath() returns the absolute path to schema.prisma
```

Then set `DATABASE_URL` (e.g. SQLite: `file:./dev.db`) and run migrations:

```bash
npx prisma migrate dev --schema=node_modules/@tako./resume-builder-prisma/schema.prisma
```

## Usage

Use `PrismaClient` from `@prisma/client` and the types from this package or core:

```ts
import { PrismaClient } from "@prisma/client"
import { validateResume, type Resume } from "@tako./resume-builder-prisma"

const prisma = new PrismaClient()

// Validate payload from API/form, then persist
const result = validateResume({ basics: { name: "Jane", email: "jane@example.com" } })
if (!result.success) throw new Error("Invalid resume")

const { basics, work } = result.data
const resume = await prisma.resume.create({
  data: {
    basics: {
      create: {
        name: basics.name,
        email: basics.email,
        label: basics.label,
        phone: basics.phone,
        website: basics.website,
        summary: basics.summary,
        location: basics.location ?? undefined,
        profiles: basics.profiles ?? undefined,
      },
    },
    ...(work?.length
      ? {
          work: {
            create: work.map((w) => ({
              company: w.company,
              position: w.position,
              startDate: w.startDate,
              endDate: w.endDate ?? null,
              summary: w.summary ?? null,
              highlights: w.highlights ?? null,
            })),
          },
        }
      : {}),
  },
  include: { basics: true, work: true },
})
```

## Database

Default schema uses **SQLite**. To use PostgreSQL, change in `schema.prisma` (or override in your app):

- `provider = "postgresql"`
- `url = env("DATABASE_URL")` (e.g. `postgresql://user:pass@localhost:5432/db`)

## API

- **getSchemaPath(): string** – path to this package's `schema.prisma`.
- Re-exports **Resume**, **Basics**, **WorkExperience**, **Education**, **Skill**, **Language**, **Project**, **Location**, **Profile**, **ValidateResult** and **validateResume** from `@tako./resume-builder-core`.