Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

investigate gorm v2 api #417

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ require (
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.32.0
gorm.io/gorm v1.25.7
)

require (
github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.6 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/api v0.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.7 // indirect
)
21 changes: 15 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,25 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 h1:2voWjNECnrZRbfwXxHB1/j8wa6xdKn85B5NzgVL/pTU=
Expand Down Expand Up @@ -145,12 +141,19 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0/go.mod h1:r1hZAcvfFXuYmcKyCJI9w
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand All @@ -165,7 +168,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.1-0.20200116171513-9eb3fc897d6f h1:GeKe/1r/0LW8inPmRZi6zVInaZcFXiMzTnPyxITwQ8A=
github.com/lib/pq v1.3.1-0.20200116171513-9eb3fc897d6f/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -211,6 +213,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -293,6 +296,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -486,6 +491,10 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
5 changes: 3 additions & 2 deletions gorm/collection_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"strings"

"github.com/golang/protobuf/proto"
"github.com/jinzhu/gorm"
"gorm.io/gorm"
"gorm.io/gorm/schema"

"github.com/infobloxopen/atlas-app-toolkit/v2/query"
)
Expand Down Expand Up @@ -172,7 +173,7 @@
for i, k := range sourceKeys {
keyPairs = append(keyPairs, k+" = "+targetKeys[i])
}
alias := gorm.ToDBName(k)
alias := schema.NamingStrategy{}.TableName(k)
join := fmt.Sprintf("LEFT JOIN %s %s ON %s", tableName, alias, strings.Join(keyPairs, " AND "))
db = db.Joins(join)
}
Expand All @@ -184,11 +185,11 @@
offset, limit := c.PaginationToGorm(ctx, p)

if offset > 0 {
db = db.Offset(offset)

Check failure on line 188 in gorm/collection_operators.go

View workflow job for this annotation

GitHub Actions / test

cannot use offset (variable of type int32) as int value in argument to db.Offset
}

if limit > 0 {
db = db.Limit(limit)

Check failure on line 192 in gorm/collection_operators.go

View workflow job for this annotation

GitHub Actions / test

cannot use limit (variable of type int32) as int value in argument to db.Limit
}

return db
Expand Down
2 changes: 1 addition & 1 deletion gorm/collection_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"testing"

"github.com/DATA-DOG/go-sqlmock"
"github.com/jinzhu/gorm"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"gorm.io/gorm"

"github.com/infobloxopen/atlas-app-toolkit/v2/gateway"
"github.com/infobloxopen/atlas-app-toolkit/v2/query"
Expand Down Expand Up @@ -66,7 +66,7 @@
t.Fatal(err)
}
var gormDB *gorm.DB
gormDB, err = gorm.Open("postgres", db)

Check failure on line 69 in gorm/collection_operators_test.go

View workflow job for this annotation

GitHub Actions / test

cannot use "postgres" (constant of type string) as "gorm.io/gorm".Dialector value in argument to gorm.Open: string does not implement "gorm.io/gorm".Dialector (missing method BindVarTo)

Check failure on line 69 in gorm/collection_operators_test.go

View workflow job for this annotation

GitHub Actions / test

cannot use db (variable of type *sql.DB) as "gorm.io/gorm".Option value in argument to gorm.Open: *sql.DB does not implement "gorm.io/gorm".Option (missing method AfterInitialize)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions gorm/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"sort"
"strings"

"github.com/jinzhu/gorm"
"gorm.io/gorm"
"gorm.io/gorm/schema"

"github.com/infobloxopen/atlas-app-toolkit/v2/query"
"github.com/infobloxopen/atlas-app-toolkit/v2/util"
Expand Down Expand Up @@ -155,7 +156,7 @@ func preload(db *gorm.DB, obj interface{}, assoc string) (*gorm.DB, error) {
return db.Preload(assoc), nil
} else {
return db.Preload(assoc, func(db *gorm.DB) *gorm.DB {
return db.Order(gorm.ToDBName(pos))
return db.Order(schema.NamingStrategy{}.TableName(pos))
}), nil
}
}
Expand Down
5 changes: 3 additions & 2 deletions gorm/joins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package gorm
import (
"context"
"fmt"
"github.com/jinzhu/gorm"
"reflect"
"strings"

"gorm.io/gorm/schema"
)

// JoinInfo extracts the following information for assoc association of obj:
Expand Down Expand Up @@ -49,7 +50,7 @@ of foreign keys in %s association`, objType, assoc)
func parseParentChildAssoc(assoc string, assocChild bool, parent reflect.Type, child reflect.Type, assocKeys []string, fKeys []string) (string, string, []string, []string, error) {
parentTableName := tableName(parent)
childTableName := tableName(child)
alias := gorm.ToDBName(assoc)
alias := schema.NamingStrategy{}.TableName(assoc)
var dbAssocKeys, dbFKeys []string
for _, k := range assocKeys {
sf, ok := parent.FieldByName(k)
Expand Down
4 changes: 2 additions & 2 deletions gorm/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"reflect"
"sync"

"github.com/grpc-ecosystem/go-grpc-middleware"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/infobloxopen/atlas-app-toolkit/v2/rpc/errdetails"
"github.com/jinzhu/gorm"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)

// ctxKey is an unexported type for keys defined in this package.
Expand Down Expand Up @@ -108,7 +108,7 @@
defer t.mu.Unlock()

if t.current == nil {
t.current = t.parent.BeginTx(ctx, nil)

Check failure on line 111 in gorm/transaction.go

View workflow job for this annotation

GitHub Actions / test

t.parent.BeginTx undefined (type *"gorm.io/gorm".DB has no field or method BeginTx)
}

return t.current
Expand All @@ -125,7 +125,7 @@
defer t.mu.Unlock()

if t.current == nil {
t.current = t.parent.BeginTx(ctx, opts)

Check failure on line 128 in gorm/transaction.go

View workflow job for this annotation

GitHub Actions / test

t.parent.BeginTx undefined (type *"gorm.io/gorm".DB has no field or method BeginTx)
}

return t.current
Expand All @@ -140,7 +140,7 @@
if t.current == nil {
return nil
}
if reflect.ValueOf(t.current.CommonDB()).IsNil() {

Check failure on line 143 in gorm/transaction.go

View workflow job for this annotation

GitHub Actions / test

t.current.CommonDB undefined (type *"gorm.io/gorm".DB has no field or method CommonDB)
return status.Error(codes.Unavailable, "Database connection not available")
}
t.current.Rollback()
Expand All @@ -155,7 +155,7 @@
t.mu.Lock()
defer t.mu.Unlock()

if t.current == nil || reflect.ValueOf(t.current.CommonDB()).IsNil() {

Check failure on line 158 in gorm/transaction.go

View workflow job for this annotation

GitHub Actions / test

t.current.CommonDB undefined (type *"gorm.io/gorm".DB has no field or method CommonDB)
return nil
}
t.current.Commit()
Expand Down
2 changes: 1 addition & 1 deletion gorm/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

"github.com/DATA-DOG/go-sqlmock"
"github.com/infobloxopen/atlas-app-toolkit/v2/rpc/errdetails"
"github.com/jinzhu/gorm"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)

func TestUnaryServerInterceptor_success(t *testing.T) {
Expand All @@ -22,7 +22,7 @@
mock.ExpectBegin()
mock.ExpectCommit()

gdb, err := gorm.Open("postgres", db)

Check failure on line 25 in gorm/transaction_test.go

View workflow job for this annotation

GitHub Actions / test

cannot use "postgres" (constant of type string) as "gorm.io/gorm".Dialector value in argument to gorm.Open: string does not implement "gorm.io/gorm".Dialector (missing method BindVarTo)
if err != nil {
t.Fatalf("failed to open gorm db - %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions gorm/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strings"

"github.com/golang/protobuf/proto"
jgorm "github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/jinzhu/inflection"
"gorm.io/gorm/schema"

"time"

Expand Down Expand Up @@ -136,15 +136,15 @@ func tableName(t reflect.Type) string {
if tn, ok := table.(tableNamer); ok {
return tn.TableName()
}
return inflection.Plural(jgorm.ToDBName(t.Name()))
return inflection.Plural(schema.NamingStrategy{}.TableName(t.Name()))
}

func columnName(sf *reflect.StructField) string {
ex, tagCol := gormTag(sf, "column")
if ex {
return tagCol
}
return jgorm.ToDBName(sf.Name)
return schema.NamingStrategy{}.TableName(sf.Name)
}

func gormTag(sf *reflect.StructField, tag string) (bool, string) {
Expand Down
2 changes: 1 addition & 1 deletion gorm/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"strconv"
"strings"

jgorm "github.com/jinzhu/gorm"
jgorm "gorm.io/gorm"
)

// MigrationVersionValidator has a function for checking the database version
Expand Down Expand Up @@ -90,7 +90,7 @@
func VerifyMigrationVersion(db *jgorm.DB, v MigrationVersionValidator) error {
var version int64
var dirty bool
row := db.DB().QueryRow(`SELECT * FROM schema_migrations`)

Check failure on line 93 in gorm/version.go

View workflow job for this annotation

GitHub Actions / test

multiple-value db.DB() (value of type (*sql.DB, error)) in single-value context
if err := row.Scan(&version, &dirty); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion gorm/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

sqlmock "github.com/DATA-DOG/go-sqlmock"
"github.com/jinzhu/gorm"
"gorm.io/gorm"
)

func TestVersionFromPath(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions integration/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"testing"
"time"

"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)

// buildDB creates a new test Postgres database and halts the test if anything
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestReset(t *testing.T) {
t.Errorf("expected to receive an error when migrating database")
}
db.migrateUpFunction = func(*sql.DB) error {
orm, err := gorm.Open("postgres", db.GetDSN())
orm, err := gorm.Open(postgres.Open(db.GetDSN()), &gorm.Config{})
if err != nil {
t.Errorf("unable to connect to database: %v", err)
}
Expand Down
Loading