pqtgogen

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component uint64

Component bits represents single component that can be generated by the generator.

const (
	// ComponentInsert represents Insert method of a repository.
	ComponentInsert Component = 1 << (64 - 1 - iota)
	// ComponentFind represents Find method of a repository.
	ComponentFind
	// ComponentUpdate represents Update method of a repository.
	ComponentUpdate
	// ComponentUpsert represents Upsert method of a repository.
	ComponentUpsert
	// ComponentCount represents Count method of a repository.
	ComponentCount
	// ComponentDelete represents Delete method of a repository.
	ComponentDelete
	// ComponentHelpers represents all helpers.
	ComponentHelpers

	// ComponentRepository is a bit mask that group all repository methods.
	ComponentRepository = ComponentInsert | ComponentFind | ComponentUpdate | ComponentUpsert | ComponentCount | ComponentDelete
	// ComponentAll is a bit mask that groups all components.
	ComponentAll = ComponentRepository | ComponentHelpers
)

type Generator

type Generator struct {
	// Version represents Postgres database version code will run against.
	Version float64
	// Pkg is the name of package code is generated into.
	// By default it's "main".
	Pkg string
	// Imports allow to pass additional import paths that will be added into generated code.
	Imports []string
	// Plugins that generator will use during generation.
	Plugins []Plugin
	// Components ...
	Components Component
	// contains filtered or unexported fields
}

Generator ...

func (*Generator) Generate

func (g *Generator) Generate(s *pqt.Schema) ([]byte, error)

Generate generates formatted Go code for given schema.

func (*Generator) GenerateTo

func (g *Generator) GenerateTo(s *pqt.Schema, w io.Writer) error

GenerateTo works like generate but it writes into io Writer instead.

type Plugin

type Plugin interface {
	PropertyType(*pqt.Column, int32) string
	WhereClause(*pqt.Column) string
	// SetClause allow to generate alternative code for column for update queries.
	// Available placeholders:
	//
	// 	{{ .selector }} - property of patch object
	// 	{{ .column }} - const that represents given column
	// 	{{ .composer }} - Composer instance
	SetClause(*pqt.Column) string
	ScanClause(*pqt.Column) string
	Static(*pqt.Schema) string
}

Jump to

Keyboard shortcuts

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