Compare commits
9 commits
merge_chan
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
6b4e052bed | ||
|
3db4f30f56 | ||
|
256a6d4225 | ||
|
3f035a9fe2 | ||
|
c01b182839 | ||
|
e3fe976c3c | ||
|
4e1b83ab39 | ||
|
f892107dad | ||
|
fadcbfa8b6 |
9 changed files with 76 additions and 41 deletions
|
@ -170,8 +170,8 @@ func newImporter() importer {
|
|||
`"time"`,
|
||||
},
|
||||
thirdParty: importList{
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/extras/null"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/null"`,
|
||||
`"github.com/lbryio/sqlboiler/boil"`,
|
||||
`"github.com/lbryio/sqlboiler/queries"`,
|
||||
`"github.com/lbryio/sqlboiler/queries/qm"`,
|
||||
|
@ -183,9 +183,10 @@ func newImporter() importer {
|
|||
"boil_queries": imports{
|
||||
standard: importList{
|
||||
`"fmt"`,
|
||||
`"strings"`,
|
||||
},
|
||||
thirdParty: importList{
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/sqlboiler/boil"`,
|
||||
`"github.com/lbryio/sqlboiler/queries"`,
|
||||
`"github.com/lbryio/sqlboiler/queries/qm"`,
|
||||
|
@ -194,7 +195,7 @@ func newImporter() importer {
|
|||
},
|
||||
"boil_types": {
|
||||
thirdParty: importList{
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/sqlboiler/strmangle"`,
|
||||
},
|
||||
},
|
||||
|
@ -227,7 +228,7 @@ func newImporter() importer {
|
|||
},
|
||||
thirdParty: importList{
|
||||
`"github.com/kat-co/vala"`,
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/sqlboiler/boil"`,
|
||||
`"github.com/spf13/viper"`,
|
||||
},
|
||||
|
@ -265,7 +266,7 @@ func newImporter() importer {
|
|||
`"strings"`,
|
||||
},
|
||||
thirdParty: importList{
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/sqlboiler/bdb/drivers"`,
|
||||
`"github.com/lbryio/sqlboiler/randomize"`,
|
||||
`_ "github.com/lib/pq"`,
|
||||
|
@ -285,7 +286,7 @@ func newImporter() importer {
|
|||
},
|
||||
thirdParty: importList{
|
||||
`_ "github.com/go-sql-driver/mysql"`,
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/sqlboiler/bdb/drivers"`,
|
||||
`"github.com/lbryio/sqlboiler/randomize"`,
|
||||
`"github.com/spf13/viper"`,
|
||||
|
@ -302,7 +303,7 @@ func newImporter() importer {
|
|||
},
|
||||
thirdParty: importList{
|
||||
`_ "github.com/denisenkom/go-mssqldb"`,
|
||||
`"github.com/lbryio/lbry.go/extras/errors"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/errors"`,
|
||||
`"github.com/lbryio/sqlboiler/bdb/drivers"`,
|
||||
`"github.com/lbryio/sqlboiler/randomize"`,
|
||||
`"github.com/spf13/viper"`,
|
||||
|
@ -315,55 +316,55 @@ func newImporter() importer {
|
|||
// TranslateColumnType to see the type assignments.
|
||||
imp.BasedOnType = mapImports{
|
||||
"null.Float32": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Float64": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Int": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Int8": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Int16": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Int32": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Int64": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Uint": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Uint8": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Uint16": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Uint32": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Uint64": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.String": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Bool": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Time": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.JSON": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"null.Bytes": {
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`},
|
||||
thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
|
||||
},
|
||||
"time.Time": {
|
||||
standard: importList{`"time"`},
|
||||
|
|
|
@ -246,7 +246,7 @@ func TestCombineTypeImports(t *testing.T) {
|
|||
},
|
||||
thirdParty: importList{
|
||||
`"github.com/lbryio/sqlboiler/boil"`,
|
||||
`"github.com/lbryio/lbry.go/extras/null"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/null"`,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ func TestCombineTypeImports(t *testing.T) {
|
|||
},
|
||||
thirdParty: importList{
|
||||
`"github.com/lbryio/sqlboiler/boil"`,
|
||||
`"github.com/lbryio/lbry.go/extras/null"`,
|
||||
`"github.com/lbryio/lbry.go/v2/extras/null"`,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ func TestCombineImports(t *testing.T) {
|
|||
|
||||
a := imports{
|
||||
standard: importList{"fmt"},
|
||||
thirdParty: importList{"github.com/lbryio/sqlboiler", "github.com/lbryio/lbry.go/extras/null"},
|
||||
thirdParty: importList{"github.com/lbryio/sqlboiler", "github.com/lbryio/lbry.go/v2/extras/null"},
|
||||
}
|
||||
b := imports{
|
||||
standard: importList{"os"},
|
||||
|
@ -309,8 +309,8 @@ func TestCombineImports(t *testing.T) {
|
|||
if c.standard[0] != "fmt" && c.standard[1] != "os" {
|
||||
t.Errorf("Wanted: fmt, os got: %#v", c.standard)
|
||||
}
|
||||
if c.thirdParty[0] != "github.com/lbryio/sqlboiler" && c.thirdParty[1] != "github.com/lbryio/lbry.go/extras/null" {
|
||||
t.Errorf("Wanted: github.com/lbryio/sqlboiler, github.com/lbryio/lbry.go/extras/null got: %#v", c.thirdParty)
|
||||
if c.thirdParty[0] != "github.com/lbryio/sqlboiler" && c.thirdParty[1] != "github.com/lbryio/lbry.go/v2/extras/null" {
|
||||
t.Errorf("Wanted: github.com/lbryio/sqlboiler, github.com/lbryio/lbry.go/v2/extras/null got: %#v", c.thirdParty)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/lbryio/sqlboiler/boil"
|
||||
"github.com/lbryio/sqlboiler/strmangle"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type loadRelationshipState struct {
|
||||
|
@ -206,9 +206,16 @@ func (l loadRelationshipState) loadRelationshipsRecurse(depth int, obj reflect.V
|
|||
}
|
||||
|
||||
bkind := kindStruct
|
||||
if reflect.Indirect(loadedObject).Kind() != reflect.Struct {
|
||||
if derefed := reflect.Indirect(loadedObject); derefed.Kind() != reflect.Struct {
|
||||
bkind = kindPtrSliceStruct
|
||||
loadedObject = loadedObject.Addr()
|
||||
|
||||
// Convert away any helper slice types
|
||||
// elemType is *elem (from []*elem or helperSliceType)
|
||||
// sliceType is *[]*elem
|
||||
elemType := derefed.Type().Elem()
|
||||
sliceType := reflect.PtrTo(reflect.SliceOf(elemType))
|
||||
|
||||
loadedObject = loadedObject.Addr().Convert(sliceType)
|
||||
}
|
||||
return l.loadRelationships(depth+1, loadedObject.Interface(), bkind)
|
||||
}
|
||||
|
@ -241,6 +248,9 @@ func collectLoaded(key string, loadingFrom reflect.Value) (reflect.Value, bindKi
|
|||
if loadedType.Elem().Kind() == reflect.Struct {
|
||||
bkind = kindStruct
|
||||
loadedType = reflect.SliceOf(loadedType)
|
||||
} else {
|
||||
// Ensure that we get rid of all the helper "XSlice" types
|
||||
loadedType = reflect.SliceOf(loadedType.Elem())
|
||||
}
|
||||
|
||||
collection := reflect.MakeSlice(loadedType, 0, 0)
|
||||
|
@ -249,10 +259,14 @@ func collectLoaded(key string, loadingFrom reflect.Value) (reflect.Value, bindKi
|
|||
for {
|
||||
switch bkind {
|
||||
case kindStruct:
|
||||
if !loadedObject.IsNil() {
|
||||
collection = reflect.Append(collection, loadedObject)
|
||||
}
|
||||
case kindPtrSliceStruct:
|
||||
if !loadedObject.IsNil() {
|
||||
collection = reflect.AppendSlice(collection, loadedObject)
|
||||
}
|
||||
}
|
||||
|
||||
i++
|
||||
if i >= lnFrom {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
null "github.com/lbryio/lbry.go/extras/null"
|
||||
null "github.com/lbryio/lbry.go/v2/extras/null"
|
||||
)
|
||||
|
||||
type testObj struct {
|
||||
|
|
|
@ -8,9 +8,11 @@ type QueryMod func(q *queries.Query)
|
|||
// Apply the query mods to the Query object
|
||||
func Apply(q *queries.Query, mods ...QueryMod) {
|
||||
for _, mod := range mods {
|
||||
if mod != nil {
|
||||
mod(q)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SQL allows you to execute a plain SQL statement
|
||||
func SQL(sql string, args ...interface{}) QueryMod {
|
||||
|
@ -123,6 +125,12 @@ func From(from string) QueryMod {
|
|||
}
|
||||
}
|
||||
|
||||
func ForceIndex(index string) QueryMod {
|
||||
return func(q *queries.Query) {
|
||||
queries.SetForceIndex(q, index)
|
||||
}
|
||||
}
|
||||
|
||||
// Limit the number of returned rows
|
||||
func Limit(limit int) QueryMod {
|
||||
return func(q *queries.Query) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/sqlboiler/boil"
|
||||
)
|
||||
|
||||
|
@ -30,6 +30,7 @@ type Query struct {
|
|||
selectCols []string
|
||||
count bool
|
||||
from []string
|
||||
forceindex string
|
||||
joins []join
|
||||
where []where
|
||||
in []in
|
||||
|
@ -263,6 +264,11 @@ func SetLastWhereAsOr(q *Query) {
|
|||
q.where[len(q.where)-1].orSeparator = true
|
||||
}
|
||||
|
||||
// SetForceIndex sets the index to be used by the query
|
||||
func SetForceIndex(q *Query, index string){
|
||||
q.forceindex = index
|
||||
}
|
||||
|
||||
// SetLastInAsOr sets the or separator for the tail "IN" in the slice
|
||||
func SetLastInAsOr(q *Query) {
|
||||
if len(q.in) == 0 {
|
||||
|
|
|
@ -76,8 +76,14 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
|
|||
buf.WriteByte(')')
|
||||
}
|
||||
|
||||
if len(q.forceindex) > 0 {
|
||||
fmt.Fprintf(buf, " FROM %s FORCE INDEX (%s)", strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.from), ", "),q.forceindex)
|
||||
|
||||
}else{
|
||||
fmt.Fprintf(buf, " FROM %s", strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.from), ", "))
|
||||
|
||||
}
|
||||
|
||||
if len(q.joins) > 0 {
|
||||
argsLen := len(args)
|
||||
joinBuf := strmangle.GetBuffer()
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
null "github.com/lbryio/lbry.go/extras/null"
|
||||
null "github.com/lbryio/lbry.go/v2/extras/null"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/satori/go.uuid"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
null "github.com/lbryio/lbry.go/extras/null"
|
||||
null "github.com/lbryio/lbry.go/v2/extras/null"
|
||||
)
|
||||
|
||||
func TestRandomizeStruct(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue