Formatting

This commit is contained in:
Michael Anstis 2023-02-15 07:20:20 +00:00
parent e833df1935
commit 96435e699e
11 changed files with 39 additions and 38 deletions

View File

@ -49,7 +49,8 @@ func TestSelect(t *testing.T) {
Exprs: []clause.Expression{ Exprs: []clause.Expression{
clause.Expr{ clause.Expr{
SQL: "? as name", SQL: "? as name",
Vars: []interface{}{clause.Eq{ Vars: []interface{}{
clause.Eq{
Column: clause.Column{Name: "age"}, Column: clause.Column{Name: "age"},
Value: 18, Value: 18,
}, },
@ -58,7 +59,8 @@ func TestSelect(t *testing.T) {
}, },
}, },
}, clause.From{}}, }, clause.From{}},
"SELECT `age` = ? as name FROM `users`", []interface{}{18}, "SELECT `age` = ? as name FROM `users`",
[]interface{}{18},
}, },
} }

View File

@ -16,9 +16,7 @@ import (
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
) )
var ( var regFullDataType = regexp.MustCompile(`\D*(\d+)\D?`)
regFullDataType = regexp.MustCompile(`\D*(\d+)\D?`)
)
// Migrator m struct // Migrator m struct
type Migrator struct { type Migrator struct {

View File

@ -4,6 +4,7 @@ import "time"
// Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt // Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt
// It may be embedded into your model or you may build your own model without it // It may be embedded into your model or you may build your own model without it
//
// type User struct { // type User struct {
// gorm.Model // gorm.Model
// } // }

View File

@ -174,7 +174,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
field.DataType = String field.DataType = String
field.Serializer = v field.Serializer = v
} else { } else {
var serializerName = field.TagSettings["JSON"] serializerName := field.TagSettings["JSON"]
if serializerName == "" { if serializerName == "" {
serializerName = field.TagSettings["SERIALIZER"] serializerName = field.TagSettings["SERIALIZER"]
} }

View File

@ -123,6 +123,7 @@ func (schema *Schema) parseRelation(field *Field) *Relationship {
} }
// User has many Toys, its `Polymorphic` is `Owner`, Pet has one Toy, its `Polymorphic` is `Owner` // User has many Toys, its `Polymorphic` is `Owner`, Pet has one Toy, its `Polymorphic` is `Owner`
//
// type User struct { // type User struct {
// Toys []Toy `gorm:"polymorphic:Owner;"` // Toys []Toy `gorm:"polymorphic:Owner;"`
// } // }
@ -427,7 +428,7 @@ func (schema *Schema) guessRelation(relation *Relationship, field *Field, cgl gu
foreignFields = append(foreignFields, f) foreignFields = append(foreignFields, f)
} }
} else { } else {
var primarySchemaName = primarySchema.Name primarySchemaName := primarySchema.Name
if primarySchemaName == "" { if primarySchemaName == "" {
primarySchemaName = relation.FieldSchema.Name primarySchemaName = relation.FieldSchema.Name
} }

View File

@ -70,8 +70,7 @@ type SerializerValuerInterface interface {
} }
// JSONSerializer json serializer // JSONSerializer json serializer
type JSONSerializer struct { type JSONSerializer struct{}
}
// Scan implements serializer interface // Scan implements serializer interface
func (JSONSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) { func (JSONSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) {
@ -110,8 +109,7 @@ func (JSONSerializer) Value(ctx context.Context, field *Field, dst reflect.Value
} }
// UnixSecondSerializer json serializer // UnixSecondSerializer json serializer
type UnixSecondSerializer struct { type UnixSecondSerializer struct{}
}
// Scan implements serializer interface // Scan implements serializer interface
func (UnixSecondSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) { func (UnixSecondSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) {
@ -141,8 +139,7 @@ func (UnixSecondSerializer) Value(ctx context.Context, field *Field, dst reflect
} }
// GobSerializer gob serializer // GobSerializer gob serializer
type GobSerializer struct { type GobSerializer struct{}
}
// Scan implements serializer interface // Scan implements serializer interface
func (GobSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) { func (GobSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) {

View File

@ -48,9 +48,11 @@ func (c *wrapperConnPool) Ping() error {
} }
// If you use BeginTx returned *sql.Tx as shown below then you can't record queries in a transaction. // If you use BeginTx returned *sql.Tx as shown below then you can't record queries in a transaction.
//
// func (c *wrapperConnPool) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) { // func (c *wrapperConnPool) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) {
// return c.db.BeginTx(ctx, opts) // return c.db.BeginTx(ctx, opts)
// } // }
//
// You should use BeginTx returned gorm.Tx which could wrap *sql.Tx then you can record all queries. // You should use BeginTx returned gorm.Tx which could wrap *sql.Tx then you can record all queries.
func (c *wrapperConnPool) BeginTx(ctx context.Context, opts *sql.TxOptions) (gorm.ConnPool, error) { func (c *wrapperConnPool) BeginTx(ctx context.Context, opts *sql.TxOptions) (gorm.ConnPool, error) {
tx, err := c.db.BeginTx(ctx, opts) tx, err := c.db.BeginTx(ctx, opts)

View File

@ -94,7 +94,6 @@ func TestEmbeddedStruct(t *testing.T) {
t.Errorf("expected author %s got %s", want, post.Author.Name) t.Errorf("expected author %s got %s", want, post.Author.Name)
} }
} }
} }
func TestEmbeddedPointerTypeStruct(t *testing.T) { func TestEmbeddedPointerTypeStruct(t *testing.T) {

View File

@ -1,7 +1,6 @@
package tests_test package tests_test
import ( import (
"gorm.io/gorm"
"os" "os"
"sort" "sort"
"strconv" "strconv"
@ -9,6 +8,8 @@ import (
"testing" "testing"
"time" "time"
"gorm.io/gorm"
. "gorm.io/gorm/utils/tests" . "gorm.io/gorm/utils/tests"
) )

View File

@ -75,7 +75,6 @@ func TestMigrate(t *testing.T) {
t.Fatalf("Failed to find index for many2many for %v %v", indexes[0], indexes[1]) t.Fatalf("Failed to find index for many2many for %v %v", indexes[0], indexes[1])
} }
} }
} }
func TestAutoMigrateInt8PG(t *testing.T) { func TestAutoMigrateInt8PG(t *testing.T) {
@ -1267,7 +1266,7 @@ func (mm mockMigrator) AlterColumn(dst interface{}, field string) error {
} }
func TestMigrateDonotAlterColumn(t *testing.T) { func TestMigrateDonotAlterColumn(t *testing.T) {
var wrapMockMigrator = func(m gorm.Migrator) mockMigrator { wrapMockMigrator := func(m gorm.Migrator) mockMigrator {
return mockMigrator{ return mockMigrator{
Migrator: m, Migrator: m,
} }

View File

@ -158,10 +158,11 @@ func (UserWithTableNamer) TableName(namer schema.Namer) string {
} }
func TestTableWithNamer(t *testing.T) { func TestTableWithNamer(t *testing.T) {
var db, _ = gorm.Open(tests.DummyDialector{}, &gorm.Config{ db, _ := gorm.Open(tests.DummyDialector{}, &gorm.Config{
NamingStrategy: schema.NamingStrategy{ NamingStrategy: schema.NamingStrategy{
TablePrefix: "t_", TablePrefix: "t_",
}}) },
})
sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB {
return tx.Model(&UserWithTableNamer{}).Find(&UserWithTableNamer{}) return tx.Model(&UserWithTableNamer{}).Find(&UserWithTableNamer{})