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

try to discribe issue https://github.com/go-gorm/gorm/issues/5546 #503

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion db.go
Expand Up @@ -83,7 +83,7 @@ func OpenTestConnection() (db *gorm.DB, err error) {

func RunMigrations() {
var err error
allModels := []interface{}{&User{}, &Account{}, &Pet{}, &Company{}, &Toy{}, &Language{}}
allModels := []interface{}{&User{}, &Account{}, &Pet{}, &Company{}, &Toy{}, &Language{}, &ProcessTable{}}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(allModels), func(i, j int) { allModels[i], allModels[j] = allModels[j], allModels[i] })

Expand Down
12 changes: 7 additions & 5 deletions go.mod
Expand Up @@ -3,14 +3,16 @@ module gorm.io/playground
go 1.16

require (
github.com/denisenkom/go-mssqldb v0.12.2 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/jackc/pgx/v4 v4.16.1 // indirect
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 // indirect
gorm.io/driver/mysql v1.3.3
gorm.io/driver/postgres v1.3.5
gorm.io/driver/sqlite v1.3.2
github.com/mattn/go-sqlite3 v1.14.14 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
gorm.io/driver/mysql v1.3.5
gorm.io/driver/postgres v1.3.8
gorm.io/driver/sqlite v1.3.6
gorm.io/driver/sqlserver v1.3.2
gorm.io/gorm v1.23.4
gorm.io/gorm v1.23.8
)

replace gorm.io/gorm => ./gorm
31 changes: 26 additions & 5 deletions main_test.go
@@ -1,6 +1,8 @@
package main

import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"testing"
)

Expand All @@ -9,12 +11,31 @@ import (
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver

func TestGORM(t *testing.T) {
user := User{Name: "jinzhu"}
// Insert
DB.Transaction(func(tx *gorm.DB) error {
process := ProcessTable{Name: "test"}
if err := tx.Create(&process).Error; err != nil {
t.Errorf("Failed process !!!!!!!, got error: %v", err)
return err
}
return nil
})

DB.Create(&user)
// Ensure record does exist.
k := &ProcessTable{}
DB.First(k)
t.Log("My Name is --------------------------", k.Name)
var processes []ProcessTable

var result User
if err := DB.First(&result, user.ID).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
// Try to Delete and return the record using Clauses(clause.Returning{})
res := DB.Debug().Clauses(clause.Returning{}).Where(&ProcessTable{Name: "test"}).Delete(&processes)
if res.Error != nil {
t.Errorf("Failed process !!!!!!!, got error: %v", res.Error)
return
}
if len(processes) == 0 {
t.Errorf("Empty processes !!!!!!!")
return
}
t.Log(processes[0].Name)
}
8 changes: 8 additions & 0 deletions models.go
Expand Up @@ -58,3 +58,11 @@ type Language struct {
Code string `gorm:"primarykey"`
Name string
}

type ProcessTable struct {
ID uint64 `gorm:"column:f_id;primaryKey;autoIncrement;not null;comment:'主键'"`
Index string `gorm:"column:f_index;type:char(36);uniqueIndex;not null;comment:'UUID4'"`
Name string `gorm:"column:f_name;type:varchar(128);uniqueIndex;not null;comment:''"`
CreateTime time.Time `gorm:"column:f_create_time;autoCreateTime;not null;comment:''"`
UpdateTime time.Time `gorm:"column:f_update_time;autoUpdateTime;not null;comment:''"`
}
18 changes: 9 additions & 9 deletions test.sh
@@ -1,15 +1,15 @@
#!/bin/bash -e

dialects=("sqlite" "mysql" "postgres" "sqlserver")
dialects=("sqlite" "mysql")

if [ "$GORM_ENABLE_CACHE" = "" ]
then
rm -rf gorm
fi

[ -d gorm ] || (echo "git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')"; git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}'))

go get -u ./...
#if [ "$GORM_ENABLE_CACHE" = "" ]
#then
#rm -rf gorm
#fi
#
#[ -d gorm ] || (echo "git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')"; git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}'))
#
#go get -u ./...

for dialect in "${dialects[@]}" ; do
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]
Expand Down