Skip to content

Commit 723bb93

Browse files
committed
Merge branch 'gormv2'
2 parents 68f6754 + 9bb7635 commit 723bb93

17 files changed

Lines changed: 177 additions & 29 deletions

StartAPIServer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99

1010
"github.com/DataManager-Go/DataManagerServer/services"
11-
"github.com/jinzhu/gorm"
11+
"gorm.io/gorm"
1212

1313
log "github.com/sirupsen/logrus"
1414
)
@@ -71,10 +71,10 @@ func awaitExit(httpServer *services.APIService, db *gorm.DB) {
7171

7272
// Close db connection
7373
if db != nil {
74-
err := db.Close()
75-
if err != nil {
76-
log.Warn(err)
77-
}
74+
// err := db.Close()
75+
// if err != nil {
76+
// log.Warn(err)
77+
// }
7878
log.Info("Database shutdown complete")
7979
}
8080

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ require (
1414
github.com/gabriel-vasile/mimetype v1.1.1
1515
github.com/gorilla/mux v1.7.4
1616
github.com/h2non/filetype v1.1.0
17-
github.com/jinzhu/gorm v1.9.14
1817
github.com/lib/pq v1.7.0 // indirect
1918
github.com/mattn/go-colorable v0.1.7 // indirect
2019
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
2120
github.com/sbani/go-humanizer v0.3.1
2221
github.com/sirupsen/logrus v1.6.0
22+
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
2323
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
2424
gopkg.in/yaml.v2 v2.3.0 // indirect
25+
gorm.io/driver/postgres v0.2.5
26+
gorm.io/gorm v0.2.20
2527
)

go.sum

Lines changed: 146 additions & 1 deletion
Large diffs are not rendered by default.

handlers/FileAttrHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/DataManager-Go/DataManagerServer/models"
88
"github.com/JojiiOfficial/gaw"
99
"github.com/gorilla/mux"
10-
"github.com/jinzhu/gorm"
10+
"gorm.io/gorm"
1111
)
1212

1313
// AttributeHandler handler for file attributes.

handlers/FileHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/gabriel-vasile/mimetype"
1818
"github.com/gorilla/mux"
1919
"github.com/h2non/filetype"
20-
"github.com/jinzhu/gorm"
2120
log "github.com/sirupsen/logrus"
21+
"gorm.io/gorm"
2222
)
2323

2424
//UploadfileHandler handler for uploading files

handlers/Router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/DataManager-Go/DataManagerServer/models"
1010

1111
"github.com/JojiiOfficial/gaw"
12-
"github.com/jinzhu/gorm"
12+
"gorm.io/gorm"
1313

1414
"github.com/gorilla/mux"
1515
log "github.com/sirupsen/logrus"

handlers/web/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/DataManager-Go/DataManagerServer/models"
1111
"github.com/JojiiOfficial/gaw"
12-
"github.com/jinzhu/gorm"
1312
log "github.com/sirupsen/logrus"
13+
"gorm.io/gorm"
1414
)
1515

1616
//HandlerData handlerData for web

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/DataManager-Go/DataManagerServer/models"
1212
"github.com/DataManager-Go/DataManagerServer/storage"
1313

14-
"github.com/jinzhu/gorm"
1514
log "github.com/sirupsen/logrus"
15+
"gorm.io/gorm"
1616

1717
"github.com/alecthomas/kingpin"
18-
_ "github.com/jinzhu/gorm/dialects/postgres"
18+
_ "gorm.io/driver/postgres"
1919
)
2020

2121
const version = "v3.12.0"

models/File.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
"github.com/JojiiOfficial/gaw"
1212
"github.com/JojiiOfficial/shred"
13-
"github.com/jinzhu/gorm"
1413
log "github.com/sirupsen/logrus"
14+
"gorm.io/gorm"
1515
)
1616

1717
var shredder = shred.Shredder{}
@@ -364,7 +364,7 @@ func (file *File) Save(db *gorm.DB) error {
364364

365365
// GetCount get count if file
366366
func (file File) GetCount(db *gorm.DB, fileID uint) (uint, error) {
367-
var c uint
367+
var c int64
368368

369369
fileFilter := File{
370370
Model: file.Model,
@@ -396,7 +396,7 @@ func (file File) GetCount(db *gorm.DB, fileID uint) (uint, error) {
396396
// Execute statement
397397
err := del.Count(&c).Error
398398

399-
return c, err
399+
return uint(c), err
400400
}
401401

402402
// GetPublicFile returns a file which is public
@@ -405,7 +405,7 @@ func GetPublicFile(db *gorm.DB, publicFilename string) (*File, bool, error) {
405405
err := db.Model(&File{}).Where("public_filename = ? AND is_public=true", publicFilename).First(&file).Error
406406
if err != nil {
407407
// Check error. Send server error if error is not "not found"
408-
if gorm.IsRecordNotFoundError(err) {
408+
if err == gorm.ErrRecordNotFound {
409409
return nil, false, nil
410410
}
411411

@@ -495,7 +495,7 @@ func (file *File) SetUniqueFilename(db *gorm.DB) bool {
495495

496496
for i := 0; i < 7; i++ {
497497
localName = gaw.RandString(40)
498-
var c int
498+
var c int64
499499
db.Model(&File{}).Where(&File{LocalName: localName}).Count(&c)
500500
if c == 0 {
501501
file.LocalName = localName

models/Group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package models
22

33
import (
4-
"github.com/jinzhu/gorm"
4+
"gorm.io/gorm"
55
)
66

77
// Group a group in DB

0 commit comments

Comments
 (0)