generator

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 16 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

func TransformBinaryTarget added in v0.19.0

func TransformBinaryTarget(name string) string

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"`
}

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 Datasource

type Datasource struct {
	Name           types.String `json:"name"`
	Provider       Provider     `json:"provider"`
	ActiveProvider Provider     `json:"activeProvider"`
	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 Provider added in v0.27.0

type Provider string

Provider describes the Database of this datasource.

const (
	ProviderMySQL      Provider = "mysql"
	ProviderMongo      Provider = "mongo"
	ProviderSQLite     Provider = "sqlite"
	ProviderPostgreSQL Provider = "postgresql"
)

Provider values

type Root

type Root struct {
	Generator       Generator   `json:"generator"`
	OtherGenerators []Generator `json:"otherGenerators"`
	SchemaPath      string      `json:"schemaPath"`
	// Version contains the version hash of the Prisma engine
	Version     string        `json:"version"`
	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) EscapedDatamodel added in v0.22.0

func (r *Root) EscapedDatamodel() string

func (*Root) GetDatasourcesJSON added in v0.27.0

func (r *Root) GetDatasourcesJSON() string

func (*Root) GetEngineType

func (r *Root) GetEngineType() string

func (*Root) GetSanitizedDatasourceURL added in v0.27.0

func (r *Root) GetSanitizedDatasourceURL() 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