diff --git a/main.go b/main.go index 22e294c..1bf96c2 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "github.com/jessevdk/go-flags" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" - "github.com/relops/sqlc/sqlc" + "github.com/shutej/sqlc/sqlc" "log" "os" ) diff --git a/meta/types.go b/meta/types.go index db3eeb5..311b343 100644 --- a/meta/types.go +++ b/meta/types.go @@ -1,15 +1,36 @@ package meta +import ( + "reflect" +) + type TypeInfo struct { Prefix string Literal string + Type reflect.Type } var Types = []TypeInfo{ - TypeInfo{Prefix: "String", Literal: "string"}, + TypeInfo{Prefix: "Bool", Literal: "bool"}, + TypeInfo{Prefix: "Date", Literal: "time.Time"}, // TODO(shutej): test + TypeInfo{Prefix: "Datetime", Literal: "time.Time"}, // TODO(shutej): test + TypeInfo{Prefix: "Float32", Literal: "float32"}, + TypeInfo{Prefix: "Float64", Literal: "float64"}, + TypeInfo{Prefix: "Blob", Literal: "[]byte"}, // TODO(shutej): test TypeInfo{Prefix: "Int", Literal: "int"}, TypeInfo{Prefix: "Int64", Literal: "int64"}, - TypeInfo{Prefix: "Time", Literal: "time.Time"}, + TypeInfo{Prefix: "NullBool", Literal: "sql.NullBool"}, + TypeInfo{Prefix: "NullDate", Literal: "NullableDate"}, // TODO(shutej): test + TypeInfo{Prefix: "NullDatetime", Literal: "NullableDatetime"}, // TODO(shutej): test + TypeInfo{Prefix: "NullFloat32", Literal: "sql.NullFloat64"}, // TODO(shutej): test + TypeInfo{Prefix: "NullFloat64", Literal: "sql.NullFloat64"}, + TypeInfo{Prefix: "NullBlob", Literal: "NullableBlob"}, // TODO(shutej): test + TypeInfo{Prefix: "NullInt", Literal: "sql.NullInt64"}, // TODO(shutej): test + TypeInfo{Prefix: "NullInt64", Literal: "sql.NullInt64"}, + TypeInfo{Prefix: "NullString", Literal: "sql.NullString"}, + TypeInfo{Prefix: "NullTime", Literal: "NullableTime"}, // TODO(shutej): test + TypeInfo{Prefix: "String", Literal: "string"}, + TypeInfo{Prefix: "Time", Literal: "time.Time"}, // TODO(shutej): test } type FunctionInfo struct { @@ -27,4 +48,6 @@ var Funcs = []FunctionInfo{ FunctionInfo{Name: "Md5", Expr: "MD5(%s)"}, FunctionInfo{Name: "Lower", Expr: "LOWER(%s)"}, FunctionInfo{Name: "Hex", Expr: "HEX(%s)"}, + FunctionInfo{Name: "Substr2", Expr: "SUBSTR(%s, %v)"}, + FunctionInfo{Name: "Substr3", Expr: "SUBSTR(%s, %v, %v)"}, } diff --git a/sqlc/field_generator.go b/sqlc/field_generator.go index babe34e..4369f2f 100644 --- a/sqlc/field_generator.go +++ b/sqlc/field_generator.go @@ -6,7 +6,7 @@ import ( "bytes" "fmt" log "github.com/cihub/seelog" - "github.com/relops/sqlc/meta" + "github.com/shutej/sqlc/meta" "io/ioutil" "os" "strings" diff --git a/sqlc/fields.go b/sqlc/fields.go index 722e6e9..4830510 100755 --- a/sqlc/fields.go +++ b/sqlc/fields.go @@ -6,827 +6,4594 @@ package sqlc import ( - "time" + "database/sql" + "reflect" + "time" +) + +var ( + typeBool = reflect.TypeOf(false) + typeDate = reflect.TypeOf(time.Unix(0, 0)) + typeDatetime = reflect.TypeOf(time.Unix(0, 0)) + typeFloat32 = reflect.TypeOf(float32(0.)) + typeFloat64 = reflect.TypeOf(float64(0.)) + typeInt = reflect.TypeOf(int(0)) + typeBlob = reflect.TypeOf([]byte{}) + typeInt64 = reflect.TypeOf(int64(0)) + typeNullBool = reflect.TypeOf(sql.NullBool{}) + typeNullDate = reflect.TypeOf(NullableDate{}) + typeNullDatetime = reflect.TypeOf(NullableDatetime{}) + typeNullFloat32 = reflect.TypeOf(sql.NullFloat64{}) + typeNullFloat64 = reflect.TypeOf(sql.NullFloat64{}) + typeNullBlob = reflect.TypeOf(NullableBlob{}) + typeNullInt = reflect.TypeOf(sql.NullInt64{}) + typeNullInt64 = reflect.TypeOf(sql.NullInt64{}) + typeNullString = reflect.TypeOf(sql.NullString{}) + typeNullTime = reflect.TypeOf(NullableTime{}) + typeString = reflect.TypeOf("") + typeTime = reflect.TypeOf(time.Unix(0, 0)) ) type InsertSetStep interface { - - SetString(StringField, string) InsertSetMoreStep - - SetInt(IntField, int) InsertSetMoreStep - - SetInt64(Int64Field, int64) InsertSetMoreStep - - SetTime(TimeField, time.Time) InsertSetMoreStep - + Set(TableField, interface{}) InsertSetMoreStep + + SetBool(BoolField, bool) InsertSetMoreStep + + SetDate(DateField, time.Time) InsertSetMoreStep + + SetDatetime(DatetimeField, time.Time) InsertSetMoreStep + + SetFloat32(Float32Field, float32) InsertSetMoreStep + + SetFloat64(Float64Field, float64) InsertSetMoreStep + + SetBlob(BlobField, []byte) InsertSetMoreStep + + SetInt(IntField, int) InsertSetMoreStep + + SetInt64(Int64Field, int64) InsertSetMoreStep + + SetNullBool(NullBoolField, sql.NullBool) InsertSetMoreStep + + SetNullDate(NullDateField, NullableDate) InsertSetMoreStep + + SetNullDatetime(NullDatetimeField, NullableDatetime) InsertSetMoreStep + + SetNullFloat32(NullFloat32Field, sql.NullFloat64) InsertSetMoreStep + + SetNullFloat64(NullFloat64Field, sql.NullFloat64) InsertSetMoreStep + + SetNullBlob(NullBlobField, NullableBlob) InsertSetMoreStep + + SetNullInt(NullIntField, sql.NullInt64) InsertSetMoreStep + + SetNullInt64(NullInt64Field, sql.NullInt64) InsertSetMoreStep + + SetNullString(NullStringField, sql.NullString) InsertSetMoreStep + + SetNullTime(NullTimeField, NullableTime) InsertSetMoreStep + + SetString(StringField, string) InsertSetMoreStep + + SetTime(TimeField, time.Time) InsertSetMoreStep + +} + +type UpdateSetStep interface { + Set(TableField, interface{}) UpdateSetMoreStep + + SetBool(BoolField, bool) UpdateSetMoreStep + + SetDate(DateField, time.Time) UpdateSetMoreStep + + SetDatetime(DatetimeField, time.Time) UpdateSetMoreStep + + SetFloat32(Float32Field, float32) UpdateSetMoreStep + + SetFloat64(Float64Field, float64) UpdateSetMoreStep + + SetBlob(BlobField, []byte) UpdateSetMoreStep + + SetInt(IntField, int) UpdateSetMoreStep + + SetInt64(Int64Field, int64) UpdateSetMoreStep + + SetNullBool(NullBoolField, sql.NullBool) UpdateSetMoreStep + + SetNullDate(NullDateField, NullableDate) UpdateSetMoreStep + + SetNullDatetime(NullDatetimeField, NullableDatetime) UpdateSetMoreStep + + SetNullFloat32(NullFloat32Field, sql.NullFloat64) UpdateSetMoreStep + + SetNullFloat64(NullFloat64Field, sql.NullFloat64) UpdateSetMoreStep + + SetNullBlob(NullBlobField, NullableBlob) UpdateSetMoreStep + + SetNullInt(NullIntField, sql.NullInt64) UpdateSetMoreStep + + SetNullInt64(NullInt64Field, sql.NullInt64) UpdateSetMoreStep + + SetNullString(NullStringField, sql.NullString) UpdateSetMoreStep + + SetNullTime(NullTimeField, NullableTime) UpdateSetMoreStep + + SetString(StringField, string) UpdateSetMoreStep + + SetTime(TimeField, time.Time) UpdateSetMoreStep + +} + + +func (i *insert) SetBool(f BoolField, v bool) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetDate(f DateField, v time.Time) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetDatetime(f DatetimeField, v time.Time) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetFloat32(f Float32Field, v float32) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetFloat64(f Float64Field, v float64) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetBlob(f BlobField, v []byte) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetInt(f IntField, v int) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetInt64(f Int64Field, v int64) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullBool(f NullBoolField, v sql.NullBool) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullDate(f NullDateField, v NullableDate) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullDatetime(f NullDatetimeField, v NullableDatetime) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullFloat32(f NullFloat32Field, v sql.NullFloat64) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullFloat64(f NullFloat64Field, v sql.NullFloat64) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullBlob(f NullBlobField, v NullableBlob) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullInt(f NullIntField, v sql.NullInt64) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullInt64(f NullInt64Field, v sql.NullInt64) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullString(f NullStringField, v sql.NullString) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetNullTime(f NullTimeField, v NullableTime) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetString(f StringField, v string) InsertSetMoreStep { + return i.Set(f, v) +} + +func (i *insert) SetTime(f TimeField, v time.Time) InsertSetMoreStep { + return i.Set(f, v) +} + + + +func (u *update) SetBool(f BoolField, v bool) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetDate(f DateField, v time.Time) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetDatetime(f DatetimeField, v time.Time) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetFloat32(f Float32Field, v float32) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetFloat64(f Float64Field, v float64) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetBlob(f BlobField, v []byte) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetInt(f IntField, v int) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetInt64(f Int64Field, v int64) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullBool(f NullBoolField, v sql.NullBool) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullDate(f NullDateField, v NullableDate) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullDatetime(f NullDatetimeField, v NullableDatetime) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullFloat32(f NullFloat32Field, v sql.NullFloat64) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullFloat64(f NullFloat64Field, v sql.NullFloat64) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullBlob(f NullBlobField, v NullableBlob) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullInt(f NullIntField, v sql.NullInt64) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullInt64(f NullInt64Field, v sql.NullInt64) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullString(f NullStringField, v sql.NullString) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetNullTime(f NullTimeField, v NullableTime) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetString(f StringField, v string) UpdateSetMoreStep { + return u.Set(f, v) +} + +func (u *update) SetTime(f TimeField, v time.Time) UpdateSetMoreStep { + return u.Set(f, v) +} + + +///// + +type Reflectable interface { + + BoolField(name string) BoolField + + DateField(name string) DateField + + DatetimeField(name string) DatetimeField + + Float32Field(name string) Float32Field + + Float64Field(name string) Float64Field + + BlobField(name string) BlobField + + IntField(name string) IntField + + Int64Field(name string) Int64Field + + NullBoolField(name string) NullBoolField + + NullDateField(name string) NullDateField + + NullDatetimeField(name string) NullDatetimeField + + NullFloat32Field(name string) NullFloat32Field + + NullFloat64Field(name string) NullFloat64Field + + NullBlobField(name string) NullBlobField + + NullIntField(name string) NullIntField + + NullInt64Field(name string) NullInt64Field + + NullStringField(name string) NullStringField + + NullTimeField(name string) NullTimeField + + StringField(name string) StringField + + TimeField(name string) TimeField + +} + +type Functional interface { + + Avg() Field + + Max() Field + + Min() Field + + Ceil() Field + + Div(_0 interface{}) Field + + Cast(_0 interface{}) Field + + Md5() Field + + Lower() Field + + Hex() Field + + Substr2(_0 interface{}) Field + + Substr3(_0,_1 interface{}) Field + +} + + +func (s *selection) BoolField(name string) BoolField { + return &boolField{name: name} +} +func (t table) BoolField(name string) BoolField { + return &boolField{name: name, selection: t} +} + +func (s *selection) DateField(name string) DateField { + return &dateField{name: name} +} +func (t table) DateField(name string) DateField { + return &dateField{name: name, selection: t} +} + +func (s *selection) DatetimeField(name string) DatetimeField { + return &datetimeField{name: name} +} +func (t table) DatetimeField(name string) DatetimeField { + return &datetimeField{name: name, selection: t} +} + +func (s *selection) Float32Field(name string) Float32Field { + return &float32Field{name: name} +} +func (t table) Float32Field(name string) Float32Field { + return &float32Field{name: name, selection: t} +} + +func (s *selection) Float64Field(name string) Float64Field { + return &float64Field{name: name} +} +func (t table) Float64Field(name string) Float64Field { + return &float64Field{name: name, selection: t} +} + +func (s *selection) BlobField(name string) BlobField { + return &blobField{name: name} +} +func (t table) BlobField(name string) BlobField { + return &blobField{name: name, selection: t} +} + +func (s *selection) IntField(name string) IntField { + return &intField{name: name} +} +func (t table) IntField(name string) IntField { + return &intField{name: name, selection: t} +} + +func (s *selection) Int64Field(name string) Int64Field { + return &int64Field{name: name} +} +func (t table) Int64Field(name string) Int64Field { + return &int64Field{name: name, selection: t} +} + +func (s *selection) NullBoolField(name string) NullBoolField { + return &nullboolField{name: name} +} +func (t table) NullBoolField(name string) NullBoolField { + return &nullboolField{name: name, selection: t} +} + +func (s *selection) NullDateField(name string) NullDateField { + return &nulldateField{name: name} +} +func (t table) NullDateField(name string) NullDateField { + return &nulldateField{name: name, selection: t} +} + +func (s *selection) NullDatetimeField(name string) NullDatetimeField { + return &nulldatetimeField{name: name} +} +func (t table) NullDatetimeField(name string) NullDatetimeField { + return &nulldatetimeField{name: name, selection: t} +} + +func (s *selection) NullFloat32Field(name string) NullFloat32Field { + return &nullfloat32Field{name: name} +} +func (t table) NullFloat32Field(name string) NullFloat32Field { + return &nullfloat32Field{name: name, selection: t} +} + +func (s *selection) NullFloat64Field(name string) NullFloat64Field { + return &nullfloat64Field{name: name} +} +func (t table) NullFloat64Field(name string) NullFloat64Field { + return &nullfloat64Field{name: name, selection: t} +} + +func (s *selection) NullBlobField(name string) NullBlobField { + return &nullblobField{name: name} +} +func (t table) NullBlobField(name string) NullBlobField { + return &nullblobField{name: name, selection: t} +} + +func (s *selection) NullIntField(name string) NullIntField { + return &nullintField{name: name} +} +func (t table) NullIntField(name string) NullIntField { + return &nullintField{name: name, selection: t} +} + +func (s *selection) NullInt64Field(name string) NullInt64Field { + return &nullint64Field{name: name} +} +func (t table) NullInt64Field(name string) NullInt64Field { + return &nullint64Field{name: name, selection: t} +} + +func (s *selection) NullStringField(name string) NullStringField { + return &nullstringField{name: name} +} +func (t table) NullStringField(name string) NullStringField { + return &nullstringField{name: name, selection: t} +} + +func (s *selection) NullTimeField(name string) NullTimeField { + return &nulltimeField{name: name} +} +func (t table) NullTimeField(name string) NullTimeField { + return &nulltimeField{name: name, selection: t} +} + +func (s *selection) StringField(name string) StringField { + return &stringField{name: name} +} +func (t table) StringField(name string) StringField { + return &stringField{name: name, selection: t} +} + +func (s *selection) TimeField(name string) TimeField { + return &timeField{name: name} +} +func (t table) TimeField(name string) TimeField { + return &timeField{name: name, selection: t} +} + + +///// + + + +type boolField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type BoolField interface { + TableField + + Eq(value bool) Condition + IsEq(value BoolField) JoinCondition + + Gt(value bool) Condition + IsGt(value BoolField) JoinCondition + + Ge(value bool) Condition + IsGe(value BoolField) JoinCondition + + Lt(value bool) Condition + IsLt(value BoolField) JoinCondition + + Le(value bool) Condition + IsLe(value BoolField) JoinCondition + +} + +func (c *boolField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *boolField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &boolField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &boolField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *boolField) As(alias string) Field { + return &boolField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *boolField) Alias() string { + return c.alias +} + +func (c *boolField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *boolField) Name() string { + return c.name +} + +func (c *boolField) Type() reflect.Type { + return typeBool +} + +func (c *boolField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *boolField) Eq(pred bool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *boolField) IsEq(pred BoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *boolField) Gt(pred bool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *boolField) IsGt(pred BoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *boolField) Ge(pred bool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *boolField) IsGe(pred BoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *boolField) Lt(pred bool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *boolField) IsLt(pred BoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *boolField) Le(pred bool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *boolField) IsLe(pred BoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Bool(s Selectable, name string) BoolField { + return &boolField{name: name, selection: s} +} + +////// + + +func (c *boolField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *boolField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *boolField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *boolField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *boolField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *boolField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *boolField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *boolField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *boolField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *boolField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *boolField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type dateField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type DateField interface { + TableField + + Eq(value time.Time) Condition + IsEq(value DateField) JoinCondition + + Gt(value time.Time) Condition + IsGt(value DateField) JoinCondition + + Ge(value time.Time) Condition + IsGe(value DateField) JoinCondition + + Lt(value time.Time) Condition + IsLt(value DateField) JoinCondition + + Le(value time.Time) Condition + IsLe(value DateField) JoinCondition + +} + +func (c *dateField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *dateField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &dateField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &dateField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *dateField) As(alias string) Field { + return &dateField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *dateField) Alias() string { + return c.alias +} + +func (c *dateField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *dateField) Name() string { + return c.name +} + +func (c *dateField) Type() reflect.Type { + return typeDate +} + +func (c *dateField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *dateField) Eq(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *dateField) IsEq(pred DateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *dateField) Gt(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *dateField) IsGt(pred DateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *dateField) Ge(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *dateField) IsGe(pred DateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *dateField) Lt(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *dateField) IsLt(pred DateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *dateField) Le(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *dateField) IsLe(pred DateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Date(s Selectable, name string) DateField { + return &dateField{name: name, selection: s} +} + +////// + + +func (c *dateField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *dateField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *dateField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *dateField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *dateField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *dateField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *dateField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *dateField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *dateField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *dateField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *dateField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type datetimeField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type DatetimeField interface { + TableField + + Eq(value time.Time) Condition + IsEq(value DatetimeField) JoinCondition + + Gt(value time.Time) Condition + IsGt(value DatetimeField) JoinCondition + + Ge(value time.Time) Condition + IsGe(value DatetimeField) JoinCondition + + Lt(value time.Time) Condition + IsLt(value DatetimeField) JoinCondition + + Le(value time.Time) Condition + IsLe(value DatetimeField) JoinCondition + +} + +func (c *datetimeField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *datetimeField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &datetimeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &datetimeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *datetimeField) As(alias string) Field { + return &datetimeField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *datetimeField) Alias() string { + return c.alias +} + +func (c *datetimeField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *datetimeField) Name() string { + return c.name +} + +func (c *datetimeField) Type() reflect.Type { + return typeDatetime +} + +func (c *datetimeField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *datetimeField) Eq(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *datetimeField) IsEq(pred DatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *datetimeField) Gt(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *datetimeField) IsGt(pred DatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *datetimeField) Ge(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *datetimeField) IsGe(pred DatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *datetimeField) Lt(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *datetimeField) IsLt(pred DatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *datetimeField) Le(pred time.Time) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *datetimeField) IsLe(pred DatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Datetime(s Selectable, name string) DatetimeField { + return &datetimeField{name: name, selection: s} +} + +////// + + +func (c *datetimeField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *datetimeField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *datetimeField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *datetimeField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *datetimeField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *datetimeField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *datetimeField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *datetimeField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *datetimeField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *datetimeField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *datetimeField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type float32Field struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type Float32Field interface { + TableField + + Eq(value float32) Condition + IsEq(value Float32Field) JoinCondition + + Gt(value float32) Condition + IsGt(value Float32Field) JoinCondition + + Ge(value float32) Condition + IsGe(value Float32Field) JoinCondition + + Lt(value float32) Condition + IsLt(value Float32Field) JoinCondition + + Le(value float32) Condition + IsLe(value Float32Field) JoinCondition + +} + +func (c *float32Field) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *float32Field) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &float32Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &float32Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *float32Field) As(alias string) Field { + return &float32Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *float32Field) Alias() string { + return c.alias +} + +func (c *float32Field) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *float32Field) Name() string { + return c.name +} + +func (c *float32Field) Type() reflect.Type { + return typeFloat32 +} + +func (c *float32Field) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *float32Field) Eq(pred float32) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *float32Field) IsEq(pred Float32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *float32Field) Gt(pred float32) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *float32Field) IsGt(pred Float32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *float32Field) Ge(pred float32) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *float32Field) IsGe(pred Float32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *float32Field) Lt(pred float32) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *float32Field) IsLt(pred Float32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *float32Field) Le(pred float32) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *float32Field) IsLe(pred Float32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Float32(s Selectable, name string) Float32Field { + return &float32Field{name: name, selection: s} +} + +////// + + +func (c *float32Field) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *float32Field) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *float32Field) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *float32Field) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *float32Field) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *float32Field) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *float32Field) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *float32Field) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *float32Field) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *float32Field) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *float32Field) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type float64Field struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type Float64Field interface { + TableField + + Eq(value float64) Condition + IsEq(value Float64Field) JoinCondition + + Gt(value float64) Condition + IsGt(value Float64Field) JoinCondition + + Ge(value float64) Condition + IsGe(value Float64Field) JoinCondition + + Lt(value float64) Condition + IsLt(value Float64Field) JoinCondition + + Le(value float64) Condition + IsLe(value Float64Field) JoinCondition + +} + +func (c *float64Field) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *float64Field) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &float64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &float64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *float64Field) As(alias string) Field { + return &float64Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *float64Field) Alias() string { + return c.alias +} + +func (c *float64Field) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *float64Field) Name() string { + return c.name +} + +func (c *float64Field) Type() reflect.Type { + return typeFloat64 +} + +func (c *float64Field) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *float64Field) Eq(pred float64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *float64Field) IsEq(pred Float64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *float64Field) Gt(pred float64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *float64Field) IsGt(pred Float64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *float64Field) Ge(pred float64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *float64Field) IsGe(pred Float64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *float64Field) Lt(pred float64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *float64Field) IsLt(pred Float64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *float64Field) Le(pred float64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *float64Field) IsLe(pred Float64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Float64(s Selectable, name string) Float64Field { + return &float64Field{name: name, selection: s} +} + +////// + + +func (c *float64Field) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *float64Field) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *float64Field) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *float64Field) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *float64Field) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *float64Field) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *float64Field) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *float64Field) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *float64Field) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *float64Field) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *float64Field) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type blobField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type BlobField interface { + TableField + + Eq(value []byte) Condition + IsEq(value BlobField) JoinCondition + + Gt(value []byte) Condition + IsGt(value BlobField) JoinCondition + + Ge(value []byte) Condition + IsGe(value BlobField) JoinCondition + + Lt(value []byte) Condition + IsLt(value BlobField) JoinCondition + + Le(value []byte) Condition + IsLe(value BlobField) JoinCondition + +} + +func (c *blobField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *blobField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &blobField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &blobField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *blobField) As(alias string) Field { + return &blobField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *blobField) Alias() string { + return c.alias +} + +func (c *blobField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *blobField) Name() string { + return c.name +} + +func (c *blobField) Type() reflect.Type { + return typeBlob +} + +func (c *blobField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *blobField) Eq(pred []byte) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *blobField) IsEq(pred BlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *blobField) Gt(pred []byte) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *blobField) IsGt(pred BlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *blobField) Ge(pred []byte) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *blobField) IsGe(pred BlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *blobField) Lt(pred []byte) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *blobField) IsLt(pred BlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *blobField) Le(pred []byte) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *blobField) IsLe(pred BlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Blob(s Selectable, name string) BlobField { + return &blobField{name: name, selection: s} +} + +////// + + +func (c *blobField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *blobField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *blobField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *blobField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *blobField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *blobField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *blobField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *blobField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *blobField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *blobField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *blobField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type intField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type IntField interface { + TableField + + Eq(value int) Condition + IsEq(value IntField) JoinCondition + + Gt(value int) Condition + IsGt(value IntField) JoinCondition + + Ge(value int) Condition + IsGe(value IntField) JoinCondition + + Lt(value int) Condition + IsLt(value IntField) JoinCondition + + Le(value int) Condition + IsLe(value IntField) JoinCondition + +} + +func (c *intField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *intField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &intField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &intField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *intField) As(alias string) Field { + return &intField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *intField) Alias() string { + return c.alias +} + +func (c *intField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *intField) Name() string { + return c.name +} + +func (c *intField) Type() reflect.Type { + return typeInt +} + +func (c *intField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *intField) Eq(pred int) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *intField) IsEq(pred IntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *intField) Gt(pred int) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *intField) IsGt(pred IntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *intField) Ge(pred int) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *intField) IsGe(pred IntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *intField) Lt(pred int) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *intField) IsLt(pred IntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *intField) Le(pred int) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *intField) IsLe(pred IntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Int(s Selectable, name string) IntField { + return &intField{name: name, selection: s} +} + +////// + + +func (c *intField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *intField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *intField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *intField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *intField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *intField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *intField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *intField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *intField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *intField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *intField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type int64Field struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type Int64Field interface { + TableField + + Eq(value int64) Condition + IsEq(value Int64Field) JoinCondition + + Gt(value int64) Condition + IsGt(value Int64Field) JoinCondition + + Ge(value int64) Condition + IsGe(value Int64Field) JoinCondition + + Lt(value int64) Condition + IsLt(value Int64Field) JoinCondition + + Le(value int64) Condition + IsLe(value Int64Field) JoinCondition + +} + +func (c *int64Field) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *int64Field) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &int64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &int64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *int64Field) As(alias string) Field { + return &int64Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *int64Field) Alias() string { + return c.alias +} + +func (c *int64Field) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *int64Field) Name() string { + return c.name +} + +func (c *int64Field) Type() reflect.Type { + return typeInt64 +} + +func (c *int64Field) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *int64Field) Eq(pred int64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *int64Field) IsEq(pred Int64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *int64Field) Gt(pred int64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *int64Field) IsGt(pred Int64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *int64Field) Ge(pred int64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *int64Field) IsGe(pred Int64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *int64Field) Lt(pred int64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *int64Field) IsLt(pred Int64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *int64Field) Le(pred int64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *int64Field) IsLe(pred Int64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func Int64(s Selectable, name string) Int64Field { + return &int64Field{name: name, selection: s} +} + +////// + + +func (c *int64Field) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *int64Field) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *int64Field) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *int64Field) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *int64Field) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *int64Field) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *int64Field) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *int64Field) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *int64Field) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *int64Field) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *int64Field) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type nullboolField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type NullBoolField interface { + TableField + + Eq(value sql.NullBool) Condition + IsEq(value NullBoolField) JoinCondition + + Gt(value sql.NullBool) Condition + IsGt(value NullBoolField) JoinCondition + + Ge(value sql.NullBool) Condition + IsGe(value NullBoolField) JoinCondition + + Lt(value sql.NullBool) Condition + IsLt(value NullBoolField) JoinCondition + + Le(value sql.NullBool) Condition + IsLe(value NullBoolField) JoinCondition + +} + +func (c *nullboolField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *nullboolField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullboolField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullboolField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *nullboolField) As(alias string) Field { + return &nullboolField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nullboolField) Alias() string { + return c.alias +} + +func (c *nullboolField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nullboolField) Name() string { + return c.name +} + +func (c *nullboolField) Type() reflect.Type { + return typeNullBool +} + +func (c *nullboolField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *nullboolField) Eq(pred sql.NullBool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nullboolField) IsEq(pred NullBoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *nullboolField) Gt(pred sql.NullBool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *nullboolField) IsGt(pred NullBoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *nullboolField) Ge(pred sql.NullBool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *nullboolField) IsGe(pred NullBoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *nullboolField) Lt(pred sql.NullBool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *nullboolField) IsLt(pred NullBoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *nullboolField) Le(pred sql.NullBool) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *nullboolField) IsLe(pred NullBoolField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func NullBool(s Selectable, name string) NullBoolField { + return &nullboolField{name: name, selection: s} +} + +////// + + +func (c *nullboolField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *nullboolField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *nullboolField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *nullboolField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *nullboolField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *nullboolField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *nullboolField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nullboolField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *nullboolField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *nullboolField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nullboolField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type nulldateField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type NullDateField interface { + TableField + + Eq(value NullableDate) Condition + IsEq(value NullDateField) JoinCondition + + Gt(value NullableDate) Condition + IsGt(value NullDateField) JoinCondition + + Ge(value NullableDate) Condition + IsGe(value NullDateField) JoinCondition + + Lt(value NullableDate) Condition + IsLt(value NullDateField) JoinCondition + + Le(value NullableDate) Condition + IsLe(value NullDateField) JoinCondition + +} + +func (c *nulldateField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *nulldateField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nulldateField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nulldateField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *nulldateField) As(alias string) Field { + return &nulldateField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nulldateField) Alias() string { + return c.alias +} + +func (c *nulldateField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nulldateField) Name() string { + return c.name +} + +func (c *nulldateField) Type() reflect.Type { + return typeNullDate +} + +func (c *nulldateField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *nulldateField) Eq(pred NullableDate) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nulldateField) IsEq(pred NullDateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *nulldateField) Gt(pred NullableDate) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *nulldateField) IsGt(pred NullDateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *nulldateField) Ge(pred NullableDate) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *nulldateField) IsGe(pred NullDateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *nulldateField) Lt(pred NullableDate) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *nulldateField) IsLt(pred NullDateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *nulldateField) Le(pred NullableDate) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *nulldateField) IsLe(pred NullDateField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func NullDate(s Selectable, name string) NullDateField { + return &nulldateField{name: name, selection: s} +} + +////// + + +func (c *nulldateField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *nulldateField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *nulldateField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *nulldateField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *nulldateField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *nulldateField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *nulldateField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nulldateField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *nulldateField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *nulldateField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nulldateField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type nulldatetimeField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type NullDatetimeField interface { + TableField + + Eq(value NullableDatetime) Condition + IsEq(value NullDatetimeField) JoinCondition + + Gt(value NullableDatetime) Condition + IsGt(value NullDatetimeField) JoinCondition + + Ge(value NullableDatetime) Condition + IsGe(value NullDatetimeField) JoinCondition + + Lt(value NullableDatetime) Condition + IsLt(value NullDatetimeField) JoinCondition + + Le(value NullableDatetime) Condition + IsLe(value NullDatetimeField) JoinCondition + +} + +func (c *nulldatetimeField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *nulldatetimeField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nulldatetimeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nulldatetimeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *nulldatetimeField) As(alias string) Field { + return &nulldatetimeField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nulldatetimeField) Alias() string { + return c.alias +} + +func (c *nulldatetimeField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nulldatetimeField) Name() string { + return c.name +} + +func (c *nulldatetimeField) Type() reflect.Type { + return typeNullDatetime +} + +func (c *nulldatetimeField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *nulldatetimeField) Eq(pred NullableDatetime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nulldatetimeField) IsEq(pred NullDatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *nulldatetimeField) Gt(pred NullableDatetime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *nulldatetimeField) IsGt(pred NullDatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *nulldatetimeField) Ge(pred NullableDatetime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *nulldatetimeField) IsGe(pred NullDatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *nulldatetimeField) Lt(pred NullableDatetime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *nulldatetimeField) IsLt(pred NullDatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *nulldatetimeField) Le(pred NullableDatetime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *nulldatetimeField) IsLe(pred NullDatetimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func NullDatetime(s Selectable, name string) NullDatetimeField { + return &nulldatetimeField{name: name, selection: s} +} + +////// + + +func (c *nulldatetimeField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *nulldatetimeField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *nulldatetimeField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *nulldatetimeField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *nulldatetimeField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *nulldatetimeField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *nulldatetimeField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nulldatetimeField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *nulldatetimeField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *nulldatetimeField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nulldatetimeField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type nullfloat32Field struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type NullFloat32Field interface { + TableField + + Eq(value sql.NullFloat64) Condition + IsEq(value NullFloat32Field) JoinCondition + + Gt(value sql.NullFloat64) Condition + IsGt(value NullFloat32Field) JoinCondition + + Ge(value sql.NullFloat64) Condition + IsGe(value NullFloat32Field) JoinCondition + + Lt(value sql.NullFloat64) Condition + IsLt(value NullFloat32Field) JoinCondition + + Le(value sql.NullFloat64) Condition + IsLe(value NullFloat32Field) JoinCondition + +} + +func (c *nullfloat32Field) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *nullfloat32Field) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullfloat32Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullfloat32Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *nullfloat32Field) As(alias string) Field { + return &nullfloat32Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nullfloat32Field) Alias() string { + return c.alias +} + +func (c *nullfloat32Field) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nullfloat32Field) Name() string { + return c.name +} + +func (c *nullfloat32Field) Type() reflect.Type { + return typeNullFloat32 +} + +func (c *nullfloat32Field) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *nullfloat32Field) Eq(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nullfloat32Field) IsEq(pred NullFloat32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *nullfloat32Field) Gt(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *nullfloat32Field) IsGt(pred NullFloat32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *nullfloat32Field) Ge(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *nullfloat32Field) IsGe(pred NullFloat32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *nullfloat32Field) Lt(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *nullfloat32Field) IsLt(pred NullFloat32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *nullfloat32Field) Le(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *nullfloat32Field) IsLe(pred NullFloat32Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func NullFloat32(s Selectable, name string) NullFloat32Field { + return &nullfloat32Field{name: name, selection: s} +} + +////// + + +func (c *nullfloat32Field) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *nullfloat32Field) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *nullfloat32Field) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *nullfloat32Field) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *nullfloat32Field) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *nullfloat32Field) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *nullfloat32Field) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nullfloat32Field) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *nullfloat32Field) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *nullfloat32Field) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nullfloat32Field) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type nullfloat64Field struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type NullFloat64Field interface { + TableField + + Eq(value sql.NullFloat64) Condition + IsEq(value NullFloat64Field) JoinCondition + + Gt(value sql.NullFloat64) Condition + IsGt(value NullFloat64Field) JoinCondition + + Ge(value sql.NullFloat64) Condition + IsGe(value NullFloat64Field) JoinCondition + + Lt(value sql.NullFloat64) Condition + IsLt(value NullFloat64Field) JoinCondition + + Le(value sql.NullFloat64) Condition + IsLe(value NullFloat64Field) JoinCondition + +} + +func (c *nullfloat64Field) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *nullfloat64Field) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullfloat64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullfloat64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *nullfloat64Field) As(alias string) Field { + return &nullfloat64Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nullfloat64Field) Alias() string { + return c.alias +} + +func (c *nullfloat64Field) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nullfloat64Field) Name() string { + return c.name +} + +func (c *nullfloat64Field) Type() reflect.Type { + return typeNullFloat64 +} + +func (c *nullfloat64Field) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *nullfloat64Field) Eq(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nullfloat64Field) IsEq(pred NullFloat64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *nullfloat64Field) Gt(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *nullfloat64Field) IsGt(pred NullFloat64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *nullfloat64Field) Ge(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *nullfloat64Field) IsGe(pred NullFloat64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *nullfloat64Field) Lt(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *nullfloat64Field) IsLt(pred NullFloat64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *nullfloat64Field) Le(pred sql.NullFloat64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *nullfloat64Field) IsLe(pred NullFloat64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func NullFloat64(s Selectable, name string) NullFloat64Field { + return &nullfloat64Field{name: name, selection: s} +} + +////// + + +func (c *nullfloat64Field) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *nullfloat64Field) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *nullfloat64Field) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *nullfloat64Field) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *nullfloat64Field) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *nullfloat64Field) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *nullfloat64Field) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nullfloat64Field) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *nullfloat64Field) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *nullfloat64Field) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nullfloat64Field) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type nullblobField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type NullBlobField interface { + TableField + + Eq(value NullableBlob) Condition + IsEq(value NullBlobField) JoinCondition + + Gt(value NullableBlob) Condition + IsGt(value NullBlobField) JoinCondition + + Ge(value NullableBlob) Condition + IsGe(value NullBlobField) JoinCondition + + Lt(value NullableBlob) Condition + IsLt(value NullBlobField) JoinCondition + + Le(value NullableBlob) Condition + IsLe(value NullBlobField) JoinCondition + +} + +func (c *nullblobField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *nullblobField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullblobField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullblobField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *nullblobField) As(alias string) Field { + return &nullblobField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nullblobField) Alias() string { + return c.alias +} + +func (c *nullblobField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nullblobField) Name() string { + return c.name +} + +func (c *nullblobField) Type() reflect.Type { + return typeNullBlob +} + +func (c *nullblobField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *nullblobField) Eq(pred NullableBlob) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nullblobField) IsEq(pred NullBlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *nullblobField) Gt(pred NullableBlob) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *nullblobField) IsGt(pred NullBlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *nullblobField) Ge(pred NullableBlob) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *nullblobField) IsGe(pred NullBlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *nullblobField) Lt(pred NullableBlob) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *nullblobField) IsLt(pred NullBlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *nullblobField) Le(pred NullableBlob) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *nullblobField) IsLe(pred NullBlobField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func NullBlob(s Selectable, name string) NullBlobField { + return &nullblobField{name: name, selection: s} +} + +////// + + +func (c *nullblobField) Avg() Field { + return c.fct("Avg", "AVG(%s)") } -type UpdateSetStep interface { - - SetString(StringField, string) UpdateSetMoreStep - - SetInt(IntField, int) UpdateSetMoreStep - - SetInt64(Int64Field, int64) UpdateSetMoreStep - - SetTime(TimeField, time.Time) UpdateSetMoreStep - +func (c *nullblobField) Max() Field { + return c.fct("Max", "MAX(%s)") } +func (c *nullblobField) Min() Field { + return c.fct("Min", "MIN(%s)") +} -func (i *insert) SetString(f StringField, v string) InsertSetMoreStep { - return i.set(f,v) +func (c *nullblobField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") } -func (i *insert) SetInt(f IntField, v int) InsertSetMoreStep { - return i.set(f,v) +func (c *nullblobField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) } -func (i *insert) SetInt64(f Int64Field, v int64) InsertSetMoreStep { - return i.set(f,v) +func (c *nullblobField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) } -func (i *insert) SetTime(f TimeField, v time.Time) InsertSetMoreStep { - return i.set(f,v) +func (c *nullblobField) Md5() Field { + return c.fct("Md5", "MD5(%s)") } +func (c *nullblobField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} +func (c *nullblobField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} -func (u *update) SetString(f StringField, v string) UpdateSetMoreStep { - return u.set(f,v) +func (c *nullblobField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) } -func (u *update) SetInt(f IntField, v int) UpdateSetMoreStep { - return u.set(f,v) +func (c *nullblobField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) } -func (u *update) SetInt64(f Int64Field, v int64) UpdateSetMoreStep { - return u.set(f,v) + + + +type nullintField struct { + name string + selection Selectable + alias string + fun FieldFunction } -func (u *update) SetTime(f TimeField, v time.Time) UpdateSetMoreStep { - return u.set(f,v) +type NullIntField interface { + TableField + + Eq(value sql.NullInt64) Condition + IsEq(value NullIntField) JoinCondition + + Gt(value sql.NullInt64) Condition + IsGt(value NullIntField) JoinCondition + + Ge(value sql.NullInt64) Condition + IsGe(value NullIntField) JoinCondition + + Lt(value sql.NullInt64) Condition + IsLt(value NullIntField) JoinCondition + + Le(value sql.NullInt64) Condition + IsLe(value NullIntField) JoinCondition + } +func (c *nullintField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} -///// +func (c *nullintField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullintField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullintField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} -type Reflectable interface { +func (c *nullintField) As(alias string) Field { + return &nullintField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *nullintField) Alias() string { + return c.alias +} + +func (c *nullintField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *nullintField) Name() string { + return c.name +} - StringField(name string) StringField +func (c *nullintField) Type() reflect.Type { + return typeNullInt +} + +func (c *nullintField) Parent() Selectable { + return c.selection +} - IntField(name string) IntField +// -- - Int64Field(name string) Int64Field - TimeField(name string) TimeField +func (c *nullintField) Eq(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *nullintField) IsEq(pred NullIntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} } -type Functional interface { - Avg() Field - Max() Field +func (c *nullintField) Gt(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} - Min() Field +func (c *nullintField) IsGt(pred NullIntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} - Ceil() Field - Div(_0 interface{}) Field - Cast(_0 interface{}) Field +func (c *nullintField) Ge(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} - Md5() Field +func (c *nullintField) IsGe(pred NullIntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} - Lower() Field - Hex() Field +func (c *nullintField) Lt(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} } +func (c *nullintField) IsLt(pred NullIntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} -func (s *selection) StringField(name string) StringField { - return &stringField{name: name} + + +func (c *nullintField) Le(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} } -func (t table) StringField(name string) StringField { - return &stringField{name: name, selection: t} + +func (c *nullintField) IsLe(pred NullIntField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} } -func (s *selection) IntField(name string) IntField { - return &intField{name: name} + + +// -- + +func NullInt(s Selectable, name string) NullIntField { + return &nullintField{name: name, selection: s} } -func (t table) IntField(name string) IntField { - return &intField{name: name, selection: t} + +////// + + +func (c *nullintField) Avg() Field { + return c.fct("Avg", "AVG(%s)") } -func (s *selection) Int64Field(name string) Int64Field { - return &int64Field{name: name} +func (c *nullintField) Max() Field { + return c.fct("Max", "MAX(%s)") } -func (t table) Int64Field(name string) Int64Field { - return &int64Field{name: name, selection: t} + +func (c *nullintField) Min() Field { + return c.fct("Min", "MIN(%s)") } -func (s *selection) TimeField(name string) TimeField { - return &timeField{name: name} +func (c *nullintField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") } -func (t table) TimeField(name string) TimeField { - return &timeField{name: name, selection: t} + +func (c *nullintField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) } +func (c *nullintField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} -///// +func (c *nullintField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nullintField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} +func (c *nullintField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} +func (c *nullintField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} -type stringField struct { - name string - selection Selectable - alias string - fun FieldFunction +func (c *nullintField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) } -type StringField interface { - TableField - - Eq(value string) Condition - IsEq(value StringField) JoinCondition - - Gt(value string) Condition - IsGt(value StringField) JoinCondition - - Ge(value string) Condition - IsGe(value StringField) JoinCondition - - Lt(value string) Condition - IsLt(value StringField) JoinCondition - - Le(value string) Condition - IsLe(value StringField) JoinCondition - + + + +type nullint64Field struct { + name string + selection Selectable + alias string + fun FieldFunction } -func (c *stringField) Function() FieldFunction { - return FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - } +type NullInt64Field interface { + TableField + + Eq(value sql.NullInt64) Condition + IsEq(value NullInt64Field) JoinCondition + + Gt(value sql.NullInt64) Condition + IsGt(value NullInt64Field) JoinCondition + + Ge(value sql.NullInt64) Condition + IsGe(value NullInt64Field) JoinCondition + + Lt(value sql.NullInt64) Condition + IsLt(value NullInt64Field) JoinCondition + + Le(value sql.NullInt64) Condition + IsLe(value NullInt64Field) JoinCondition + } -func (c *stringField) fct(fun, expr string, args ...interface{}) Field { - if &c.fun == nil { - return &stringField{ - name: c.name, - selection: c.selection, - fun: FieldFunction{Name:fun, Expr:expr, Args: args}, - } - } else { - return &stringField{ - name: c.name, - selection: c.selection, - fun: FieldFunction{ - Name: fun, - Expr: expr, - Args: args, - Child: &FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - }, - } - } +func (c *nullint64Field) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } } -func (c *stringField) As(alias string) Field { - return &stringField{ - name: c.name, - selection: c.selection, - alias: alias, - fun: FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - } +func (c *nullint64Field) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullint64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullint64Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } } -func (c *stringField) Alias() string { - return c.alias +func (c *nullint64Field) As(alias string) Field { + return &nullint64Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } } -func (c *stringField) MaybeAlias() string { - if c.alias == "" { - return c.name - } else { - return c.alias - } +func (c *nullint64Field) Alias() string { + return c.alias } -func (c *stringField) Name() string { - return c.name +func (c *nullint64Field) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } } -func (c *stringField) Parent() Selectable { - return c.selection +func (c *nullint64Field) Name() string { + return c.name +} + +func (c *nullint64Field) Type() reflect.Type { + return typeNullInt64 +} + +func (c *nullint64Field) Parent() Selectable { + return c.selection } // -- -func (c *stringField) Eq(pred string) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +func (c *nullint64Field) Eq(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} } -func (c *stringField) IsEq(pred StringField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +func (c *nullint64Field) IsEq(pred NullInt64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} } -func (c *stringField) Gt(pred string) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +func (c *nullint64Field) Gt(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} } -func (c *stringField) IsGt(pred StringField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +func (c *nullint64Field) IsGt(pred NullInt64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} } -func (c *stringField) Ge(pred string) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +func (c *nullint64Field) Ge(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} } -func (c *stringField) IsGe(pred StringField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +func (c *nullint64Field) IsGe(pred NullInt64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} } -func (c *stringField) Lt(pred string) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +func (c *nullint64Field) Lt(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} } -func (c *stringField) IsLt(pred StringField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +func (c *nullint64Field) IsLt(pred NullInt64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} } -func (c *stringField) Le(pred string) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +func (c *nullint64Field) Le(pred sql.NullInt64) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} } -func (c *stringField) IsLe(pred StringField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +func (c *nullint64Field) IsLe(pred NullInt64Field) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} } // -- -func String(s Selectable, name string) StringField { - return &stringField{name: name, selection: s} +func NullInt64(s Selectable, name string) NullInt64Field { + return &nullint64Field{name: name, selection: s} } ////// -func (c *stringField) Avg() Field { - return c.fct("Avg", "AVG(%s)") +func (c *nullint64Field) Avg() Field { + return c.fct("Avg", "AVG(%s)") } -func (c *stringField) Max() Field { - return c.fct("Max", "MAX(%s)") +func (c *nullint64Field) Max() Field { + return c.fct("Max", "MAX(%s)") } -func (c *stringField) Min() Field { - return c.fct("Min", "MIN(%s)") +func (c *nullint64Field) Min() Field { + return c.fct("Min", "MIN(%s)") } -func (c *stringField) Ceil() Field { - return c.fct("Ceil", "CEIL(%s)") +func (c *nullint64Field) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") } -func (c *stringField) Div(_0 interface{}) Field { - return c.fct("Div", "%s / %v", _0) +func (c *nullint64Field) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) } -func (c *stringField) Cast(_0 interface{}) Field { - return c.fct("Cast", "CAST(%s AS %s)", _0) +func (c *nullint64Field) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) } -func (c *stringField) Md5() Field { - return c.fct("Md5", "MD5(%s)") +func (c *nullint64Field) Md5() Field { + return c.fct("Md5", "MD5(%s)") } -func (c *stringField) Lower() Field { - return c.fct("Lower", "LOWER(%s)") +func (c *nullint64Field) Lower() Field { + return c.fct("Lower", "LOWER(%s)") } -func (c *stringField) Hex() Field { - return c.fct("Hex", "HEX(%s)") +func (c *nullint64Field) Hex() Field { + return c.fct("Hex", "HEX(%s)") } +func (c *nullint64Field) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nullint64Field) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} -type intField struct { - name string - selection Selectable - alias string - fun FieldFunction + +type nullstringField struct { + name string + selection Selectable + alias string + fun FieldFunction } -type IntField interface { - TableField - - Eq(value int) Condition - IsEq(value IntField) JoinCondition - - Gt(value int) Condition - IsGt(value IntField) JoinCondition - - Ge(value int) Condition - IsGe(value IntField) JoinCondition - - Lt(value int) Condition - IsLt(value IntField) JoinCondition - - Le(value int) Condition - IsLe(value IntField) JoinCondition - +type NullStringField interface { + TableField + + Eq(value sql.NullString) Condition + IsEq(value NullStringField) JoinCondition + + Gt(value sql.NullString) Condition + IsGt(value NullStringField) JoinCondition + + Ge(value sql.NullString) Condition + IsGe(value NullStringField) JoinCondition + + Lt(value sql.NullString) Condition + IsLt(value NullStringField) JoinCondition + + Le(value sql.NullString) Condition + IsLe(value NullStringField) JoinCondition + } -func (c *intField) Function() FieldFunction { - return FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - } +func (c *nullstringField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } } -func (c *intField) fct(fun, expr string, args ...interface{}) Field { - if &c.fun == nil { - return &intField{ - name: c.name, - selection: c.selection, - fun: FieldFunction{Name:fun, Expr:expr, Args: args}, - } - } else { - return &intField{ - name: c.name, - selection: c.selection, - fun: FieldFunction{ - Name: fun, - Expr: expr, - Args: args, - Child: &FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - }, - } - } +func (c *nullstringField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nullstringField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nullstringField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } } -func (c *intField) As(alias string) Field { - return &intField{ - name: c.name, - selection: c.selection, - alias: alias, - fun: FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - } +func (c *nullstringField) As(alias string) Field { + return &nullstringField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } } -func (c *intField) Alias() string { - return c.alias +func (c *nullstringField) Alias() string { + return c.alias } -func (c *intField) MaybeAlias() string { - if c.alias == "" { - return c.name - } else { - return c.alias - } +func (c *nullstringField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } } -func (c *intField) Name() string { - return c.name +func (c *nullstringField) Name() string { + return c.name } -func (c *intField) Parent() Selectable { - return c.selection +func (c *nullstringField) Type() reflect.Type { + return typeNullString +} + +func (c *nullstringField) Parent() Selectable { + return c.selection } // -- -func (c *intField) Eq(pred int) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +func (c *nullstringField) Eq(pred sql.NullString) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} } -func (c *intField) IsEq(pred IntField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +func (c *nullstringField) IsEq(pred NullStringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} } -func (c *intField) Gt(pred int) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +func (c *nullstringField) Gt(pred sql.NullString) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} } -func (c *intField) IsGt(pred IntField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +func (c *nullstringField) IsGt(pred NullStringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} } -func (c *intField) Ge(pred int) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +func (c *nullstringField) Ge(pred sql.NullString) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} } -func (c *intField) IsGe(pred IntField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +func (c *nullstringField) IsGe(pred NullStringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} } -func (c *intField) Lt(pred int) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +func (c *nullstringField) Lt(pred sql.NullString) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} } -func (c *intField) IsLt(pred IntField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +func (c *nullstringField) IsLt(pred NullStringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} } -func (c *intField) Le(pred int) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +func (c *nullstringField) Le(pred sql.NullString) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} } -func (c *intField) IsLe(pred IntField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +func (c *nullstringField) IsLe(pred NullStringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} } // -- -func Int(s Selectable, name string) IntField { - return &intField{name: name, selection: s} +func NullString(s Selectable, name string) NullStringField { + return &nullstringField{name: name, selection: s} } ////// -func (c *intField) Avg() Field { - return c.fct("Avg", "AVG(%s)") +func (c *nullstringField) Avg() Field { + return c.fct("Avg", "AVG(%s)") } -func (c *intField) Max() Field { - return c.fct("Max", "MAX(%s)") +func (c *nullstringField) Max() Field { + return c.fct("Max", "MAX(%s)") } -func (c *intField) Min() Field { - return c.fct("Min", "MIN(%s)") +func (c *nullstringField) Min() Field { + return c.fct("Min", "MIN(%s)") } -func (c *intField) Ceil() Field { - return c.fct("Ceil", "CEIL(%s)") +func (c *nullstringField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") } -func (c *intField) Div(_0 interface{}) Field { - return c.fct("Div", "%s / %v", _0) +func (c *nullstringField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) } -func (c *intField) Cast(_0 interface{}) Field { - return c.fct("Cast", "CAST(%s AS %s)", _0) +func (c *nullstringField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) } -func (c *intField) Md5() Field { - return c.fct("Md5", "MD5(%s)") +func (c *nullstringField) Md5() Field { + return c.fct("Md5", "MD5(%s)") } -func (c *intField) Lower() Field { - return c.fct("Lower", "LOWER(%s)") +func (c *nullstringField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") } -func (c *intField) Hex() Field { - return c.fct("Hex", "HEX(%s)") +func (c *nullstringField) Hex() Field { + return c.fct("Hex", "HEX(%s)") } +func (c *nullstringField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nullstringField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} -type int64Field struct { - name string - selection Selectable - alias string - fun FieldFunction + +type nulltimeField struct { + name string + selection Selectable + alias string + fun FieldFunction } -type Int64Field interface { - TableField - - Eq(value int64) Condition - IsEq(value Int64Field) JoinCondition - - Gt(value int64) Condition - IsGt(value Int64Field) JoinCondition - - Ge(value int64) Condition - IsGe(value Int64Field) JoinCondition - - Lt(value int64) Condition - IsLt(value Int64Field) JoinCondition - - Le(value int64) Condition - IsLe(value Int64Field) JoinCondition - +type NullTimeField interface { + TableField + + Eq(value NullableTime) Condition + IsEq(value NullTimeField) JoinCondition + + Gt(value NullableTime) Condition + IsGt(value NullTimeField) JoinCondition + + Ge(value NullableTime) Condition + IsGe(value NullTimeField) JoinCondition + + Lt(value NullableTime) Condition + IsLt(value NullTimeField) JoinCondition + + Le(value NullableTime) Condition + IsLe(value NullTimeField) JoinCondition + } -func (c *int64Field) Function() FieldFunction { - return FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - } +func (c *nulltimeField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } } -func (c *int64Field) fct(fun, expr string, args ...interface{}) Field { - if &c.fun == nil { - return &int64Field{ - name: c.name, - selection: c.selection, - fun: FieldFunction{Name:fun, Expr:expr, Args: args}, - } - } else { - return &int64Field{ - name: c.name, - selection: c.selection, - fun: FieldFunction{ - Name: fun, - Expr: expr, - Args: args, - Child: &FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - }, - } - } +func (c *nulltimeField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &nulltimeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &nulltimeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } } -func (c *int64Field) As(alias string) Field { - return &int64Field{ - name: c.name, - selection: c.selection, - alias: alias, - fun: FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - } +func (c *nulltimeField) As(alias string) Field { + return &nulltimeField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } } -func (c *int64Field) Alias() string { - return c.alias +func (c *nulltimeField) Alias() string { + return c.alias } -func (c *int64Field) MaybeAlias() string { - if c.alias == "" { - return c.name - } else { - return c.alias - } +func (c *nulltimeField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } } -func (c *int64Field) Name() string { - return c.name +func (c *nulltimeField) Name() string { + return c.name } -func (c *int64Field) Parent() Selectable { - return c.selection +func (c *nulltimeField) Type() reflect.Type { + return typeNullTime +} + +func (c *nulltimeField) Parent() Selectable { + return c.selection } // -- -func (c *int64Field) Eq(pred int64) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +func (c *nulltimeField) Eq(pred NullableTime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} } -func (c *int64Field) IsEq(pred Int64Field) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +func (c *nulltimeField) IsEq(pred NullTimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} } -func (c *int64Field) Gt(pred int64) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +func (c *nulltimeField) Gt(pred NullableTime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} } -func (c *int64Field) IsGt(pred Int64Field) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +func (c *nulltimeField) IsGt(pred NullTimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} } -func (c *int64Field) Ge(pred int64) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +func (c *nulltimeField) Ge(pred NullableTime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} } -func (c *int64Field) IsGe(pred Int64Field) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +func (c *nulltimeField) IsGe(pred NullTimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} } -func (c *int64Field) Lt(pred int64) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +func (c *nulltimeField) Lt(pred NullableTime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} } -func (c *int64Field) IsLt(pred Int64Field) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +func (c *nulltimeField) IsLt(pred NullTimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} } -func (c *int64Field) Le(pred int64) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +func (c *nulltimeField) Le(pred NullableTime) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} } -func (c *int64Field) IsLe(pred Int64Field) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +func (c *nulltimeField) IsLe(pred NullTimeField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} } // -- -func Int64(s Selectable, name string) Int64Field { - return &int64Field{name: name, selection: s} +func NullTime(s Selectable, name string) NullTimeField { + return &nulltimeField{name: name, selection: s} +} + +////// + + +func (c *nulltimeField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *nulltimeField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *nulltimeField) Min() Field { + return c.fct("Min", "MIN(%s)") +} + +func (c *nulltimeField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") +} + +func (c *nulltimeField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) +} + +func (c *nulltimeField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) +} + +func (c *nulltimeField) Md5() Field { + return c.fct("Md5", "MD5(%s)") +} + +func (c *nulltimeField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") +} + +func (c *nulltimeField) Hex() Field { + return c.fct("Hex", "HEX(%s)") +} + +func (c *nulltimeField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) +} + +func (c *nulltimeField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) +} + + + + +type stringField struct { + name string + selection Selectable + alias string + fun FieldFunction +} + +type StringField interface { + TableField + + Eq(value string) Condition + IsEq(value StringField) JoinCondition + + Gt(value string) Condition + IsGt(value StringField) JoinCondition + + Ge(value string) Condition + IsGe(value StringField) JoinCondition + + Lt(value string) Condition + IsLt(value StringField) JoinCondition + + Le(value string) Condition + IsLe(value StringField) JoinCondition + +} + +func (c *stringField) Function() FieldFunction { + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } +} + +func (c *stringField) fct(fun, expr string, args ...interface{}) Field { + if &c.fun == nil { + return &stringField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &stringField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } +} + +func (c *stringField) As(alias string) Field { + return &stringField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } +} + +func (c *stringField) Alias() string { + return c.alias +} + +func (c *stringField) MaybeAlias() string { + if c.alias == "" { + return c.name + } else { + return c.alias + } +} + +func (c *stringField) Name() string { + return c.name +} + +func (c *stringField) Type() reflect.Type { + return typeString +} + +func (c *stringField) Parent() Selectable { + return c.selection +} + +// -- + + + +func (c *stringField) Eq(pred string) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} +} + +func (c *stringField) IsEq(pred StringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} +} + + + +func (c *stringField) Gt(pred string) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} +} + +func (c *stringField) IsGt(pred StringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} +} + + + +func (c *stringField) Ge(pred string) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} +} + +func (c *stringField) IsGe(pred StringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} +} + + + +func (c *stringField) Lt(pred string) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} +} + +func (c *stringField) IsLt(pred StringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} +} + + + +func (c *stringField) Le(pred string) Condition { + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} +} + +func (c *stringField) IsLe(pred StringField) JoinCondition { + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} +} + + + +// -- + +func String(s Selectable, name string) StringField { + return &stringField{name: name, selection: s} } ////// -func (c *int64Field) Avg() Field { - return c.fct("Avg", "AVG(%s)") +func (c *stringField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *stringField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *stringField) Min() Field { + return c.fct("Min", "MIN(%s)") } -func (c *int64Field) Max() Field { - return c.fct("Max", "MAX(%s)") +func (c *stringField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") } -func (c *int64Field) Min() Field { - return c.fct("Min", "MIN(%s)") +func (c *stringField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) } -func (c *int64Field) Ceil() Field { - return c.fct("Ceil", "CEIL(%s)") +func (c *stringField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) } -func (c *int64Field) Div(_0 interface{}) Field { - return c.fct("Div", "%s / %v", _0) +func (c *stringField) Md5() Field { + return c.fct("Md5", "MD5(%s)") } -func (c *int64Field) Cast(_0 interface{}) Field { - return c.fct("Cast", "CAST(%s AS %s)", _0) +func (c *stringField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") } -func (c *int64Field) Md5() Field { - return c.fct("Md5", "MD5(%s)") +func (c *stringField) Hex() Field { + return c.fct("Hex", "HEX(%s)") } -func (c *int64Field) Lower() Field { - return c.fct("Lower", "LOWER(%s)") +func (c *stringField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) } -func (c *int64Field) Hex() Field { - return c.fct("Hex", "HEX(%s)") +func (c *stringField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) } type timeField struct { - name string - selection Selectable - alias string - fun FieldFunction + name string + selection Selectable + alias string + fun FieldFunction } type TimeField interface { - TableField - - Eq(value time.Time) Condition - IsEq(value TimeField) JoinCondition - - Gt(value time.Time) Condition - IsGt(value TimeField) JoinCondition - - Ge(value time.Time) Condition - IsGe(value TimeField) JoinCondition - - Lt(value time.Time) Condition - IsLt(value TimeField) JoinCondition - - Le(value time.Time) Condition - IsLe(value TimeField) JoinCondition - + TableField + + Eq(value time.Time) Condition + IsEq(value TimeField) JoinCondition + + Gt(value time.Time) Condition + IsGt(value TimeField) JoinCondition + + Ge(value time.Time) Condition + IsGe(value TimeField) JoinCondition + + Lt(value time.Time) Condition + IsLt(value TimeField) JoinCondition + + Le(value time.Time) Condition + IsLe(value TimeField) JoinCondition + } func (c *timeField) Function() FieldFunction { - return FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - } + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } } func (c *timeField) fct(fun, expr string, args ...interface{}) Field { - if &c.fun == nil { - return &timeField{ - name: c.name, - selection: c.selection, - fun: FieldFunction{Name:fun, Expr:expr, Args: args}, - } - } else { - return &timeField{ - name: c.name, - selection: c.selection, - fun: FieldFunction{ - Name: fun, - Expr: expr, - Args: args, - Child: &FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - }, - } - } + if &c.fun == nil { + return &timeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &timeField{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } } func (c *timeField) As(alias string) Field { - return &timeField{ - name: c.name, - selection: c.selection, - alias: alias, - fun: FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - } + return &timeField{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } } func (c *timeField) Alias() string { - return c.alias + return c.alias } func (c *timeField) MaybeAlias() string { - if c.alias == "" { - return c.name - } else { - return c.alias - } + if c.alias == "" { + return c.name + } else { + return c.alias + } } func (c *timeField) Name() string { - return c.name + return c.name +} + +func (c *timeField) Type() reflect.Type { + return typeTime } func (c *timeField) Parent() Selectable { - return c.selection + return c.selection } // -- @@ -834,51 +4601,51 @@ func (c *timeField) Parent() Selectable { func (c *timeField) Eq(pred time.Time) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: EqPredicate} } func (c *timeField) IsEq(pred TimeField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} + return JoinCondition{Lhs: c, Rhs: pred, Predicate: EqPredicate} } func (c *timeField) Gt(pred time.Time) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GtPredicate} } func (c *timeField) IsGt(pred TimeField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GtPredicate} } func (c *timeField) Ge(pred time.Time) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: GePredicate} } func (c *timeField) IsGe(pred TimeField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} + return JoinCondition{Lhs: c, Rhs: pred, Predicate: GePredicate} } func (c *timeField) Lt(pred time.Time) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LtPredicate} } func (c *timeField) IsLt(pred TimeField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LtPredicate} } func (c *timeField) Le(pred time.Time) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: LePredicate} } func (c *timeField) IsLe(pred TimeField) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} + return JoinCondition{Lhs: c, Rhs: pred, Predicate: LePredicate} } @@ -886,46 +4653,54 @@ func (c *timeField) IsLe(pred TimeField) JoinCondition { // -- func Time(s Selectable, name string) TimeField { - return &timeField{name: name, selection: s} + return &timeField{name: name, selection: s} } ////// -func (c *timeField) Avg() Field { - return c.fct("Avg", "AVG(%s)") +func (c *timeField) Avg() Field { + return c.fct("Avg", "AVG(%s)") +} + +func (c *timeField) Max() Field { + return c.fct("Max", "MAX(%s)") +} + +func (c *timeField) Min() Field { + return c.fct("Min", "MIN(%s)") } -func (c *timeField) Max() Field { - return c.fct("Max", "MAX(%s)") +func (c *timeField) Ceil() Field { + return c.fct("Ceil", "CEIL(%s)") } -func (c *timeField) Min() Field { - return c.fct("Min", "MIN(%s)") +func (c *timeField) Div(_0 interface{}) Field { + return c.fct("Div", "%s / %v", _0) } -func (c *timeField) Ceil() Field { - return c.fct("Ceil", "CEIL(%s)") +func (c *timeField) Cast(_0 interface{}) Field { + return c.fct("Cast", "CAST(%s AS %s)", _0) } -func (c *timeField) Div(_0 interface{}) Field { - return c.fct("Div", "%s / %v", _0) +func (c *timeField) Md5() Field { + return c.fct("Md5", "MD5(%s)") } -func (c *timeField) Cast(_0 interface{}) Field { - return c.fct("Cast", "CAST(%s AS %s)", _0) +func (c *timeField) Lower() Field { + return c.fct("Lower", "LOWER(%s)") } -func (c *timeField) Md5() Field { - return c.fct("Md5", "MD5(%s)") +func (c *timeField) Hex() Field { + return c.fct("Hex", "HEX(%s)") } -func (c *timeField) Lower() Field { - return c.fct("Lower", "LOWER(%s)") +func (c *timeField) Substr2(_0 interface{}) Field { + return c.fct("Substr2", "SUBSTR(%s, %v)", _0) } -func (c *timeField) Hex() Field { - return c.fct("Hex", "HEX(%s)") +func (c *timeField) Substr3(_0,_1 interface{}) Field { + return c.fct("Substr3", "SUBSTR(%s, %v, %v)", _0,_1) } diff --git a/sqlc/generator.go b/sqlc/generator.go index 34e3d81..d7a6dd2 100644 --- a/sqlc/generator.go +++ b/sqlc/generator.go @@ -5,7 +5,7 @@ import ( "database/sql" "errors" "fmt" - "github.com/relops/sqlc/meta" + "github.com/shutej/sqlc/meta" "io/ioutil" "log" "os" @@ -15,10 +15,16 @@ import ( "time" ) +var boolean = regexp.MustCompile("BOOLEAN") var integer = regexp.MustCompile("INT") var int_64 = regexp.MustCompile("INTEGER|BIGINT") -var varchar = regexp.MustCompile("VARCHAR|CHARACTER VARYING|TEXT") -var ts = regexp.MustCompile("TIMESTAMP|DATETIME") +var float_32 = regexp.MustCompile("FLOAT") +var float_64 = regexp.MustCompile("DOUBLE PRECISION|NUMERIC") +var varchar = regexp.MustCompile("VARCHAR|CHARACTER VARYING|TINYTEXT|TEXT|MEDIUMTEXT|LONGTEXT|CHAR") +var datetime = regexp.MustCompile("TIMESTAMP|DATETIME") +var date = regexp.MustCompile("DATE") +var time_ = regexp.MustCompile("TIME") +var blob = regexp.MustCompile("INET|TINYBLOB|BLOB|MEDIUMBLOB|LONGBLOB") var dbType = regexp.MustCompile("mysql|postgres|sqlite") type Provenance struct { @@ -101,6 +107,7 @@ func Generate(db *sql.DB, version string, opts *Options) error { } params := make(map[string]interface{}) + params["Schema"] = opts.Schema params["Tables"] = tables params["Package"] = opts.Package params["Types"] = meta.Types @@ -163,22 +170,40 @@ func infoSchema(d Dialect, schema string, db *sql.DB) ([]TableMeta, error) { fields := make([]FieldMeta, 0) for rows.Next() { - var colName, colType sql.NullString - err = rows.Scan(&colName, &colType) + var colName, colType, colIsNullable sql.NullString + err = rows.Scan(&colName, &colType, &colIsNullable) if err != nil { return nil, err } var fieldType string + nullable := strings.ToUpper(colIsNullable.String) == "YES" + if int_64.MatchString(colType.String) { fieldType = "Int64" } else if integer.MatchString(colType.String) { fieldType = "Int" + } else if float_64.MatchString(colType.String) { + fieldType = "Float64" + } else if float_32.MatchString(colType.String) { + fieldType = "Float32" } else if varchar.MatchString(colType.String) { fieldType = "String" - } else if ts.MatchString(colType.String) { + } else if datetime.MatchString(colType.String) { + fieldType = "Datetime" + } else if date.MatchString(colType.String) { + fieldType = "Date" + } else if time_.MatchString(colType.String) { fieldType = "Time" + } else if boolean.MatchString(colType.String) { + fieldType = "Bool" + } else if blob.MatchString(colType.String) { + fieldType = "Blob" + } + + if nullable { + fieldType = "Null" + fieldType } field := FieldMeta{Name: colName.String, Type: fieldType} @@ -222,16 +247,34 @@ func sqlite(db *sql.DB) ([]TableMeta, error) { return nil, err } + nullable := !notNull.Bool + var fieldType string if int_64.MatchString(colType.String) { fieldType = "Int64" } else if integer.MatchString(colType.String) { fieldType = "Int" + } else if float_64.MatchString(colType.String) { + fieldType = "Float64" + } else if float_32.MatchString(colType.String) { + fieldType = "Float32" } else if varchar.MatchString(colType.String) { fieldType = "String" - } else if ts.MatchString(colType.String) { + } else if datetime.MatchString(colType.String) { fieldType = "Time" + } else if date.MatchString(colType.String) { + fieldType = "Date" + } else if time_.MatchString(colType.String) { + fieldType = "Time" + } else if boolean.MatchString(colType.String) { + fieldType = "Bool" + } else if blob.MatchString(colType.String) { + fieldType = "Blob" + } + + if nullable { + fieldType = "Null" + fieldType } field := FieldMeta{Name: colName.String, Type: fieldType} @@ -259,7 +302,7 @@ const infoTablesTmpl = ` ` const infoColumnsTmpl = ` - SELECT column_name, UPPER(data_type) - FROM information_schema.columns + SELECT column_name, UPPER(data_type), is_nullable + FROM information_schema.columns WHERE table_schema = %s and table_name = %s; ` diff --git a/sqlc/insert.go b/sqlc/insert.go index 32d5011..332603e 100644 --- a/sqlc/insert.go +++ b/sqlc/insert.go @@ -30,7 +30,7 @@ func (i *insert) Fetch(d Dialect, db *sql.DB) (*sql.Row, error) { return db.QueryRow(buf.String(), args...), nil } -func (i *insert) set(f TableField, v interface{}) InsertSetMoreStep { +func (i *insert) Set(f TableField, v interface{}) InsertSetMoreStep { binding := TableFieldBinding{Field: f, Value: v} i.bindings = append(i.bindings, binding) return i diff --git a/sqlc/schema.go b/sqlc/schema.go index 37f82f5..d2e215e 100644 --- a/sqlc/schema.go +++ b/sqlc/schema.go @@ -27,89 +27,109 @@ func bindata_read(data []byte, name string) ([]byte, error) { func sqlc_tmpl_fields_tmpl() ([]byte, error) { return bindata_read([]byte{ - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xc4, 0x57, - 0x51, 0x6f, 0xdb, 0x36, 0x10, 0x7e, 0x96, 0x7e, 0xc5, 0xc1, 0x08, 0x02, - 0x2b, 0x50, 0x94, 0x77, 0x03, 0x79, 0x70, 0x5b, 0x65, 0xf5, 0xe0, 0x3a, - 0x81, 0xed, 0x2e, 0xd8, 0xd3, 0xa0, 0xca, 0x94, 0xcb, 0x4d, 0xa1, 0x35, - 0x89, 0xce, 0x5a, 0x08, 0xfa, 0xef, 0xbb, 0x23, 0x29, 0x95, 0xb2, 0x29, - 0xd7, 0xc6, 0xb0, 0xd6, 0x0f, 0x89, 0x79, 0x24, 0xef, 0xbe, 0xfb, 0xee, - 0x3b, 0x92, 0xbe, 0xbb, 0x83, 0xf5, 0xfb, 0xd9, 0x0a, 0x1e, 0x66, 0xf3, - 0x18, 0x9e, 0xa7, 0x2b, 0x98, 0x7e, 0x5c, 0x3f, 0xfe, 0x12, 0x2f, 0xe2, - 0xe5, 0x74, 0x1d, 0xbf, 0x83, 0x5b, 0x98, 0x2e, 0x7e, 0x87, 0xf8, 0xdd, - 0x6c, 0xbd, 0x82, 0xf5, 0xa3, 0x5e, 0xfa, 0x3c, 0x9b, 0xcf, 0xe1, 0x4d, - 0x0c, 0xf3, 0xc7, 0xd5, 0x1a, 0x9e, 0xdf, 0xc7, 0x0b, 0x98, 0xad, 0x01, - 0xed, 0xcb, 0xb8, 0xdb, 0xe7, 0xfb, 0x75, 0x0d, 0x57, 0x45, 0xc9, 0x36, - 0x15, 0x4c, 0xee, 0x21, 0xa2, 0x6f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0x9e, 0xf4, 0x99, 0xde, - 0xea, 0xa9, 0x88, 0x7a, 0x71, 0x48, 0x58, 0xaf, 0x49, 0xbe, 0x67, 0x8e, - 0x96, 0x7b, 0xbb, 0x13, 0x1b, 0xae, 0xc0, 0x98, 0x9d, 0xbf, 0xee, 0xb8, - 0x18, 0xda, 0xd8, 0x47, 0x18, 0x00, 0xad, 0xed, 0x3b, 0xf8, 0x26, 0x51, - 0x2d, 0x82, 0x14, 0x6e, 0x4e, 0xd1, 0x19, 0x74, 0x3d, 0x33, 0x0e, 0xfa, - 0xdc, 0x58, 0xe5, 0xef, 0xd9, 0xd1, 0xec, 0x2d, 0x54, 0xc5, 0x21, 0xa5, - 0x3b, 0x4a, 0x75, 0x4e, 0x88, 0xc6, 0xf8, 0x4b, 0x51, 0x76, 0x46, 0x1a, - 0x90, 0x71, 0x5a, 0x6e, 0xab, 0xce, 0x48, 0x03, 0x32, 0xbe, 0xfd, 0xcc, - 0xf3, 0xcd, 0xc4, 0x18, 0xd5, 0x00, 0xad, 0x97, 0x60, 0xce, 0x52, 0x3c, - 0x88, 0xf6, 0x22, 0x04, 0x86, 0x61, 0x4c, 0x79, 0x43, 0x48, 0xd0, 0x3d, - 0x44, 0x51, 0xd4, 0xd5, 0xad, 0x6e, 0x7b, 0x97, 0x72, 0xe1, 0x19, 0x5c, - 0xab, 0x88, 0x70, 0x7f, 0x0f, 0x82, 0xe7, 0x64, 0x3b, 0x4f, 0xdf, 0xb8, - 0xce, 0xd3, 0x1a, 0x57, 0x9f, 0x34, 0x12, 0x26, 0x63, 0xcf, 0x52, 0x7b, - 0x1a, 0x75, 0x03, 0x35, 0x85, 0x81, 0xcc, 0xfa, 0x03, 0xfa, 0x14, 0x77, - 0x0a, 0xbc, 0x22, 0x8c, 0x32, 0x08, 0x41, 0xd3, 0x44, 0x09, 0x34, 0xb4, - 0x1b, 0x55, 0xd4, 0x00, 0xcb, 0x2b, 0xf6, 0xb3, 0x40, 0xd2, 0x64, 0x5b, - 0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x79, - 0x0c, 0xf5, 0x0c, 0x6a, 0xa8, 0x09, 0xe1, 0xa9, 0xfd, 0xa9, 0x32, 0x31, - 0x20, 0x3a, 0x03, 0x86, 0xba, 0xa4, 0x08, 0xee, 0x5b, 0xce, 0xca, 0xe0, - 0xe4, 0x25, 0x67, 0x65, 0xd2, 0xb3, 0xd7, 0xf3, 0xcf, 0xd8, 0x03, 0x69, - 0x08, 0x4b, 0xfa, 0xaf, 0xd1, 0x7f, 0x1f, 0x72, 0xef, 0x79, 0xa2, 0xaa, - 0xa4, 0x92, 0x38, 0x7c, 0x42, 0x57, 0x56, 0x9d, 0x43, 0xf8, 0xdf, 0x5f, - 0x4e, 0x55, 0xe3, 0xb7, 0xef, 0xa5, 0xa3, 0x07, 0xd3, 0xc1, 0xeb, 0xf5, - 0x02, 0xce, 0xcf, 0x78, 0xe3, 0x42, 0xed, 0x59, 0x22, 0xa6, 0x5b, 0x76, - 0xd4, 0xdb, 0x39, 0x0a, 0xc1, 0x18, 0xe8, 0xec, 0x21, 0x03, 0x8e, 0xb8, - 0xf8, 0x93, 0x80, 0x5b, 0xce, 0x8e, 0x7e, 0xc0, 0x98, 0xaf, 0xff, 0x06, - 0x00, 0x00, 0xff, 0xff, 0xb4, 0xaa, 0xc3, 0xea, 0x54, 0x0f, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xcc, 0x58, + 0x5f, 0x6f, 0xdb, 0x36, 0x10, 0x7f, 0xd7, 0xa7, 0x38, 0x18, 0x45, 0x20, + 0x07, 0x8a, 0x12, 0x6c, 0x45, 0x1f, 0x0c, 0xe4, 0xc1, 0x69, 0x9c, 0xd5, + 0x83, 0xeb, 0x04, 0xb1, 0xb2, 0x60, 0x18, 0x86, 0x81, 0x91, 0x29, 0x97, + 0x9b, 0x2a, 0x79, 0x12, 0x9d, 0x25, 0x30, 0xf4, 0xdd, 0xc7, 0x23, 0x29, + 0x99, 0x94, 0x28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0x0e, 0xe0, 0x1e, 0x7f, 0x15, 0xfc, 0xb7, 0x31, 0x5b, 0x17, 0x2f, + 0x59, 0x27, 0x99, 0x45, 0xfb, 0x13, 0xa1, 0x34, 0x4a, 0x1d, 0xc0, 0x7f, + 0x7f, 0x29, 0x2c, 0x2b, 0xaf, 0xbe, 0x0a, 0x76, 0xee, 0x82, 0xad, 0xbb, + 0xf9, 0x11, 0xac, 0x1f, 0x70, 0x81, 0xb7, 0xfb, 0x18, 0x6f, 0x0b, 0x03, + 0xcb, 0x72, 0x10, 0x80, 0x16, 0xe0, 0x76, 0x87, 0x02, 0xf1, 0xc6, 0xb2, + 0xdf, 0x11, 0xb8, 0xe1, 0xac, 0xf3, 0x85, 0xa6, 0x1f, 0xff, 0x0e, 0x00, + 0x00, 0xff, 0xff, 0x14, 0x91, 0xb5, 0x2c, 0x54, 0x14, 0x00, 0x00, }, "sqlc/tmpl/fields.tmpl", ) @@ -118,53 +138,58 @@ func sqlc_tmpl_fields_tmpl() ([]byte, error) { func sqlc_tmpl_schema_tmpl() ([]byte, error) { return bindata_read([]byte{ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0x9c, 0x54, - 0x61, 0x6f, 0xda, 0x30, 0x10, 0xfd, 0x4c, 0x7e, 0xc5, 0x29, 0xaa, 0xa6, - 0x64, 0xea, 0xc2, 0x77, 0x24, 0x3e, 0x64, 0x6a, 0xda, 0x46, 0x62, 0x61, - 0x22, 0xa6, 0x68, 0x9a, 0x26, 0x64, 0x52, 0x87, 0x45, 0x0b, 0x49, 0x66, - 0x9b, 0x6e, 0x08, 0xf1, 0xdf, 0x77, 0xb6, 0x49, 0x49, 0xc1, 0x14, 0x34, - 0x84, 0x90, 0x39, 0xbf, 0x7b, 0xf7, 0xee, 0xf9, 0xec, 0x7e, 0x1f, 0xc8, - 0x63, 0x9c, 0xc2, 0x7d, 0x3c, 0x8a, 0x60, 0x16, 0xa6, 0x10, 0x4e, 0x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51, 0xa1, 0x9c, 0x91, 0x5c, 0x3d, 0xcf, 0x98, 0x22, 0xa9, 0x06, 0xad, + 0xd3, 0x56, 0x0e, 0x97, 0xc8, 0xb5, 0xd0, 0xc2, 0x2b, 0xfe, 0xe0, 0x8a, + 0x55, 0x58, 0x3e, 0xca, 0xb8, 0x24, 0x60, 0x2c, 0x75, 0x44, 0xe1, 0xc0, + 0x18, 0xcf, 0x41, 0x62, 0x0e, 0xc2, 0x0a, 0x6f, 0x12, 0x9c, 0x6e, 0x04, + 0x0c, 0x48, 0x88, 0x87, 0xb2, 0xe4, 0x10, 0xf1, 0x09, 0x82, 0x29, 0xb6, + 0x78, 0x12, 0xb1, 0x48, 0x80, 0x2d, 0x89, 0x1e, 0x59, 0x8f, 0xf3, 0x8d, + 0xec, 0x45, 0x69, 0x82, 0x08, 0x48, 0x53, 0x1a, 0xd3, 0x14, 0xd7, 0x79, + 0x04, 0x06, 0x85, 0x8f, 0x4a, 0x5d, 0x26, 0xb8, 0x24, 0xc0, 0x29, 0x8e, + 0x28, 0x77, 0x61, 0x98, 0x70, 0x98, 0xd0, 0x22, 0x13, 0x61, 0xc5, 0x92, + 0x45, 0x98, 0xaa, 0x30, 0xad, 0xab, 0xbc, 0xdd, 0x9a, 0xc2, 0xcb, 0x3f, + 0x94, 0x10, 0xc2, 0xe6, 0xb7, 0x9a, 0xf9, 0x88, 0x13, 0xbc, 0x31, 0xa8, + 0xd5, 0xd1, 0xcd, 0xc4, 0x3c, 0x86, 0x58, 0xba, 0x39, 0x85, 0xcf, 0x26, + 0x06, 0x6a, 0xd9, 0x4c, 0xc9, 0x71, 0xf2, 0xdd, 0xa7, 0xff, 0xa0, 0xec, + 0xe7, 0x05, 0x53, 0x26, 0x37, 0x32, 0xbb, 0x05, 0x50, 0x4b, 0xb9, 0x31, + 0xeb, 0x7a, 0x8e, 0xf3, 0x6b, 0x27, 0xb8, 0x40, 0x7c, 0xab, 0x99, 0xe4, + 0x8c, 0xd7, 0x2b, 0xa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0xf4, 0x19, 0x1b, 0xed, 0x5f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xd4, 0xa6, 0xda, 0x3b, 0xc5, 0x07, 0x00, 0x00, }, "sqlc/tmpl/schema.tmpl", ) @@ -207,17 +232,14 @@ var _bindata = map[string]func() ([]byte, error){ // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(cannonicalName, "/") node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } + for _, p := range pathList { + node = node.Children[p] + if node == nil { + return nil, fmt.Errorf("Asset %s not found", name) } } if node.Func != nil { @@ -237,10 +259,10 @@ type _bintree_t struct { var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ "sqlc": &_bintree_t{nil, map[string]*_bintree_t{ "tmpl": &_bintree_t{nil, map[string]*_bintree_t{ - "schema.tmpl": &_bintree_t{sqlc_tmpl_schema_tmpl, map[string]*_bintree_t{ - }}, "fields.tmpl": &_bintree_t{sqlc_tmpl_fields_tmpl, map[string]*_bintree_t{ }}, + "schema.tmpl": &_bintree_t{sqlc_tmpl_schema_tmpl, map[string]*_bintree_t{ + }}, }}, }}, }} diff --git a/sqlc/sqlc.go b/sqlc/sqlc.go index eb235db..6c0fd2e 100644 --- a/sqlc/sqlc.go +++ b/sqlc/sqlc.go @@ -3,7 +3,11 @@ package sqlc import ( "bytes" "database/sql" + "database/sql/driver" "io" + "reflect" + "strings" + "time" ) type PredicateType int @@ -54,6 +58,7 @@ type Field interface { Aliasable Functional Name() string + Type() reflect.Type As(string) Field Function() FieldFunction } @@ -186,7 +191,7 @@ func (u *update) Where(c ...Condition) Executable { return u } -func (u *update) set(f TableField, v interface{}) UpdateSetMoreStep { +func (u *update) Set(f TableField, v interface{}) UpdateSetMoreStep { binding := TableFieldBinding{Field: f, Value: v} u.bindings = append(u.bindings, binding) return u @@ -201,3 +206,89 @@ func exec(d Dialect, r Renderable, db *sql.DB) (sql.Result, error) { args := r.Render(d, &buf) return db.Exec(buf.String(), args...) } + +func Qualified(parts ...string) string { + tmp := []string{} + for _, part := range parts { + if part != "" { + tmp = append(tmp, part) + } + } + return strings.Join(tmp, ".") +} + +type NullableBlob struct { + Inet []byte + Valid bool // Valid is true if Inet is not NULL +} + +// Scan implements the Scanner interface. +func (self *NullableBlob) Scan(value interface{}) error { + self.Inet, self.Valid = value.([]byte) + return nil +} + +// Value implements the driver Valuer interface. +func (self NullableBlob) Value() (driver.Value, error) { + if !self.Valid { + return nil, nil + } + return self.Inet, nil +} + +type NullableDate struct { + Date time.Time + Valid bool // Valid is true if Date is not NULL +} + +// Scan implements the Scanner interface. +func (self *NullableDate) Scan(value interface{}) error { + self.Date, self.Valid = value.(time.Time) + return nil +} + +// Value implements the driver Valuer interface. +func (self NullableDate) Value() (driver.Value, error) { + if !self.Valid { + return nil, nil + } + return self.Date, nil +} + +type NullableTime struct { + Time time.Time + Valid bool // Valid is true if Time is not NULL +} + +// Scan implements the Scanner interface. +func (self *NullableTime) Scan(value interface{}) error { + self.Time, self.Valid = value.(time.Time) + return nil +} + +// Value implements the driver Valuer interface. +func (self NullableTime) Value() (driver.Value, error) { + if !self.Valid { + return nil, nil + } + return self.Time, nil +} + +type NullableDatetime struct { + Datetime time.Time + Valid bool // Valid is true if Datetime is not NULL +} + +// Scan implements the Scanner interface. +func (self *NullableDatetime) Scan(value interface{}) error { + self.Datetime, self.Valid = value.(time.Time) + return nil +} + +// Value implements the driver Valuer interface. +func (self NullableDatetime) Value() (driver.Value, error) { + if !self.Valid { + return nil, nil + } + return self.Datetime, nil +} diff --git a/sqlc/tmpl/fields.tmpl b/sqlc/tmpl/fields.tmpl index 60afb29..5b83f23 100644 --- a/sqlc/tmpl/fields.tmpl +++ b/sqlc/tmpl/fields.tmpl @@ -6,30 +6,57 @@ package sqlc import ( - "time" + "database/sql" + "reflect" + "time" +) + +var ( + typeBool = reflect.TypeOf(false) + typeDate = reflect.TypeOf(time.Unix(0, 0)) + typeDatetime = reflect.TypeOf(time.Unix(0, 0)) + typeFloat32 = reflect.TypeOf(float32(0.)) + typeFloat64 = reflect.TypeOf(float64(0.)) + typeInt = reflect.TypeOf(int(0)) + typeBlob = reflect.TypeOf([]byte{}) + typeInt64 = reflect.TypeOf(int64(0)) + typeNullBool = reflect.TypeOf(sql.NullBool{}) + typeNullDate = reflect.TypeOf(NullableDate{}) + typeNullDatetime = reflect.TypeOf(NullableDatetime{}) + typeNullFloat32 = reflect.TypeOf(sql.NullFloat64{}) + typeNullFloat64 = reflect.TypeOf(sql.NullFloat64{}) + typeNullBlob = reflect.TypeOf(NullableBlob{}) + typeNullInt = reflect.TypeOf(sql.NullInt64{}) + typeNullInt64 = reflect.TypeOf(sql.NullInt64{}) + typeNullString = reflect.TypeOf(sql.NullString{}) + typeNullTime = reflect.TypeOf(NullableTime{}) + typeString = reflect.TypeOf("") + typeTime = reflect.TypeOf(time.Unix(0, 0)) ) type InsertSetStep interface { - {{ range $_, $t := .types }} - Set{{ $t.Prefix }}({{ $t.Prefix }}Field, {{ $t.Literal }}) InsertSetMoreStep - {{ end }} + Set(TableField, interface{}) InsertSetMoreStep + {{ range $_, $t := .types }} + Set{{ $t.Prefix }}({{ $t.Prefix }}Field, {{ $t.Literal }}) InsertSetMoreStep + {{ end }} } type UpdateSetStep interface { - {{ range $_, $t := .types }} - Set{{ $t.Prefix }}({{ $t.Prefix }}Field, {{ $t.Literal }}) UpdateSetMoreStep - {{ end }} + Set(TableField, interface{}) UpdateSetMoreStep + {{ range $_, $t := .types }} + Set{{ $t.Prefix }}({{ $t.Prefix }}Field, {{ $t.Literal }}) UpdateSetMoreStep + {{ end }} } {{ range $_, $t := .types }} func (i *insert) Set{{ $t.Prefix }}(f {{ $t.Prefix }}Field, v {{ $t.Literal }}) InsertSetMoreStep { - return i.set(f,v) + return i.Set(f, v) } {{ end }} {{ range $_, $t := .types }} func (u *update) Set{{ $t.Prefix }}(f {{ $t.Prefix }}Field, v {{ $t.Literal }}) UpdateSetMoreStep { - return u.set(f,v) + return u.Set(f, v) } {{ end }} @@ -37,22 +64,22 @@ func (u *update) Set{{ $t.Prefix }}(f {{ $t.Prefix }}Field, v {{ $t.Literal }}) type Reflectable interface { {{ range $_, $t := .types }} - {{ $t.Prefix }}Field(name string) {{ $t.Prefix }}Field + {{ $t.Prefix }}Field(name string) {{ $t.Prefix }}Field {{ end }} } type Functional interface { {{ range $_, $f := $funcs }} - {{ $f.Name }}({{ signifier $f }}) Field + {{ $f.Name }}({{ signifier $f }}) Field {{ end }} } {{ range $_, $t := .types }} func (s *selection) {{ $t.Prefix }}Field(name string) {{ $t.Prefix }}Field { - return &{{ toLower $t.Prefix }}Field{name: name} + return &{{ toLower $t.Prefix }}Field{name: name} } func (t table) {{ $t.Prefix }}Field(name string) {{ $t.Prefix }}Field { - return &{{ toLower $t.Prefix }}Field{name: name, selection: t} + return &{{ toLower $t.Prefix }}Field{name: name, selection: t} } {{ end }} @@ -61,87 +88,91 @@ func (t table) {{ $t.Prefix }}Field(name string) {{ $t.Prefix }}Field { {{ range $_, $t := .types }} type {{ toLower $t.Prefix }}Field struct { - name string - selection Selectable - alias string - fun FieldFunction + name string + selection Selectable + alias string + fun FieldFunction } type {{ $t.Prefix }}Field interface { - TableField - {{ range $_, $p := $preds }} - {{ $p.FieldFunction }}(value {{ $t.Literal }}) Condition - {{ $p.JoinFunction }}(value {{ $t.Prefix }}Field) JoinCondition - {{ end }} + TableField + {{ range $_, $p := $preds }} + {{ $p.FieldFunction }}(value {{ $t.Literal }}) Condition + {{ $p.JoinFunction }}(value {{ $t.Prefix }}Field) JoinCondition + {{ end }} } func (c *{{ toLower $t.Prefix }}Field) Function() FieldFunction { - return FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - } + return FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + } } func (c *{{ toLower $t.Prefix }}Field) fct(fun, expr string, args ...interface{}) Field { - if &c.fun == nil { - return &{{ toLower $t.Prefix }}Field{ - name: c.name, - selection: c.selection, - fun: FieldFunction{Name:fun, Expr:expr, Args: args}, - } - } else { - return &{{ toLower $t.Prefix }}Field{ - name: c.name, - selection: c.selection, - fun: FieldFunction{ - Name: fun, - Expr: expr, - Args: args, - Child: &FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - }, - } - } + if &c.fun == nil { + return &{{ toLower $t.Prefix }}Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{Name:fun, Expr:expr, Args: args}, + } + } else { + return &{{ toLower $t.Prefix }}Field{ + name: c.name, + selection: c.selection, + fun: FieldFunction{ + Name: fun, + Expr: expr, + Args: args, + Child: &FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + }, + } + } } func (c *{{ toLower $t.Prefix }}Field) As(alias string) Field { - return &{{ toLower $t.Prefix }}Field{ - name: c.name, - selection: c.selection, - alias: alias, - fun: FieldFunction{ - Name: c.fun.Name, - Expr: c.fun.Expr, - Args: c.fun.Args, - Child: c.fun.Child, - }, - } + return &{{ toLower $t.Prefix }}Field{ + name: c.name, + selection: c.selection, + alias: alias, + fun: FieldFunction{ + Name: c.fun.Name, + Expr: c.fun.Expr, + Args: c.fun.Args, + Child: c.fun.Child, + }, + } } func (c *{{ toLower $t.Prefix }}Field) Alias() string { - return c.alias + return c.alias } func (c *{{ toLower $t.Prefix }}Field) MaybeAlias() string { - if c.alias == "" { - return c.name - } else { - return c.alias - } + if c.alias == "" { + return c.name + } else { + return c.alias + } } func (c *{{ toLower $t.Prefix }}Field) Name() string { - return c.name + return c.name +} + +func (c *{{ toLower $t.Prefix }}Field) Type() reflect.Type { + return type{{ $t.Prefix }} } func (c *{{ toLower $t.Prefix }}Field) Parent() Selectable { - return c.selection + return c.selection } // -- @@ -149,11 +180,11 @@ func (c *{{ toLower $t.Prefix }}Field) Parent() Selectable { {{ range $_, $p := $preds }} func (c *{{ toLower $t.Prefix }}Field) {{ $p.FieldFunction }}(pred {{ $t.Literal }}) Condition { - return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: {{ $p.Predicate }}} + return Condition{Binding: FieldBinding{Value: pred, Field: c}, Predicate: {{ $p.Predicate }}} } func (c *{{ toLower $t.Prefix }}Field) {{ $p.JoinFunction }}(pred {{ $t.Prefix }}Field) JoinCondition { - return JoinCondition{Lhs: c, Rhs: pred, Predicate: {{ $p.Predicate }}} + return JoinCondition{Lhs: c, Rhs: pred, Predicate: {{ $p.Predicate }}} } {{ end }} @@ -161,14 +192,14 @@ func (c *{{ toLower $t.Prefix }}Field) {{ $p.JoinFunction }}(pred {{ $t.Prefix } // -- func {{ $t.Prefix }}(s Selectable, name string) {{ $t.Prefix }}Field { - return &{{ toLower $t.Prefix }}Field{name: name, selection: s} + return &{{ toLower $t.Prefix }}Field{name: name, selection: s} } ////// {{ range $_, $f := $funcs }} -func (c *{{ toLower $t.Prefix }}Field) {{ $f.Name }}({{ signifier $f }}) Field { - return c.fct("{{ $f.Name }}", "{{ $f.Expr }}"{{ injectifier $f }}) +func (c *{{ toLower $t.Prefix }}Field) {{ $f.Name }}({{ signifier $f }}) Field { + return c.fct("{{ $f.Name }}", "{{ $f.Expr }}"{{ injectifier $f }}) } {{ end }} diff --git a/sqlc/tmpl/schema.tmpl b/sqlc/tmpl/schema.tmpl index 99912a0..28f74b5 100644 --- a/sqlc/tmpl/schema.tmpl +++ b/sqlc/tmpl/schema.tmpl @@ -6,62 +6,68 @@ package {{ .Package }} import ( - "github.com/relops/sqlc/sqlc" - "strings" + "github.com/shutej/sqlc/sqlc" + "strings" ) +const Schema = "{{ .Schema }}" + {{ range $_, $t := .Tables }} type {{ toLower $t.Name }} struct { - {{ range $_, $f := $t.Fields }} - {{ toUpper $f.Name }} sqlc.{{ $f.Type }}Field - {{ end }} - alias string + {{ range $_, $f := $t.Fields }} + {{ toUpper $f.Name }} sqlc.{{ $f.Type }}Field + {{ end }} + alias string } func (t *{{ toLower $t.Name }}) IsSelectable() {} +func (t *{{ toLower $t.Name }}) Schema() string { + return Schema +} + func (t *{{ toLower $t.Name }}) Name() string { - return "{{ toLower $t.Name }}" + return sqlc.Qualified(t.Schema(), "{{ toLower $t.Name }}") } func (t *{{ toLower $t.Name }}) As(a string) sqlc.Selectable { - return &{{ toLower $t.Name }}{ - {{ range $_, $f := $t.Fields }} - {{ toUpper $f.Name }}: t.{{ toUpper $f.Name }}, - {{ end }} - alias:a, - } + return &{{ toLower $t.Name }}{ + {{ range $_, $f := $t.Fields }} + {{ toUpper $f.Name }}: t.{{ toUpper $f.Name }}, + {{ end }} + alias:a, + } } func (t *{{ toLower $t.Name }}) Alias() string { - return t.alias + return t.alias } func (t *{{ toLower $t.Name }}) MaybeAlias() string { - if t.alias == "" { - return "{{ toLower $t.Name }}" - } else { - return t.alias - } + if t.alias == "" { + return "{{ toLower $t.Name }}" + } else { + return t.alias + } } ///// {{ range $_, $ty := $types }} func (t *{{ toLower $t.Name }}) {{ $ty.Prefix }}Field(name string) sqlc.{{ $ty.Prefix }}Field { - return sqlc.{{ $ty.Prefix }}({{ toUpper $t.Name }}, strings.ToUpper(name)) + return sqlc.{{ $ty.Prefix }}({{ toUpper $t.Name }}, strings.ToUpper(name)) } {{ end }} ///// func (t *{{ toLower $t.Name }}) Fields() []sqlc.Field { - return []sqlc.Field{ - {{ range $_, $f := $t.Fields }} - sqlc.{{ $f.Type }}({{ toUpper $t.Name }}, "{{ toUpper $f.Name }}"), - {{ end }} - } + return []sqlc.Field{ + {{ range $_, $f := $t.Fields }} + sqlc.{{ $f.Type }}({{ toUpper $t.Name }}, "{{ toUpper $f.Name }}"), + {{ end }} + } } {{ end }} @@ -69,12 +75,16 @@ func (t *{{ toLower $t.Name }}) Fields() []sqlc.Field { {{ range $_, $t := .Tables }} var __{{ toLower $t.Name }} = &{{ toLower $t.Name }}{} var {{ toUpper $t.Name }} = &{{ toLower $t.Name }} { - + {{ range $_, $f := $t.Fields }} - {{ toUpper $f.Name }}: sqlc.{{ $f.Type }}(__{{ toLower $t.Name }}, "{{ toUpper $f.Name }}"), + {{ toUpper $f.Name }}: sqlc.{{ $f.Type }}(__{{ toLower $t.Name }}, "{{ toUpper $f.Name }}"), {{ end }} } - -{{ end }} \ No newline at end of file +{{ end }} +var TableLikes = []sqlc.TableLike{ +{{ range $_, $t := .Tables }} + {{ toUpper $t.Name }}, +{{ end }} +} diff --git a/test/generic/call_records.go b/test/generic/call_records.go index a7fd01c..62f01be 100644 --- a/test/generic/call_records.go +++ b/test/generic/call_records.go @@ -3,8 +3,8 @@ package generic import ( "database/sql" "fmt" - "github.com/relops/sqlc/sqlc" - . "github.com/relops/sqlc/test/generated/generic" + "github.com/shutej/sqlc/sqlc" + . "github.com/shutej/sqlc/test/generated/generic" "github.com/stretchr/testify/assert" "testing" "time" diff --git a/test/migrate_db.go b/test/migrate_db.go index 17b9837..97ae958 100644 --- a/test/migrate_db.go +++ b/test/migrate_db.go @@ -8,8 +8,8 @@ import ( _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" - "github.com/relops/sqlc/sqlc" - "github.com/relops/sqlc/test" + "github.com/shutej/sqlc/sqlc" + "github.com/shutej/sqlc/test" "log" "os" ) diff --git a/test/mysql_test.go b/test/mysql_test.go index 6f8d7d9..6f0e5f7 100644 --- a/test/mysql_test.go +++ b/test/mysql_test.go @@ -3,8 +3,8 @@ package test import ( "database/sql" _ "github.com/go-sql-driver/mysql" - "github.com/relops/sqlc/sqlc" - "github.com/relops/sqlc/test/generic" + "github.com/shutej/sqlc/sqlc" + "github.com/shutej/sqlc/test/generic" "github.com/stretchr/testify/assert" "testing" ) diff --git a/test/postgres_test.go b/test/postgres_test.go index 825e8c1..e770aad 100644 --- a/test/postgres_test.go +++ b/test/postgres_test.go @@ -3,9 +3,9 @@ package test import ( "database/sql" _ "github.com/lib/pq" - "github.com/relops/sqlc/sqlc" - . "github.com/relops/sqlc/test/generated/postgres" - "github.com/relops/sqlc/test/generic" + "github.com/shutej/sqlc/sqlc" + . "github.com/shutej/sqlc/test/generated/postgres" + "github.com/shutej/sqlc/test/generic" "github.com/stretchr/testify/assert" "testing" ) diff --git a/test/sqlite_test.go b/test/sqlite_test.go index c3107bb..d9be031 100644 --- a/test/sqlite_test.go +++ b/test/sqlite_test.go @@ -3,8 +3,8 @@ package test import ( "database/sql" _ "github.com/mattn/go-sqlite3" - "github.com/relops/sqlc/sqlc" - "github.com/relops/sqlc/test/generic" + "github.com/shutej/sqlc/sqlc" + "github.com/shutej/sqlc/test/generic" "github.com/stretchr/testify/assert" "os" "testing"