Files
Hein b4ff4334cc
Some checks failed
CI / Lint (push) Successful in -27m53s
CI / Test (1.24) (push) Successful in -27m31s
CI / Build (push) Successful in -28m13s
CI / Test (1.25) (push) Failing after 1m11s
Integration Tests / Integration Tests (push) Failing after -28m15s
feat(models): 🎉 Add GUID field to various models
* Introduced GUID field to Database, Domain, DomainTable, Schema, Table, View, Sequence, Column, Index, Relationship, Constraint, Enum, and Script models.
* Updated initialization functions to assign new GUIDs using uuid package.
* Enhanced DCTX reader and writer to utilize GUIDs from models where available.
2026-01-04 19:53:17 +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