schema

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: BSD-2-Clause Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SqliteIndex = iota
	MysqlIndex
	PostgresIndex
)

Variables

View Source
var AllDialects = []Dialect{Sqlite, Mysql, Postgres}

AllDialects lists all currently-supported dialects.

Functions

This section is empty.

Types

type Dialect

type Dialect interface {
	Index() int
	String() string
	Alias() string

	TableDDL(*TableDescription) string
	FieldDDL(w io.Writer, field *Field, comma string) string
	TruncateDDL(tableName string, force bool) []string
	CreateTableSettings() string
	FieldAsColumn(*Field) string
	InsertHasReturningPhrase() bool

	SplitAndQuote(csv string) string
	Quote(string) string
	QuoteW(w io.Writer, identifier string)
	QuoteWithPlaceholder(w io.Writer, identifier string, j int)
	ReplacePlaceholders(sql string, args []interface{}) string
	Placeholder(name string, j int) string
	Placeholders(n int) string
}
var Mysql Dialect = mysql{}
var Postgres Dialect = postgres{}
var Sqlite Dialect = sqlite{}

func PickDialect

func PickDialect(name string) Dialect

PickDialect finds a dialect that matches by name, ignoring letter case. It returns nil if not found.

type Field

type Field struct {
	Node
	SqlName string
	Encode  SqlEncode
	Tags    Tag
}

func (*Field) IsExported

func (f *Field) IsExported() bool

type FieldList

type FieldList []*Field

func (FieldList) DistinctTypes

func (list FieldList) DistinctTypes() []Type

func (FieldList) FilterNot

func (list FieldList) FilterNot(predicate func(*Field) bool) FieldList

func (FieldList) FormalParams

func (list FieldList) FormalParams() Identifiers

func (FieldList) Names

func (list FieldList) Names() Identifiers

func (FieldList) NoSkipOrPrimary

func (list FieldList) NoSkipOrPrimary() FieldList

func (FieldList) NoSkips

func (list FieldList) NoSkips() FieldList

func (FieldList) NonAuto

func (list FieldList) NonAuto() FieldList

func (FieldList) Pointers

func (list FieldList) Pointers() FieldList

func (FieldList) SqlNames

func (list FieldList) SqlNames() Identifiers

func (FieldList) WhereClauses

func (list FieldList) WhereClauses() Identifiers

type Identifiers

type Identifiers []string

func (Identifiers) MkString

func (ids Identifiers) MkString(sep string) string

func (Identifiers) MkString3

func (ids Identifiers) MkString3(before, separator, after string) string

func (Identifiers) MkString3W

func (ids Identifiers) MkString3W(w io.Writer, before, separator, after string)

func (Identifiers) Quoted

func (ids Identifiers) Quoted(w io.Writer, quoter func(string) string)

type Index

type Index struct {
	Name   string
	Unique bool

	Fields FieldList
}

func (*Index) Columns

func (i *Index) Columns() string

func (*Index) JoinedNames

func (i *Index) JoinedNames(sep string) string

func (*Index) Single

func (i *Index) Single() bool

func (*Index) UniqueStr

func (i *Index) UniqueStr() string

type Node

type Node struct {
	Name   string
	Type   Type
	Parent *Node
}

func (*Node) JoinParts

func (node *Node) JoinParts(delta int, sep string) string

func (*Node) Parts

func (node *Node) Parts() []string

Parts gets the node containment chain as a sequence of names of parts.

type SqlEncode

type SqlEncode int
const (
	ENCNONE SqlEncode = iota
	ENCJSON
	ENCTEXT
	ENCDRIVER // SQL driver uses Scan() & Value() to encode & decode
)

List of vendor-specific keywords

type SqlToken

type SqlToken int
const (
	AUTO_INCREMENT SqlToken = iota
	PRIMARY_KEY
)

List of vendor-specific keywords

type TableDescription

type TableDescription struct {
	Type string
	Name string

	Fields  FieldList
	Index   []*Index
	Primary *Field // compound primaries are not supported
}

func (*TableDescription) ColumnNames

func (table *TableDescription) ColumnNames(withAuto bool) Identifiers

func (*TableDescription) HasLastInsertId

func (t *TableDescription) HasLastInsertId() bool

func (*TableDescription) HasPrimaryKey

func (t *TableDescription) HasPrimaryKey() bool

func (*TableDescription) NumColumnNames

func (t *TableDescription) NumColumnNames(withAuto bool) int

func (*TableDescription) SafePrimary

func (t *TableDescription) SafePrimary() Field

func (*TableDescription) SimpleFields

func (t *TableDescription) SimpleFields() FieldList

type Type

type Type struct {
	PkgPath   string // package name (full path)
	PkgName   string // package name (short name)
	Name      string // name of source code type.
	IsPtr     bool
	IsScanner bool
	IsValuer  bool
	Base      Kind // underlying source code kind.
}

func (Type) NullableValue

func (t Type) NullableValue() string

func (Type) Star

func (t Type) Star() string

func (Type) String

func (t Type) String() string

func (Type) Tag

func (t Type) Tag() string

func (Type) Type

func (t Type) Type() string

type TypeSet

type TypeSet map[Type]struct{}

TypeSet is the primary type that represents a set

func BuildTypeSetFromChan

func BuildTypeSetFromChan(source <-chan Type) TypeSet

BuildTypeSetFromChan constructs a new TypeSet from a channel that supplies a sequence of values until it is closed. The function doesn't return until then.

func ConvertTypeSet

func ConvertTypeSet(values ...interface{}) (TypeSet, bool)

ConvertTypeSet constructs a new set containing the supplied values, if any. The returned boolean will be false if any of the values could not be converted correctly.

func NewTypeSet

func NewTypeSet(values ...Type) TypeSet

NewTypeSet creates and returns a reference to an empty set.

func (TypeSet) Add

func (set TypeSet) Add(i ...Type) TypeSet

Add adds items to the current set, returning the modified set.

func (TypeSet) Append

func (set TypeSet) Append(more ...Type) TypeSet

Union returns a new set with all items in both sets.

func (TypeSet) Cardinality

func (set TypeSet) Cardinality() int

Cardinality returns how many items are currently in the set. This is a synonym for Size.

func (*TypeSet) Clear

func (set *TypeSet) Clear()

Clear clears the entire set to be the empty set.

func (TypeSet) Clone

func (set TypeSet) Clone() TypeSet

Clone returns a shallow copy of the map. It does not clone the underlying elements.

func (TypeSet) Contains

func (set TypeSet) Contains(i Type) bool

Contains determines if a given item is already in the set.

func (TypeSet) ContainsAll

func (set TypeSet) ContainsAll(i ...Type) bool

ContainsAll determines if the given items are all in the set

func (TypeSet) CountBy

func (set TypeSet) CountBy(predicate func(Type) bool) (result int)

CountBy gives the number elements of TypeSet that return true for the passed predicate.

func (TypeSet) Difference

func (set TypeSet) Difference(other TypeSet) TypeSet

Difference returns a new set with items in the current set but not in the other set

func (TypeSet) Equals

func (set TypeSet) Equals(other TypeSet) bool

Equals determines if two sets are equal to each other. If they both are the same size and have the same items they are considered equal. Order of items is not relevent for sets to be equal.

func (TypeSet) Exists

func (set TypeSet) Exists(fn func(Type) bool) bool

Exists applies a predicate function to every element in the set. If the function returns true, the iteration terminates early. The returned value is true if an early return occurred. or false if all elements were visited without finding a match.

func (TypeSet) Filter

func (set TypeSet) Filter(fn func(Type) bool) TypeSet

Filter returns a new TypeSet whose elements return true for func. The original set is not modified

func (TypeSet) FlatMap

func (set TypeSet) FlatMap(fn func(Type) []Type) TypeSet

FlatMap returns a new TypeSet by transforming every element with a function fn that returns zero or more items in a slice. The resulting list may have a different size to the original list. The original list is not modified.

This is a domain-to-range mapping function. For bespoke transformations to other types, copy and modify this method appropriately.

func (TypeSet) Forall

func (set TypeSet) Forall(fn func(Type) bool) bool

Forall applies a predicate function to every element in the set. If the function returns false, the iteration terminates early. The returned value is true if all elements were visited, or false if an early return occurred.

Note that this method can also be used simply as a way to visit every element using a function with some side-effects; such a function must always return true.

func (TypeSet) Foreach

func (set TypeSet) Foreach(fn func(Type))

Foreach iterates over TypeSet and executes the passed func against each element.

func (TypeSet) Intersect

func (set TypeSet) Intersect(other TypeSet) TypeSet

Intersect returns a new set with items that exist only in both sets.

func (TypeSet) IsEmpty

func (set TypeSet) IsEmpty() bool

IsEmpty returns true if the set is empty.

func (TypeSet) IsSequence

func (set TypeSet) IsSequence() bool

IsSequence returns true for lists.

func (TypeSet) IsSet

func (set TypeSet) IsSet() bool

IsSet returns false for lists.

func (TypeSet) IsSubset

func (set TypeSet) IsSubset(other TypeSet) bool

IsSubset determines if every item in the other set is in this set.

func (TypeSet) IsSuperset

func (set TypeSet) IsSuperset(other TypeSet) bool

IsSuperset determines if every item of this set is in the other set.

func (TypeSet) Map

func (set TypeSet) Map(fn func(Type) Type) TypeSet

Map returns a new TypeSet by transforming every element with a function fn. The original set is not modified.

This is a domain-to-range mapping function. For bespoke transformations to other types, copy and modify this method appropriately.

func (TypeSet) MaxBy

func (set TypeSet) MaxBy(less func(Type, Type) bool) Type

MaxBy returns an element of TypeSet containing the maximum value, when compared to other elements using a passed func defining ‘less’. In the case of multiple items being equally maximal, the first such element is returned. Panics if there are no elements.

func (TypeSet) MinBy

func (set TypeSet) MinBy(less func(Type, Type) bool) Type

MinBy returns an element of TypeSet containing the minimum value, when compared to other elements using a passed func defining ‘less’. In the case of multiple items being equally minimal, the first such element is returned. Panics if there are no elements.

func (TypeSet) NonEmpty

func (set TypeSet) NonEmpty() bool

NonEmpty returns true if the set is not empty.

func (TypeSet) Partition

func (set TypeSet) Partition(p func(Type) bool) (TypeSet, TypeSet)

Partition returns two new TypeSets whose elements return true or false for the predicate, p. The first result consists of all elements that satisfy the predicate and the second result consists of all elements that don't. The relative order of the elements in the results is the same as in the original list. The original set is not modified

func (TypeSet) Remove

func (set TypeSet) Remove(i Type)

Remove allows the removal of a single item from the set.

func (TypeSet) Send

func (set TypeSet) Send() <-chan Type

Send returns a channel that will send all the elements in order. A goroutine is created to send the elements; this only terminates when all the elements have been consumed

func (TypeSet) Size

func (set TypeSet) Size() int

Size returns how many items are currently in the set. This is a synonym for Cardinality.

func (TypeSet) SymmetricDifference

func (set TypeSet) SymmetricDifference(other TypeSet) TypeSet

SymmetricDifference returns a new set with items in the current set or the other set but not in both.

func (TypeSet) ToInterfaceSlice

func (set TypeSet) ToInterfaceSlice() []interface{}

ToInterfaceSlice returns the elements of the current set as a slice of arbitrary type.

func (TypeSet) ToSlice

func (set TypeSet) ToSlice() []Type

ToSlice returns the elements of the current set as a slice.

func (TypeSet) Union

func (set TypeSet) Union(other TypeSet) TypeSet

Union returns a new set with all items in both sets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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