Files
Hein 666eab7cec
Some checks failed
CI / Test (1.24) (push) Failing after -24m41s
CI / Test (1.25) (push) Failing after -24m25s
CI / Lint (push) Failing after -25m49s
CI / Build (push) Successful in -26m3s
Updated Readme files
2025-12-28 10:34:20 +02:00
..
2025-12-19 22:28:24 +02:00
2025-12-28 10:34:20 +02:00

Prisma Reader

Reads Prisma schema files and extracts database schema information.

Overview

The Prisma Reader parses .prisma schema files that define database models using Prisma's schema language and converts them into RelSpec's internal database model representation.

Features

  • Parses Prisma schema syntax
  • Extracts models, fields, and relationships
  • Supports Prisma attributes and directives
  • Handles enums and composite types

Usage

Basic Example

package main

import (
    "fmt"
    "git.warky.dev/wdevs/relspecgo/pkg/readers"
    "git.warky.dev/wdevs/relspecgo/pkg/readers/prisma"
)

func main() {
    options := &readers.ReaderOptions{
        FilePath: "/path/to/schema.prisma",
    }

    reader := prisma.NewReader(options)
    db, err := reader.ReadDatabase()
    if err != nil {
        panic(err)
    }

    fmt.Printf("Found %d schemas\n", len(db.Schemas))
}

CLI Example

# Read Prisma schema and convert to JSON
relspec --input prisma --in-file schema.prisma --output json --out-file schema.json

# Convert Prisma to GORM models
relspec --input prisma --in-file schema.prisma --output gorm --out-file models.go

Example Prisma Schema

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id        Int      @id @default(autoincrement())
  username  String   @unique @db.VarChar(50)
  email     String   @db.VarChar(100)
  createdAt DateTime @default(now()) @map("created_at")

  posts Post[]

  @@map("users")
}

model Post {
  id      Int    @id @default(autoincrement())
  userId  Int    @map("user_id")
  title   String @db.VarChar(200)
  content String @db.Text

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@map("posts")
}

Supported Prisma Attributes

  • @id - Primary key
  • @unique - Unique constraint
  • @default - Default value
  • @map - Column name mapping
  • @@map - Table name mapping
  • @relation - Relationship definition
  • @db.* - Database-specific type annotations

Notes

  • Extracts datasource provider information
  • Supports @@map for custom table names
  • Handles Prisma-specific types and converts them to standard SQL types