prisma

package
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements the readers.Reader interface for Prisma schema format

func NewReader

func NewReader(options *readers.ReaderOptions) *Reader

NewReader creates a new Prisma reader with the given options

func (*Reader) ReadDatabase

func (r *Reader) ReadDatabase() (*models.Database, error)

ReadDatabase reads and parses Prisma schema input, returning a Database model

func (*Reader) ReadSchema

func (r *Reader) ReadSchema() (*models.Schema, error)

ReadSchema reads and parses Prisma schema input, returning a Schema model

func (*Reader) ReadTable

func (r *Reader) ReadTable() (*models.Table, error)

ReadTable reads and parses Prisma schema input, returning a Table model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL