pgsql

package module
v5.7.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2015 License: BSD-3-Clause Imports: 15 Imported by: 0

README

pgsql

Build Status

Works only with go >= 1.1

WARNING: This package is in flux. You should not use it in production yet. API will / might break.

sql generation for postgres

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JoinSql = map[JoinType]string{
	InnerJoinType: "JOIN",
	LeftJoinType:  "LEFT JOIN",
	RightJoinType: "RIGHT JOIN",
	FullJoinType:  "FULL OUTER JOIN",
}
View Source
var Transformer = map[string]func(interface{}) string{
	"value":    escapeValue,
	"sql":      handleSql,
	"%search":  escapeSearchEnd,
	"search%":  escapeSearchStart,
	"%search%": escapeSearchBoth,
}
View Source
var TypeCompatibles = map[Type][]Type{
	IntType:          []Type{IntType},
	IntsType:         []Type{IntsType, TextType},
	StringsType:      []Type{StringsType, TextType},
	BoolsType:        []Type{BoolsType, TextType},
	FloatsType:       []Type{FloatsType, TextType},
	TimeStampsTZType: []Type{TimeStampsTZType, TextType},
	FloatType:        []Type{IntType, FloatType},
	TextType:         []Type{TextType, XmlType},
	BoolType:         []Type{BoolType},
	DateType:         []Type{TextType, DateType, TimeType, TimeStampTZType, TimeStampType},
	TimeType:         []Type{TextType, DateType, TimeType, TimeStampTZType, TimeStampType},
	XmlType:          []Type{XmlType, TextType},
	HtmlType:         []Type{HtmlType, TextType},
	UuidType:         []Type{UuidType, TextType},
	LtreeType:        []Type{LtreeType, TextType},
	TriggerType:      []Type{TriggerType, TextType},
	TimeStampTZType:  []Type{TextType, DateType, TimeType, TimeStampTZType, TimeStampType},
	TimeStampType:    []Type{TextType, DateType, TimeType, TimeStampTZType, TimeStampType},
	JsonType:         []Type{JsonType, TextType},
}
View Source
var TypeConverter = NewTypeConverter()
View Source
var TypeNames = map[Type]string{
	TextType:        "text",
	IntType:         "int",
	FloatType:       "float",
	BoolType:        "bool",
	TimeStampTZType: "timestamptz",
	TimeStampType:   "timestamp",
	DateType:        "date",
	TimeType:        "time",
	XmlType:         "xml",
	HtmlType:        "text",
	IntsType:        "integer[]",
	StringsType:     "character varying[]",
	BoolsType:       "boolean[]",

	FloatsType:       "float[]",
	TimeStampsTZType: "timestamptz[]",
	UuidType:         "uuid",
	LtreeType:        "ltree",
	TriggerType:      "trigger",
	JsonType:         "json",
}

Functions

func Call

func Call(name string, params ...Sqler) (out *callStruct)

func Case

func Case(sqls ...Sqler) (ø *caseStruct)

func Convert

func Convert(in interface{}, out interface{}) (err error)

func Escape

func Escape(in string) (out string)

func IsNotNull

func IsNotNull(s Sqler) *nuller

func IsNull

func IsNull(s Sqler) *nuller

func IsVarChar

func IsVarChar(t Type) bool

is the type a varchar

func MustTableDefinition

func MustTableDefinition(strPtr interface{}) *tableDefinition

func NewPgInterpretedString

func NewPgInterpretedString(s string) (ip *pgInterpretedString)

func NewTypeConverter

func NewTypeConverter() (ø *typeconverter.BasicConverter)

func TableDefinition

func TableDefinition(strPtr interface{}) (td *tableDefinition, err error)

func ToString

func ToString(i interface{}) string

Types

type AsStruct

type AsStruct struct {
	Sqler Sqler
	As    string
	Type  Type
	// contains filtered or unexported fields
}

func As

func As(sq Sqler, as string, typ Type) *AsStruct

func JoinField

func JoinField(js *JoinStruct, f *Field) *AsStruct

func (*AsStruct) QueryField

func (ø *AsStruct) QueryField() string

func (*AsStruct) SetQueryField

func (ø *AsStruct) SetQueryField(f string) *AsStruct

sets the queryField, allows chaining

func (*AsStruct) Sql

func (ø *AsStruct) Sql() string

type Boolser

type Boolser interface {
	Bools() []bool
}

type Comparer

type Comparer struct {
	A    Sqler
	B    Sqler
	Sign string
}

func Equals

func Equals(a interface{}, b interface{}) *Comparer

func EqualsNot

func EqualsNot(a interface{}, b interface{}) *Comparer

func GreaterThan

func GreaterThan(a interface{}, b interface{}) *Comparer

func GreaterThanEqual

func GreaterThanEqual(a interface{}, b interface{}) *Comparer

func LessThan

func LessThan(a interface{}, b interface{}) *Comparer

func LessThanEqual

func LessThanEqual(a interface{}, b interface{}) *Comparer

func Like

func Like(a interface{}, b interface{}) *Comparer

func (*Comparer) Sql

func (ø *Comparer) Sql() SqlType

type CompiledQuery

type CompiledQuery struct {
	//freplace *fastreplace.FReplace
	//*template.Template
	*template.Template
	Query Query
}

func Compile

func Compile(name string, q Query) (c *CompiledQuery, ſ error)

func MustCompile

func MustCompile(name string, q Query) *CompiledQuery

panics on error

type Condition

type Condition struct {
	Conditions []Sqler
	Sign       string
}

func And

func And(sqls ...Sqler) *Condition

func Or

func Or(sqls ...Sqler) *Condition

func (*Condition) Sql

func (ø *Condition) Sql() (s SqlType)

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

type DBComplete

type DBComplete interface {
	DB
	Close() (ſ error)
	Begin() (tx *sql.Tx, ſ error)
}

type Database

type Database struct {
	Name    string
	Schemas []*Schema
}

type DbWrapper

type DbWrapper struct {
	*sync.RWMutex

	Debug bool
	// contains filtered or unexported fields
}

wraps a *sql.DB in order to do x queries at a time, to prevent

pq: too many connections for role "user"

errors to be used with github.com/metakeule/pq (only one global connection)

func Open

func Open(driverName, dataSourceName string) (ø *DbWrapper, ſ error)

func (*DbWrapper) Begin

func (ø *DbWrapper) Begin() (tx *sql.Tx, ſ error)

func (*DbWrapper) Close

func (ø *DbWrapper) Close() (ſ error)

func (*DbWrapper) Exec

func (ø *DbWrapper) Exec(query string, args ...interface{}) (res sql.Result, ſ error)

func (*DbWrapper) Prepare

func (ø *DbWrapper) Prepare(query string) (st *sql.Stmt, ſ error)

func (*DbWrapper) Query

func (ø *DbWrapper) Query(query string, args ...interface{}) (rows *sql.Rows, ſ error)

func (*DbWrapper) QueryRow

func (ø *DbWrapper) QueryRow(query string, args ...interface{}) (r *sql.Row)

type DeleteQuery

type DeleteQuery struct {
	Table *Table
	Where *WhereStruct
	Limit Limit
}

func (*DeleteQuery) Sql

func (ø *DeleteQuery) Sql() (s SqlType)

func (*DeleteQuery) String

func (ø *DeleteQuery) String() string

type Direction

type Direction bool

func (Direction) Sql

func (ø Direction) Sql() (s SqlType)

type Distinct

type Distinct bool

func (Distinct) Sql

func (ø Distinct) Sql() (s SqlType)

type Field

type Field struct {
	Name string

	Default     Sqler
	Type        Type
	Table       *Table
	ForeignKey  *Field
	Selection   SelectionArray
	Validations []FieldValidator
	// contains filtered or unexported fields
}

func NewField

func NewField(name string, options ...interface{}) *Field

func (*Field) Add

func (ø *Field) Add(options ...interface{})

func (*Field) AddValidator

func (ø *Field) AddValidator(v ...FieldValidator)

func (*Field) InSelection

func (ø *Field) InSelection(value interface{}) bool

func (*Field) Is

func (ø *Field) Is(f Flag) bool

checks if a given flag is set, e.g.

Is(NullAllowed)

checks is null is allowed

func (*Field) MustValue

func (ø *Field) MustValue(val interface{}) (tv *TypedValue)

func (*Field) Placeholder

func (ø *Field) Placeholder() Placeholder

func (*Field) QueryField

func (ø *Field) QueryField() string

func (*Field) SetQueryField

func (ø *Field) SetQueryField(f string) *Field

sets the queryField, allows chaining

func (*Field) Sql

func (ø *Field) Sql() SqlType

func (*Field) Validate

func (ø *Field) Validate(value interface{}) (err error)

func (*Field) Value

func (ø *Field) Value(val interface{}) (tv *TypedValue, err error)

return the value in a typed fashion converted to the required postgres type

type FieldInJoin

type FieldInJoin struct {
	*Field
	As string
}

func (*FieldInJoin) Sql

func (ø *FieldInJoin) Sql() SqlType

type FieldValidator

type FieldValidator interface {
	Validate(value interface{}) error
}

type Flag

type Flag int
const (
	NullAllowed     Flag // field may have null values
	PrimaryKey           // field is primary key
	Indexed              // field is indexed
	Unique               // field is unique
	Serial               // field is a serial field
	UuidGenerate         // generate a uuid
	OnDeleteCascade      // fkey is on delete cascade (default: restrict)
)

type Floatser

type Floatser interface {
	Floats() []float64
}

type Function

type Function struct {
	Name     string
	Input    []Type
	Output   Type
	Body     Sqler
	Language Sqler
}

func (*Function) Call

func (ø *Function) Call(p ...Sqler) SqlType

func (*Function) Create

func (ø *Function) Create() SqlType

func (*Function) Sql

func (ø *Function) Sql() SqlType

type GroupByArray

type GroupByArray []*Field

func GroupBy

func GroupBy(f ...*Field) GroupByArray

func (GroupByArray) Sql

func (ø GroupByArray) Sql() SqlType

type InComparer

type InComparer struct {
	A  Sqler
	Bs []Sqler
}

func In

func In(a interface{}, bs ...interface{}) *InComparer

func (*InComparer) Sql

func (ø *InComparer) Sql() SqlType

type Index

type Index struct {
	Name         string
	Unique       bool
	Concurrently bool
	Fields       []*Field
	Table        *Table
	Method       string
}
	CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ name ] ON table [ USING method ]
    ( { column | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )
    [ WITH ( storage_parameter = value [, ... ] ) ]
    [ TABLESPACE tablespace ]
    [ WHERE predicate ]

func (*Index) Create

func (ø *Index) Create() SqlType

func (*Index) Sql

func (ø *Index) Sql() SqlType

type InsertQuery

type InsertQuery struct {
	Table *Table
	Sets  []map[*Field]interface{}
}

func (*InsertQuery) Sql

func (ø *InsertQuery) Sql() (s SqlType)

func (*InsertQuery) SqlError

func (ø *InsertQuery) SqlError() (s SqlType, e error)

func (*InsertQuery) String

func (ø *InsertQuery) String() string

type Intser

type Intser interface {
	Ints() []int
}

type JoinStruct

type JoinStruct struct {
	Table *Table
	As    string
	Type  JoinType
	On    *Comparer
}

func FullJoin

func FullJoin(from *Field, to *Field, as string) *JoinStruct

func Join

func Join(from *Field, to *Field, as string) *JoinStruct

func LeftJoin

func LeftJoin(from *Field, to *Field, as string) *JoinStruct

func RightJoin

func RightJoin(from *Field, to *Field, as string) *JoinStruct

func (*JoinStruct) Field

func (js *JoinStruct) Field(f *Field) *AsStruct

func (*JoinStruct) Sql

func (ø *JoinStruct) Sql() SqlType

type JoinType

type JoinType int
const (
	LeftJoinType JoinType = iota
	RightJoinType
	InnerJoinType
	FullJoinType
)

type Limit

type Limit int

func (Limit) Sql

func (ø Limit) Sql() SqlType

type NullTime

type NullTime struct {
	*time.Time
	Valid bool
}

func (*NullTime) Scan

func (n *NullTime) Scan(value interface{}) (err error)

func (*NullTime) TypedValue

func (n *NullTime) TypedValue() *TypedValue

type Offset

type Offset int

func (Offset) Sql

func (ø Offset) Sql() (s SqlType)

type OrFieldValidator

type OrFieldValidator []FieldValidator

func (OrFieldValidator) Validate

func (ø OrFieldValidator) Validate(value interface{}) (err error)

type OrRowValidator

type OrRowValidator []RowValidator

func (OrRowValidator) ValidateRow

func (ø OrRowValidator) ValidateRow(value map[*Field]interface{}) (err error)

type OrderByStruct

type OrderByStruct struct {
	Sqler
	Direction Direction
}

func OrderBy

func OrderBy(os ...interface{}) (o []*OrderByStruct)

func (*OrderByStruct) Sql

func (ø *OrderByStruct) Sql() SqlType

type Placeholder

type Placeholder interface {
	placeholder.Setter
	Sqler
	Set(val interface{}) placeholder.Setter
	Setf(format string, val ...interface{}) placeholder.Setter
}

type PostDelete

type PostDelete func(*Row) error

type PostGet

type PostGet func(*Row) error

type PostInsert

type PostInsert func(*Row) error

type PostUpdate

type PostUpdate func(*Row) error

type PostValidate

type PostValidate func(*Row) error

type PreDelete

type PreDelete func(*Row) error

type PreGet

type PreGet func(*Row) error

type PreInsert

type PreInsert func(*Row) error

type PreUpdate

type PreUpdate func(*Row) error

type PreValidate

type PreValidate func(*Row) error

type Query

type Query interface {
	Sql() SqlType
	String() string
}

func Delete

func Delete(options ...interface{}) Query

func Insert

func Insert(table *Table, first_row SetArray, rows ...SetArray) Query

func InsertMap

func InsertMap(table *Table, m map[*Field]interface{}) Query

func Select

func Select(options ...interface{}) Query

func Update

func Update(table *Table, options ...interface{}) Query

type Row

type Row struct {
	*Table
	DB DB
	Tx *sql.Tx

	Debug        bool
	LastSql      string
	PreValidate  []PreValidate
	PostValidate []PostValidate
	PreGet       []PreGet
	PostGet      []PostGet
	PreInsert    []PreInsert
	PostInsert   []PostInsert
	PreUpdate    []PreUpdate
	PostUpdate   []PostUpdate
	PreDelete    []PreDelete
	PostDelete   []PostDelete
	// contains filtered or unexported fields
}

func NewRow

func NewRow(db DB, table *Table, hooks ...interface{}) (ø *Row)

func (*Row) AliasValues

func (ø *Row) AliasValues() (vals map[*AsStruct]interface{})

func (*Row) Any

func (ø *Row) Any(options ...interface{}) (r *Row, err error)

return the first result

func (*Row) AsStrings

func (ø *Row) AsStrings() (m map[string]string)

func (*Row) Commit

func (ø *Row) Commit() (ſ error)

func (*Row) Delete

func (ø *Row) Delete() (err error)

func (*Row) Each

func (ø *Row) Each(fn func(*Row) error, options ...interface{}) (err error)

call fn on each row

func (*Row) Exec

func (ø *Row) Exec(query Query, args ...interface{}) (r sql.Result, err error)

func (*Row) Fill

func (ø *Row) Fill(m map[string]interface{}) error

func (*Row) Find

func (ø *Row) Find(options ...interface{}) (rows *Rows, err error)

func (*Row) FindWithArgs

func (ø *Row) FindWithArgs(args []interface{}, options ...interface{}) (rows *Rows, err error)

func (*Row) Get

func (ø *Row) Get(o ...interface{})

the parameters should be given in pairs of *Field and *value

func (*Row) GetString

func (ø *Row) GetString(field interface{}) (s string)

func (*Row) GetStruct

func (ø *Row) GetStruct(tagVal string, s interface{}) (err error)

ro.Get(artist.Id, &a.Id, artist.FirstName, &a.FirstName, artist.LastName, &a.LastName, artist.GalleryArtist, &a.GalleryArtist, artist.Vita, &a.Vita, artist.Area, &ar)

func (*Row) HasId

func (ø *Row) HasId() bool

func (*Row) Id

func (ø *Row) Id() (vals []SqlType)

func (*Row) Insert

func (ø *Row) Insert() (err error)

func (*Row) InsertQuery

func (ø *Row) InsertQuery() Query

func (*Row) IsValid

func (ø *Row) IsValid(f string, value interface{}) bool

TODO: change signature to

IsValid(f string, value interface{}) (error, bool)

then it may be called like this

  if err, is := IsValid(..) ; is {
		// handle validation error
  }

func (*Row) Load

func (ø *Row) Load(ids ...string) (err error)

func (*Row) LoadStruct

func (ø *Row) LoadStruct(tagVal string, structPtr interface{}, ids ...string) error

runs load and puts the result into the struct

func (*Row) Prepare

func (ø *Row) Prepare(query Query) (r *sql.Stmt, err error)

func (*Row) Properties

func (ø *Row) Properties() (m map[string]interface{})

func (*Row) Query

func (ø *Row) Query(query Query, args ...interface{}) (r *sql.Rows, err error)

func (*Row) QueryRow

func (ø *Row) QueryRow(query Query, args ...interface{}) (r *sql.Row)

func (*Row) Reload

func (ø *Row) Reload() (err error)

func (*Row) Reset

func (ø *Row) Reset()

func (*Row) Result

func (ø *Row) Result(tagVal string, structPtr interface{}, findOptions ...interface{}) error

runs any and returns the result into the struct

func (*Row) Rollback

func (ø *Row) Rollback() (ſ error)

func (*Row) Save

func (ø *Row) Save() (err error)

func (*Row) Scan

func (ø *Row) Scan(row *sql.Rows, fields ...interface{}) (err error)

func (*Row) Select

func (ø *Row) Select(objects ...interface{}) (r *sql.Rows, err error)

func (*Row) SelectByStruct

func (ø *Row) SelectByStruct(structPtr interface{}, tagVal string, opts ...interface{}) error

func (*Row) SelectByStructs

func (ø *Row) SelectByStructs(result interface{}, tagVal string, opts ...interface{}) (int, error)

TODO make a compilable version that saves the infos about fieldnumbers etc and allows faster queriing

func (*Row) SelectQuery

func (ø *Row) SelectQuery(objects ...interface{}) (s *SelectQuery)

func (*Row) Set

func (ø *Row) Set(o ...interface{}) (err error)

the parameters should be given in pairs of *Field and value

func (*Row) SetDB

func (ø *Row) SetDB(db DB)

func (*Row) SetDebug

func (ø *Row) SetDebug() *Row

func (*Row) SetId

func (ø *Row) SetId(vals ...string) (err error)

vals must be in the order of ø.PrimaryKey

func (*Row) SetNull

func (ø *Row) SetNull(field *Field)

set field to null

func (*Row) SetTransaction

func (ø *Row) SetTransaction(tx *sql.Tx)

func (*Row) Unset

func (ø *Row) Unset(o ...*Field)

unset the given fields

func (*Row) UnsetDebug

func (ø *Row) UnsetDebug() *Row

func (*Row) Update

func (ø *Row) Update(pkVals ...interface{}) (err error)

has to be invoked directly

func (*Row) UpdateQuery

func (ø *Row) UpdateQuery(pkVals ...interface{}) Query

func (*Row) Validate

func (ø *Row) Validate() (err error)

func (*Row) ValidateAll

func (ø *Row) ValidateAll() (errs map[Sqler]error)

func (*Row) Values

func (ø *Row) Values() (vals map[*Field]interface{})

type RowValidator

type RowValidator interface {
	ValidateRow(value map[*Field]interface{}) error
}

type Rows

type Rows struct {
	*sql.Rows // inherits from *sql.Rows and is fully compatible

	Fields []interface{}
	// contains filtered or unexported fields
}

func (*Rows) ScanRow

func (ø *Rows) ScanRow() (row *Row, ſ error)

scan the result into a row

func (*Rows) ScanStruct

func (ø *Rows) ScanStruct(tagVal string, s interface{}) (ſ error)

scan the result into a struct

type Schema

type Schema struct {
	Name     string
	Database *Database
	Tables   []*Table
}

func NewSchema

func NewSchema(name string, options ...interface{}) *Schema

func (*Schema) AddTable

func (ø *Schema) AddTable(tables ...*Table)

func (*Schema) Sql

func (ø *Schema) Sql() SqlType

type SchemaDB

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

func NewSchemaDB

func NewSchemaDB(db DBComplete, schemaname string) *SchemaDB

func (*SchemaDB) Transaction

func (s *SchemaDB) Transaction(fn func(DB) error) error

Transaction receives a function that gets a transaction and returns an error it starts a transaction, sets the search path to the schemaname

type SearchBoth

type SearchBoth string

func (SearchBoth) Placeholder

func (ø SearchBoth) Placeholder() Placeholder

type SearchEnd

type SearchEnd string

func (SearchEnd) Placeholder

func (ø SearchEnd) Placeholder() Placeholder

type SearchStart

type SearchStart string

func (SearchStart) Placeholder

func (ø SearchStart) Placeholder() Placeholder

type SelectQuery

type SelectQuery struct {
	Distinct        Distinct
	Table           Sqler
	Where           *WhereStruct
	Limit           Limit
	Joins           []*JoinStruct
	Fields          []*Field
	FieldsWithAlias []*AsStruct
	Offset          Offset
	OrderBy         []*OrderByStruct
	GroupBy         GroupByArray
}

func (*SelectQuery) Sql

func (ø *SelectQuery) Sql() (s SqlType)

SELECT #{distinct}

#{fields}

FROM

#{table}

#{joins} #{where} #{group_by} #{order_by} #{limit} #{offset}"

func (*SelectQuery) String

func (ø *SelectQuery) String() string

type SelectionArray

type SelectionArray []interface{}

func Selection

func Selection(o ...interface{}) SelectionArray

type SelectionValidator

type SelectionValidator struct{ *Field }

func (*SelectionValidator) Validate

func (ø *SelectionValidator) Validate(value interface{}) error

type SetArray

type SetArray []interface{}

func Set

func Set(i ...interface{}) (out SetArray)

func (SetArray) Map

func (ø SetArray) Map() (m map[*Field]interface{})

type SqlType

type SqlType string

func Sql

func Sql(s string) SqlType

func Sqlf

func Sqlf(s string, v ...interface{}) SqlType

converts a string with formatting rules to sql string via fmt.Sprintf

func (SqlType) Placeholder

func (ø SqlType) Placeholder() Placeholder

func (SqlType) Sql

func (ø SqlType) Sql() SqlType

func (SqlType) String

func (ø SqlType) String() string

func (SqlType) TypedValue

func (ø SqlType) TypedValue() *TypedValue

type Sqler

type Sqler interface {
	Sql() SqlType
}

func ToSql

func ToSql(i interface{}) Sqler

type Stringer

type Stringer interface {
	String() string
}

type Stringser

type Stringser interface {
	Strings() []string
}

type Table

type Table struct {
	Name   string
	Schema *Schema
	Fields []*Field
	//	PrimaryKeySeq Sqler
	PrimaryKey  []*Field
	Validations []RowValidator
	Constraints []Sqler
}

func NewTable

func NewTable(name string, options ...interface{}) *Table

func (*Table) AddField

func (ø *Table) AddField(fields ...*Field)

func (*Table) AddForeignKeyConstraint

func (ø *Table) AddForeignKeyConstraint(field *Field, onDeleteCascade bool)

func (*Table) AddUnique

func (ø *Table) AddUnique(name string, fields ...*Field)

func (*Table) AddValidator

func (ø *Table) AddValidator(v ...RowValidator)

func (*Table) Create

func (ø *Table) Create() SqlType

func (*Table) Drop

func (ø *Table) Drop() SqlType

func (*Table) DropCascade

func (ø *Table) DropCascade() SqlType

func (*Table) Field

func (ø *Table) Field(name string) (f *Field)

func (*Table) IsPrimaryKey

func (ø *Table) IsPrimaryKey(f *Field) (is bool)

func (*Table) NewField

func (ø *Table) NewField(name string, options ...interface{}) (field *Field)

func (*Table) QueryField

func (ø *Table) QueryField(name string) (f *Field)

func (*Table) Sql

func (ø *Table) Sql() SqlType

func (*Table) Validate

func (ø *Table) Validate(values map[*Field]interface{}) (errs map[Sqler]error)

TODO: handle somehow validations for placeholders

type Timeser

type Timeser interface {
	Times() []time.Time
}

type Trigger

type Trigger struct {
	Name      string
	Condition Sqler
	Table     *Table
	Body      Sqler
}

func (*Trigger) Create

func (ø *Trigger) Create() SqlType

func (*Trigger) Sql

func (ø *Trigger) Sql() SqlType

type Type

type Type int
const (
	NullType Type = iota + 256 // starting from 256 to allow VarChar to have numbers from 1 to 255
	IntType
	FloatType
	TextType
	BoolType
	DateType
	TimeType
	XmlType
	TimeStampTZType
	TimeStampType
	IntsType
	StringsType
	HtmlType
	UuidType
	LtreeType
	TriggerType
	BoolsType
	FloatsType
	TimeStampsTZType
	JsonType
)

func VarChar

func VarChar(i int) Type

func (Type) Default

func (ø Type) Default() interface{}

func (Type) IsCompatible

func (ø Type) IsCompatible(other Type) bool

func (Type) String

func (ø Type) String() string

func (Type) Type

func (ø Type) Type() Type

type TypeValidator

type TypeValidator struct{ *Field }

func (*TypeValidator) Validate

func (ø *TypeValidator) Validate(value interface{}) error

type TypedValue

type TypedValue struct {
	PgType Type
	Value  typeconverter.Stringer
	// contains filtered or unexported fields
}

func (*TypedValue) IsNil

func (ø *TypedValue) IsNil() bool

func (*TypedValue) Placeholder

func (ø *TypedValue) Placeholder() Placeholder

func (*TypedValue) Sql

func (ø *TypedValue) Sql() SqlType

func (*TypedValue) String

func (ø *TypedValue) String() string

func (*TypedValue) Type

func (ø *TypedValue) Type() Type

func (*TypedValue) TypedValue

func (ø *TypedValue) TypedValue() *TypedValue

type Typer

type Typer interface {
	Type() Type
}

type UpdateQuery

type UpdateQuery struct {
	Table  *Table
	Where  *WhereStruct
	Limit  Limit
	Set    map[*Field]interface{}
	SetSql []Sqler
}

func (*UpdateQuery) Sql

func (ø *UpdateQuery) Sql() (s SqlType)

func (*UpdateQuery) SqlError

func (ø *UpdateQuery) SqlError() (s SqlType, e error)

func (*UpdateQuery) String

func (ø *UpdateQuery) String() string

type ValidationError

type ValidationError struct {
	Field   *Field
	Table   *Table
	Err     error
	Details error // error details, not shown to the user
}

func (*ValidationError) Error

func (ve *ValidationError) Error() string

type Valuer

type Valuer interface {
	TypedValue() *TypedValue
}

type WhereStruct

type WhereStruct struct {
	Inner Sqler
}

func Where

func Where(sql Sqler) *WhereStruct

func (WhereStruct) Sql

func (ø WhereStruct) Sql() (s SqlType)

Directories

Path Synopsis
The package shared_query allows different queries from different goroutines to be executed in one single union statement.
The package shared_query allows different queries from different goroutines to be executed in one single union statement.

Jump to

Keyboard shortcuts

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