Documentation ¶
Index ¶
- Variables
- func Call(name string, params ...Sqler) (out *callStruct)
- func Case(sqls ...Sqler) (ø *caseStruct)
- func Convert(in interface{}, out interface{}) (err error)
- func Escape(in string) (out string)
- func IsNotNull(s Sqler) *nuller
- func IsNull(s Sqler) *nuller
- func IsVarChar(t Type) bool
- func MustTableDefinition(strPtr interface{}) *tableDefinition
- func NewPgInterpretedString(s string) (ip *pgInterpretedString)
- func NewTypeConverter() (ø *typeconverter.BasicConverter)
- func TableDefinition(strPtr interface{}) (td *tableDefinition, err error)
- func ToString(i interface{}) string
- type AsStruct
- type Boolser
- type Comparer
- func Equals(a interface{}, b interface{}) *Comparer
- func EqualsNot(a interface{}, b interface{}) *Comparer
- func GreaterThan(a interface{}, b interface{}) *Comparer
- func GreaterThanEqual(a interface{}, b interface{}) *Comparer
- func LessThan(a interface{}, b interface{}) *Comparer
- func LessThanEqual(a interface{}, b interface{}) *Comparer
- func Like(a interface{}, b interface{}) *Comparer
- type CompiledQuery
- type Condition
- type DB
- type DBComplete
- type Database
- type DbWrapper
- func (ø *DbWrapper) Begin() (tx *sql.Tx, ſ error)
- func (ø *DbWrapper) Close() (ſ error)
- func (ø *DbWrapper) Exec(query string, args ...interface{}) (res sql.Result, ſ error)
- func (ø *DbWrapper) Prepare(query string) (st *sql.Stmt, ſ error)
- func (ø *DbWrapper) Query(query string, args ...interface{}) (rows *sql.Rows, ſ error)
- func (ø *DbWrapper) QueryRow(query string, args ...interface{}) (r *sql.Row)
- type DeleteQuery
- type Direction
- type Distinct
- type Field
- func (ø *Field) Add(options ...interface{})
- func (ø *Field) AddValidator(v ...FieldValidator)
- func (ø *Field) InSelection(value interface{}) bool
- func (ø *Field) Is(f Flag) bool
- func (ø *Field) MustValue(val interface{}) (tv *TypedValue)
- func (ø *Field) Placeholder() Placeholder
- func (ø *Field) QueryField() string
- func (ø *Field) SetQueryField(f string) *Field
- func (ø *Field) Sql() SqlType
- func (ø *Field) Validate(value interface{}) (err error)
- func (ø *Field) Value(val interface{}) (tv *TypedValue, err error)
- type FieldInJoin
- type FieldValidator
- type Flag
- type Floatser
- type Function
- type GroupByArray
- type InComparer
- type Index
- type InsertQuery
- type Intser
- type JoinStruct
- type JoinType
- type Limit
- type NullTime
- type Offset
- type OrFieldValidator
- type OrRowValidator
- type OrderByStruct
- type Placeholder
- type PostDelete
- type PostGet
- type PostInsert
- type PostUpdate
- type PostValidate
- type PreDelete
- type PreGet
- type PreInsert
- type PreUpdate
- type PreValidate
- type Query
- type Row
- func (ø *Row) AliasValues() (vals map[*AsStruct]interface{})
- func (ø *Row) Any(options ...interface{}) (r *Row, err error)
- func (ø *Row) AsStrings() (m map[string]string)
- func (ø *Row) Commit() (ſ error)
- func (ø *Row) Delete() (err error)
- func (ø *Row) Each(fn func(*Row) error, options ...interface{}) (err error)
- func (ø *Row) Exec(query Query, args ...interface{}) (r sql.Result, err error)
- func (ø *Row) Fill(m map[string]interface{}) error
- func (ø *Row) Find(options ...interface{}) (rows *Rows, err error)
- func (ø *Row) FindWithArgs(args []interface{}, options ...interface{}) (rows *Rows, err error)
- func (ø *Row) Get(o ...interface{})
- func (ø *Row) GetString(field interface{}) (s string)
- func (ø *Row) GetStruct(tagVal string, s interface{}) (err error)
- func (ø *Row) HasId() bool
- func (ø *Row) Id() (vals []SqlType)
- func (ø *Row) Insert() (err error)
- func (ø *Row) InsertQuery() Query
- func (ø *Row) IsValid(f string, value interface{}) bool
- func (ø *Row) Load(ids ...string) (err error)
- func (ø *Row) LoadStruct(tagVal string, structPtr interface{}, ids ...string) error
- func (ø *Row) Prepare(query Query) (r *sql.Stmt, err error)
- func (ø *Row) Properties() (m map[string]interface{})
- func (ø *Row) Query(query Query, args ...interface{}) (r *sql.Rows, err error)
- func (ø *Row) QueryRow(query Query, args ...interface{}) (r *sql.Row)
- func (ø *Row) Reload() (err error)
- func (ø *Row) Reset()
- func (ø *Row) Result(tagVal string, structPtr interface{}, findOptions ...interface{}) error
- func (ø *Row) Rollback() (ſ error)
- func (ø *Row) Save() (err error)
- func (ø *Row) Scan(row *sql.Rows, fields ...interface{}) (err error)
- func (ø *Row) Select(objects ...interface{}) (r *sql.Rows, err error)
- func (ø *Row) SelectByStruct(structPtr interface{}, tagVal string, opts ...interface{}) error
- func (ø *Row) SelectByStructs(result interface{}, tagVal string, opts ...interface{}) (int, error)
- func (ø *Row) SelectQuery(objects ...interface{}) (s *SelectQuery)
- func (ø *Row) Set(o ...interface{}) (err error)
- func (ø *Row) SetDB(db DB)
- func (ø *Row) SetDebug() *Row
- func (ø *Row) SetId(vals ...string) (err error)
- func (ø *Row) SetNull(field *Field)
- func (ø *Row) SetTransaction(tx *sql.Tx)
- func (ø *Row) Unset(o ...*Field)
- func (ø *Row) UnsetDebug() *Row
- func (ø *Row) Update(pkVals ...interface{}) (err error)
- func (ø *Row) UpdateQuery(pkVals ...interface{}) Query
- func (ø *Row) Validate() (err error)
- func (ø *Row) ValidateAll() (errs map[Sqler]error)
- func (ø *Row) Values() (vals map[*Field]interface{})
- type RowValidator
- type Rows
- type Schema
- type SchemaDB
- type SearchBoth
- type SearchEnd
- type SearchStart
- type SelectQuery
- type SelectionArray
- type SelectionValidator
- type SetArray
- type SqlType
- type Sqler
- type Stringer
- type Stringser
- type Table
- func (ø *Table) AddField(fields ...*Field)
- func (ø *Table) AddForeignKeyConstraint(field *Field, onDeleteCascade bool)
- func (ø *Table) AddUnique(name string, fields ...*Field)
- func (ø *Table) AddValidator(v ...RowValidator)
- func (ø *Table) Create() SqlType
- func (ø *Table) Drop() SqlType
- func (ø *Table) DropCascade() SqlType
- func (ø *Table) Field(name string) (f *Field)
- func (ø *Table) IsPrimaryKey(f *Field) (is bool)
- func (ø *Table) NewField(name string, options ...interface{}) (field *Field)
- func (ø *Table) QueryField(name string) (f *Field)
- func (ø *Table) Sql() SqlType
- func (ø *Table) Validate(values map[*Field]interface{}) (errs map[Sqler]error)
- type Timeser
- type Trigger
- type Type
- type TypeValidator
- type TypedValue
- type Typer
- type UpdateQuery
- type ValidationError
- type Valuer
- type WhereStruct
Constants ¶
This section is empty.
Variables ¶
var ASC = Direction(true)
var DESC = Direction(false)
var JoinSql = map[JoinType]string{ InnerJoinType: "JOIN", LeftJoinType: "LEFT JOIN", RightJoinType: "RIGHT JOIN", FullJoinType: "FULL OUTER JOIN", }
var Transformer = map[string]func(interface{}) string{
"value": escapeValue,
"sql": handleSql,
"%search": escapeSearchEnd,
"search%": escapeSearchStart,
"%search%": escapeSearchBoth,
}
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}, }
var TypeConverter = NewTypeConverter()
var TypeDefaults = map[Type]interface{}{ TextType: "", IntType: 0, FloatType: float32(0), BoolType: false, TimeStampTZType: time.Now(), TimeStampType: time.Now(), DateType: time.Now(), TimeType: time.Now(), XmlType: "", HtmlType: "", IntsType: []int{}, StringsType: []string{}, UuidType: "", BoolsType: []bool{}, FloatsType: []float64{}, TimeStampsTZType: []time.Time{}, JsonType: "{}", }
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 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)
Types ¶
type AsStruct ¶
func JoinField ¶
func JoinField(js *JoinStruct, f *Field) *AsStruct
func (*AsStruct) QueryField ¶
func (*AsStruct) SetQueryField ¶
sets the queryField, allows chaining
type Comparer ¶
func GreaterThan ¶
func GreaterThan(a interface{}, b interface{}) *Comparer
func GreaterThanEqual ¶
func GreaterThanEqual(a interface{}, b interface{}) *Comparer
func LessThanEqual ¶
func LessThanEqual(a interface{}, b interface{}) *Comparer
type CompiledQuery ¶
type DbWrapper ¶
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)
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 Field ¶
type Field struct { Name string Default Sqler Type Type Table *Table ForeignKey *Field Selection SelectionArray Validations []FieldValidator // contains filtered or unexported fields }
func (*Field) AddValidator ¶
func (ø *Field) AddValidator(v ...FieldValidator)
func (*Field) InSelection ¶
func (*Field) MustValue ¶
func (ø *Field) MustValue(val interface{}) (tv *TypedValue)
func (*Field) Placeholder ¶
func (ø *Field) Placeholder() Placeholder
func (*Field) QueryField ¶
func (*Field) SetQueryField ¶
sets the queryField, allows chaining
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 ¶
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 GroupByArray ¶
type GroupByArray []*Field
func GroupBy ¶
func GroupBy(f ...*Field) GroupByArray
func (GroupByArray) Sql ¶
func (ø GroupByArray) Sql() SqlType
type InComparer ¶
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 ]
type InsertQuery ¶
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 JoinStruct ¶
func (*JoinStruct) Field ¶
func (js *JoinStruct) Field(f *Field) *AsStruct
func (*JoinStruct) Sql ¶
func (ø *JoinStruct) Sql() SqlType
type NullTime ¶
func (*NullTime) TypedValue ¶
func (n *NullTime) TypedValue() *TypedValue
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 ¶
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 PostInsert ¶
type PostUpdate ¶
type PostValidate ¶
type PreValidate ¶
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 (*Row) AliasValues ¶
func (*Row) FindWithArgs ¶
func (*Row) Get ¶
func (ø *Row) Get(o ...interface{})
the parameters should be given in pairs of *Field and *value
func (*Row) GetStruct ¶
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) InsertQuery ¶
func (*Row) IsValid ¶
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) LoadStruct ¶
runs load and puts the result into the struct
func (*Row) Properties ¶
func (*Row) SelectByStruct ¶
func (*Row) SelectByStructs ¶
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) SetTransaction ¶
func (*Row) UnsetDebug ¶
func (*Row) UpdateQuery ¶
func (*Row) ValidateAll ¶
type RowValidator ¶
type Rows ¶
type Rows struct { *sql.Rows // inherits from *sql.Rows and is fully compatible Fields []interface{} // contains filtered or unexported fields }
func (*Rows) ScanStruct ¶
scan the result into a struct
type SchemaDB ¶
type SchemaDB struct {
// contains filtered or unexported fields
}
func NewSchemaDB ¶
func NewSchemaDB(db DBComplete, schemaname string) *SchemaDB
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 SqlType ¶
type SqlType string
func (SqlType) Placeholder ¶
func (ø SqlType) Placeholder() Placeholder
func (SqlType) TypedValue ¶
func (ø SqlType) TypedValue() *TypedValue
type Table ¶
type Table struct { Name string Schema *Schema Fields []*Field // PrimaryKeySeq Sqler PrimaryKey []*Field Validations []RowValidator Constraints []Sqler }
func (*Table) AddForeignKeyConstraint ¶
func (*Table) AddValidator ¶
func (ø *Table) AddValidator(v ...RowValidator)
func (*Table) DropCascade ¶
func (*Table) IsPrimaryKey ¶
func (*Table) QueryField ¶
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 (Type) IsCompatible ¶
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 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)
Source Files ¶
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. |