dbx

package
v0.0.0-...-72f7963 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Error = errors.NewClass("dbx")

Functions

func RenderCode

func RenderCode(w io.Writer, schema *Schema, dialects []Dialect, lang Language) (
	err error)

func RenderTemplate

func RenderTemplate(tmpl *template.Template, w io.Writer, name string,
	data interface{}) error

func RenderTemplateString

func RenderTemplateString(tmpl *template.Template, name string,
	data interface{}) (string, error)

Types

type BinLoader

type BinLoader func(name string) ([]byte, error)

func (BinLoader) Load

func (b BinLoader) Load(name string) (*template.Template, error)

type Column

type Column struct {
	Table      *Table
	Name       string
	Type       string
	NotNull    bool
	Relation   *Relation
	Updatable  bool
	AutoInsert bool
	AutoUpdate bool
}

func What

func What(columns ...*Column) []*Column

func (*Column) Insertable

func (c *Column) Insertable() bool

func (*Column) IsInt

func (c *Column) IsInt() bool

func (*Column) RelationLeft

func (c *Column) RelationLeft() *Join

func (*Column) RelationRight

func (c *Column) RelationRight() *Join

func (*Column) SQLName

func (c *Column) SQLName() string

func (*Column) String

func (c *Column) String() string

type ColumnCmpColumnParams

type ColumnCmpColumnParams struct {
	Left     *Column
	Right    *Column
	Operator string
}

type ColumnCmpParams

type ColumnCmpParams struct {
	Left     *Column
	Operator string
}

type ColumnInParams

type ColumnInParams struct {
	Left *Column
	In   *SelectParams
}

type ConditionParams

type ConditionParams struct {
	ColumnCmp       *ColumnCmpParams
	ColumnCmpColumn *ColumnCmpColumnParams
	ColumnIn        *ColumnInParams
}

func ColumnEquals

func ColumnEquals(left *Column) *ConditionParams

func ColumnEqualsColumn

func ColumnEqualsColumn(left, right *Column) *ConditionParams

func ColumnIn

func ColumnIn(left *Column, in *SelectParams) *ConditionParams

func Where

func Where(conditions ...*ConditionParams) []*ConditionParams

type DeleteParams

type DeleteParams struct {
	Many       bool
	Table      *Table
	Conditions []*ConditionParams
}

type Dialect

type Dialect interface {
	Name() string
	RenderSchema(schema *Schema) (string, error)
	RenderSelect(params *SelectParams) (string, error)
	RenderCount(params *SelectParams) (string, error)
	RenderDelete(params *DeleteParams) (string, error)
	RenderInsert(params *InsertParams) (string, error)
	RenderUpdate(params *UpdateParams) (string, error)
	SupportsReturning() bool
}

type DirLoader

type DirLoader string

func (DirLoader) Load

func (d DirLoader) Load(name string) (*template.Template, error)

type InsertParams

type InsertParams struct {
	Table   *Table
	Columns []*Column
}

type Join

type Join struct {
	Left  *Column
	Right *Column
}

type JoinParams

type JoinParams struct {
	Left  *Column
	Right *Column
}

func Joins

func Joins(joins ...*Join) (out []*JoinParams)

type Language

type Language interface {
	Name() string
	RenderHeader(w io.Writer, dialects []Dialect, schema *Schema) error
	RenderSelect(w io.Writer, dialects []Dialect, params *SelectParams) error
	RenderCount(w io.Writer, dialects []Dialect, params *SelectParams) error
	RenderDelete(w io.Writer, dialects []Dialect, params *DeleteParams) error
	RenderInsert(w io.Writer, dialects []Dialect, params *InsertParams) error
	RenderUpdate(w io.Writer, dialects []Dialect, params *UpdateParams) error
	RenderFooter(w io.Writer) error
	Format([]byte) ([]byte, error)
}

type Loader

type Loader interface {
	Load(name string) (*template.Template, error)
}

type LoaderFunc

type LoaderFunc func(name string) (*template.Template, error)

func (LoaderFunc) Load

func (fn LoaderFunc) Load(name string) (*template.Template, error)

type Query

type Query struct {
	Table *Table
	Start []*Column
	Joins []*Join
	End   []*Column
}

func (*Query) String

func (q *Query) String() (s string)

type Relation

type Relation struct {
	Column *Column
	Kind   RelationKind
}

type RelationKind

type RelationKind string
const (
	HasA    RelationKind = "has_a"
	OwnedBy RelationKind = "owned_by"
)

type Schema

type Schema struct {
	Tables  []*Table
	Queries []*Query
}

func LoadSchema

func LoadSchema(path string) (schema *Schema, err error)

type SelectParams

type SelectParams struct {
	Many       bool
	What       []*Column
	Table      *Table
	LeftJoins  []*JoinParams
	Conditions []*ConditionParams
	PagedOn    *Column
}

type Table

type Table struct {
	Name       string
	Columns    []*Column
	Unique     [][]*Column
	PrimaryKey []*Column
}

func (*Table) BasicPrimaryKey

func (t *Table) BasicPrimaryKey() *Column

func (*Table) ColumnSetUnique

func (t *Table) ColumnSetUnique(columns []*Column) bool

func (*Table) Depth

func (t *Table) Depth() (depth int)

func (*Table) GetColumn

func (t *Table) GetColumn(name string) *Column

func (*Table) GetColumns

func (t *Table) GetColumns(names ...string) (out []*Column)

func (*Table) InsertableColumns

func (t *Table) InsertableColumns() (out []*Column)

func (*Table) Updatable

func (t *Table) Updatable() bool

func (*Table) UpdatableBy

func (t *Table) UpdatableBy() (out [][]*Column)

func (*Table) UpdatableColumns

func (t *Table) UpdatableColumns() (out []*Column)

type UpdateParams

type UpdateParams struct {
	Table      *Table
	Conditions []*ConditionParams
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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