dinosql

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingVersion = errors.New("no version number")
View Source
var ErrNoPackageName = errors.New("missing package name")
View Source
var ErrNoPackagePath = errors.New("missing package path")
View Source
var ErrNoPackages = errors.New("no packages")
View Source
var ErrUnknownVersion = errors.New("invalid version number")

Functions

func CommentToMeta

func CommentToMeta(comment string) (map[string]string, string)

func FieldJSONName

func FieldJSONName(columnName, commentName string) string

func FieldName

func FieldName(columnName, commentName string, settings GenerateSettings) string

func Generate

func Generate(r Generateable, settings GenerateSettings) (map[string]string, error)

func HasStarRef

func HasStarRef(cf nodes.ColumnRef) bool

func Imports

func Imports(r Generateable, settings GenerateSettings) func(string) [][]string

func LowerTitle

func LowerTitle(s string) string

func ModelImports

func ModelImports(r Generateable, settings GenerateSettings) [][]string

func ParseCatalog

func ParseCatalog(schema string) (core.Catalog, error)

func ParseMetadata

func ParseMetadata(t string, commentStyle CommentSyntax) (string, string, error)

func QueryImports

func QueryImports(r Generateable, settings GenerateSettings, filename string) [][]string

func ReadSQLFiles

func ReadSQLFiles(path string) ([]string, error)

func RemoveRollbackStatements

func RemoveRollbackStatements(contents string) string

Remove all lines after a rollback comment.

goose: -- +goose Down sql-migrate: -- +migrate Down

func StructName

func StructName(name string, settings GenerateSettings) string

func UsesArrays

func UsesArrays(r Generateable, settings GenerateSettings) bool

func UsesType

func UsesType(r Generateable, typ string, settings GenerateSettings) bool

func Walk

func Walk(f Visitor, node nodes.Node)

Types

type CommentSyntax

type CommentSyntax int
const (
	CommentSyntaxDash CommentSyntax = iota
	CommentSyntaxStar               // Note: this is the only style supported by the MySQL sqlparser
	CommentSyntaxHash
)

type Engine

type Engine string
const (
	EngineMySQL      Engine = "mysql"
	EnginePostgreSQL Engine = "postgresql"
)

type FileErr

type FileErr struct {
	Filename string
	Line     int
	Column   int
	Err      error
}

type GenerateSettings

type GenerateSettings struct {
	Version    string            `json:"version"`
	Packages   []PackageSettings `json:"packages"`
	Overrides  []Override        `json:"overrides,omitempty"`
	Rename     map[string]string `json:"rename,omitempty"`
	PackageMap map[string]PackageSettings
}

func ParseConfig

func ParseConfig(rd io.Reader) (GenerateSettings, error)

func (*GenerateSettings) PopulatePkgMap

func (s *GenerateSettings) PopulatePkgMap() error

type Generateable

type Generateable interface {
	Structs(settings GenerateSettings) []GoStruct
	PkgName() string
	GoQueries(settings GenerateSettings) []GoQuery
	Enums(settings GenerateSettings) []GoEnum
}

type GoConstant

type GoConstant struct {
	Name  string
	Type  string
	Value string
}

type GoEnum

type GoEnum struct {
	Name      string
	Comment   string
	Constants []GoConstant
}

type GoField

type GoField struct {
	Name    string
	Type    string
	Tags    map[string]string
	Comment string
}

func (GoField) Tag

func (gf GoField) Tag() string

type GoQuery

type GoQuery struct {
	Cmd          string
	Comments     []string
	MethodName   string
	FieldName    string
	ConstantName string
	SQL          string
	SourceName   string
	Ret          GoQueryValue
	Arg          GoQueryValue
}

A struct used to generate methods and fields on the Queries struct

type GoQueryValue

type GoQueryValue struct {
	Emit   bool
	Name   string
	Struct *GoStruct
	Typ    string
}

func (GoQueryValue) EmitStruct

func (v GoQueryValue) EmitStruct() bool

func (GoQueryValue) IsStruct

func (v GoQueryValue) IsStruct() bool

func (GoQueryValue) Pair

func (v GoQueryValue) Pair() string

func (GoQueryValue) Params

func (v GoQueryValue) Params() string

func (GoQueryValue) Scan

func (v GoQueryValue) Scan() string

func (GoQueryValue) Type

func (v GoQueryValue) Type() string

type GoStruct

type GoStruct struct {
	Table   core.FQN
	Name    string
	Fields  []GoField
	Comment string
}

type Override

type Override struct {
	// name of the golang type to use, e.g. `github.com/segmentio/ksuid.KSUID`
	GoType string `json:"go_type"`

	// fully qualified name of the Go type, e.g. `github.com/segmentio/ksuid.KSUID`
	PostgresType string `json:"postgres_type"`

	// True if the GoType should override if the maching postgres type is nullable
	Null bool `json:"null"`

	// fully qualified name of the column, e.g. `accounts.id`
	Column string `json:"column"`
	// contains filtered or unexported fields
}

func (*Override) Parse

func (o *Override) Parse() error

type PackageSettings

type PackageSettings struct {
	Name                string     `json:"name"`
	Engine              Engine     `json:"engine,omitempty"`
	Path                string     `json:"path"`
	Schema              string     `json:"schema"`
	Queries             string     `json:"queries"`
	EmitInterface       bool       `json:"emit_interface"`
	EmitJSONTags        bool       `json:"emit_json_tags"`
	EmitPreparedQueries bool       `json:"emit_prepared_queries"`
	Overrides           []Override `json:"overrides"`
}

type Parameter

type Parameter struct {
	Number int
	Column core.Column
}

type ParserErr

type ParserErr struct {
	Errs []FileErr
}

func NewParserErr

func NewParserErr() *ParserErr

func (*ParserErr) Add

func (e *ParserErr) Add(filename, source string, loc int, err error)

func (*ParserErr) Error

func (e *ParserErr) Error() string

type Query

type Query struct {
	SQL      string
	Columns  []core.Column
	Params   []Parameter
	Name     string
	Cmd      string // TODO: Pick a better name. One of: one, many, exec, execrows
	Comments []string

	// XXX: Hack
	Filename string
}

Name and Cmd may be empty Maybe I don't need the SQL string if I have the raw Stmt?

type QueryCatalog

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

func NewQueryCatalog

func NewQueryCatalog(c core.Catalog, with *nodes.WithClause) QueryCatalog

func (QueryCatalog) GetTable

func (qc QueryCatalog) GetTable(fqn core.FQN) (core.Table, *core.Error)

type Result

type Result struct {
	Queries []*Query
	Catalog core.Catalog
	// contains filtered or unexported fields
}

func ParseQueries

func ParseQueries(c core.Catalog, pkg PackageSettings) (*Result, error)

func (Result) Enums

func (r Result) Enums(settings GenerateSettings) []GoEnum

func (Result) GoQueries

func (r Result) GoQueries(settings GenerateSettings) []GoQuery

func (Result) PkgName

func (r Result) PkgName() string

func (Result) Structs

func (r Result) Structs(settings GenerateSettings) []GoStruct

type Visitor

type Visitor interface {
	Visit(nodes.Node) Visitor
}

type VisitorFunc

type VisitorFunc func(nodes.Node)

func (VisitorFunc) Visit

func (vf VisitorFunc) Visit(node nodes.Node) Visitor

Jump to

Keyboard shortcuts

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