generator

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

Generator

This package handles the actual generation of the Go client files. It handles copying engines and converting templates with a given AST to a Go client ORM file.

Note that there is a lot of special logic around "DMMF" as the design was initially intended for JavaScript, but not for type-safe languages like Go.

Documentation

Overview

Package generator acts as a prisma generator

Index

Constants

View Source
const DefaultPackageName = "db"

Variables

This section is empty.

Functions

func Run

func Run(input *Root) error

Run invokes the generator, which builds the templates and writes to the specified output file.

func Transform

func Transform(input *Root)

Transform builds the AST from the flat DMMF so it can be used properly in templates

Types

type BinaryPaths

type BinaryPaths struct {
	// MigrationEngine (optional)
	MigrationEngine map[string]string `json:"migrationEngine"` // key target, value path
	// QueryEngine (optional)
	QueryEngine map[string]string `json:"queryEngine"`
	// IntrospectionEngine (optional)
	IntrospectionEngine map[string]string `json:"introspectionEngine"`
}

BinaryPaths holds the information of the paths to the Prisma binaries.

type BinaryTarget

type BinaryTarget struct {
	FromEnvVar string `json:"fromEnvVar"`
	Value      string `json:"value"`
}

type Config

type Config struct {
	EngineType        string       `json:"engineType"`
	Package           types.String `json:"package"`
	DisableGitignore  string       `json:"disableGitignore"`
	DisableGoBinaries string       `json:"disableGoBinaries"`
}

Config describes the options for the Prisma Client Go generator

type ConnectorType

type ConnectorType string

ConnectorType describes the Database of this generator.

const (
	ConnectorTypeMySQL      ConnectorType = "mysql"
	ConnectorTypeMongo      ConnectorType = "mongo"
	ConnectorTypeSQLite     ConnectorType = "sqlite"
	ConnectorTypePostgreSQL ConnectorType = "postgresql"
)

ConnectorType values

type Datasource

type Datasource struct {
	Name          types.String  `json:"name"`
	ConnectorType ConnectorType `json:"connectorType"`
	URL           EnvValue      `json:"url"`
	Config        interface{}   `json:"config"`
}

Datasource describes a Prisma data source of any database type.

type EnvValue

type EnvValue struct {
	// FromEnvVar (optional)
	FromEnvVar string `json:"fromEnvVar"`
	Value      string `json:"value"`
}

EnvValue contains a string value and optionally information if, and if yes from where, an env var is used for this value.

type Generator

type Generator struct {
	// Output holds the file path of where the client gets generated in.
	Output        *Value         `json:"output"`
	Name          types.String   `json:"name"`
	Provider      *Value         `json:"provider"`
	Config        Config         `json:"config"`
	BinaryTargets []BinaryTarget `json:"binaryTargets"`
	// PinnedBinaryTarget (optional)
	PinnedBinaryTarget string `json:"pinnedBinaryTarget"`
}

Generator describes a generator defined in the Prisma schema.

type Root

type Root struct {
	Generator       Generator     `json:"generator"`
	OtherGenerators []Generator   `json:"otherGenerators"`
	SchemaPath      string        `json:"schemaPath"`
	DMMF            dmmf.Document `json:"DMMF"`
	Datasources     []Datasource  `json:"datasources"`
	// Datamodel provides the raw string of the Prisma datamodel.
	Datamodel string `json:"datamodel"`
	// BinaryPaths (optional)
	BinaryPaths BinaryPaths    `json:"binaryPaths"`
	AST         *transform.AST `json:"ast"`
}

Root describes the generator output root.

func (*Root) GetEngineType

func (r *Root) GetEngineType() string

type Value

type Value struct {
	FromEnvVar string `json:"fromEnvVar"`
	Value      string `json:"value"`
}

Directories

Path Synopsis
ast

Jump to

Keyboard shortcuts

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