Compare commits

...

3 commits

Author SHA1 Message Date
Mark
6b4e052bed
Merge pull request #10 from lbryio/eagerloading_depth
Fix multi-depth eager loading of relationships. If a relationship is …
2020-09-02 15:59:52 -04:00
Mark Beamer Jr
3db4f30f56
Fix multi-depth eager loading of relationships. If a relationship is nil, do not add it to the collection for checking the next depth level. 2020-08-19 23:43:39 -04:00
Niko Storni
256a6d4225 update lbry.go library 2020-03-05 16:29:03 -05:00
7 changed files with 41 additions and 37 deletions

View file

@ -170,8 +170,8 @@ func newImporter() importer {
`"time"`, `"time"`,
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/lbryio/lbry.go/extras/errors"`, `"github.com/lbryio/lbry.go/v2/extras/errors"`,
`"github.com/lbryio/lbry.go/extras/null"`, `"github.com/lbryio/lbry.go/v2/extras/null"`,
`"github.com/lbryio/sqlboiler/boil"`, `"github.com/lbryio/sqlboiler/boil"`,
`"github.com/lbryio/sqlboiler/queries"`, `"github.com/lbryio/sqlboiler/queries"`,
`"github.com/lbryio/sqlboiler/queries/qm"`, `"github.com/lbryio/sqlboiler/queries/qm"`,
@ -186,7 +186,7 @@ func newImporter() importer {
`"strings"`, `"strings"`,
}, },
thirdParty: importList{ 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/boil"`,
`"github.com/lbryio/sqlboiler/queries"`, `"github.com/lbryio/sqlboiler/queries"`,
`"github.com/lbryio/sqlboiler/queries/qm"`, `"github.com/lbryio/sqlboiler/queries/qm"`,
@ -195,7 +195,7 @@ func newImporter() importer {
}, },
"boil_types": { "boil_types": {
thirdParty: importList{ thirdParty: importList{
`"github.com/lbryio/lbry.go/extras/errors"`, `"github.com/lbryio/lbry.go/v2/extras/errors"`,
`"github.com/lbryio/sqlboiler/strmangle"`, `"github.com/lbryio/sqlboiler/strmangle"`,
}, },
}, },
@ -228,7 +228,7 @@ func newImporter() importer {
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/kat-co/vala"`, `"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/lbryio/sqlboiler/boil"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
}, },
@ -266,7 +266,7 @@ func newImporter() importer {
`"strings"`, `"strings"`,
}, },
thirdParty: importList{ 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/bdb/drivers"`,
`"github.com/lbryio/sqlboiler/randomize"`, `"github.com/lbryio/sqlboiler/randomize"`,
`_ "github.com/lib/pq"`, `_ "github.com/lib/pq"`,
@ -286,7 +286,7 @@ func newImporter() importer {
}, },
thirdParty: importList{ thirdParty: importList{
`_ "github.com/go-sql-driver/mysql"`, `_ "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/bdb/drivers"`,
`"github.com/lbryio/sqlboiler/randomize"`, `"github.com/lbryio/sqlboiler/randomize"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
@ -303,7 +303,7 @@ func newImporter() importer {
}, },
thirdParty: importList{ thirdParty: importList{
`_ "github.com/denisenkom/go-mssqldb"`, `_ "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/bdb/drivers"`,
`"github.com/lbryio/sqlboiler/randomize"`, `"github.com/lbryio/sqlboiler/randomize"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
@ -316,55 +316,55 @@ func newImporter() importer {
// TranslateColumnType to see the type assignments. // TranslateColumnType to see the type assignments.
imp.BasedOnType = mapImports{ imp.BasedOnType = mapImports{
"null.Float32": { "null.Float32": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Float64": { "null.Float64": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Int": { "null.Int": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Int8": { "null.Int8": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Int16": { "null.Int16": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Int32": { "null.Int32": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Int64": { "null.Int64": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Uint": { "null.Uint": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Uint8": { "null.Uint8": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Uint16": { "null.Uint16": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Uint32": { "null.Uint32": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Uint64": { "null.Uint64": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.String": { "null.String": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Bool": { "null.Bool": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Time": { "null.Time": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.JSON": { "null.JSON": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"null.Bytes": { "null.Bytes": {
thirdParty: importList{`"github.com/lbryio/lbry.go/extras/null"`}, thirdParty: importList{`"github.com/lbryio/lbry.go/v2/extras/null"`},
}, },
"time.Time": { "time.Time": {
standard: importList{`"time"`}, standard: importList{`"time"`},

View file

@ -246,7 +246,7 @@ func TestCombineTypeImports(t *testing.T) {
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/lbryio/sqlboiler/boil"`, `"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{ thirdParty: importList{
`"github.com/lbryio/sqlboiler/boil"`, `"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{ a := imports{
standard: importList{"fmt"}, 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{ b := imports{
standard: importList{"os"}, standard: importList{"os"},
@ -309,8 +309,8 @@ func TestCombineImports(t *testing.T) {
if c.standard[0] != "fmt" && c.standard[1] != "os" { if c.standard[0] != "fmt" && c.standard[1] != "os" {
t.Errorf("Wanted: fmt, os got: %#v", c.standard) 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" { 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/extras/null got: %#v", c.thirdParty) t.Errorf("Wanted: github.com/lbryio/sqlboiler, github.com/lbryio/lbry.go/v2/extras/null got: %#v", c.thirdParty)
} }
} }

View file

@ -5,9 +5,9 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/pkg/errors"
"github.com/lbryio/sqlboiler/boil" "github.com/lbryio/sqlboiler/boil"
"github.com/lbryio/sqlboiler/strmangle" "github.com/lbryio/sqlboiler/strmangle"
"github.com/pkg/errors"
) )
type loadRelationshipState struct { type loadRelationshipState struct {
@ -259,9 +259,13 @@ func collectLoaded(key string, loadingFrom reflect.Value) (reflect.Value, bindKi
for { for {
switch bkind { switch bkind {
case kindStruct: case kindStruct:
collection = reflect.Append(collection, loadedObject) if !loadedObject.IsNil() {
collection = reflect.Append(collection, loadedObject)
}
case kindPtrSliceStruct: case kindPtrSliceStruct:
collection = reflect.AppendSlice(collection, loadedObject) if !loadedObject.IsNil() {
collection = reflect.AppendSlice(collection, loadedObject)
}
} }
i++ i++

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
null "github.com/lbryio/lbry.go/extras/null" null "github.com/lbryio/lbry.go/v2/extras/null"
) )
type testObj struct { type testObj struct {

View file

@ -4,7 +4,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/lbryio/lbry.go/extras/errors" "github.com/lbryio/lbry.go/v2/extras/errors"
"github.com/lbryio/sqlboiler/boil" "github.com/lbryio/sqlboiler/boil"
) )

View file

@ -14,7 +14,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
null "github.com/lbryio/lbry.go/extras/null" null "github.com/lbryio/lbry.go/v2/extras/null"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/satori/go.uuid" "github.com/satori/go.uuid"

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
null "github.com/lbryio/lbry.go/extras/null" null "github.com/lbryio/lbry.go/v2/extras/null"
) )
func TestRandomizeStruct(t *testing.T) { func TestRandomizeStruct(t *testing.T) {