feat: null_safety test

This commit is contained in:
2024-12-29 21:39:29 +07:00
parent b32eafb43d
commit 9a66f2f2a7
9 changed files with 107 additions and 36 deletions

View File

@@ -0,0 +1,29 @@
package null_safety
type Order1 struct {
Id uint `gorm:"primaryKey"`
Description string
// not nullable - not nullable
CustomerId uint `gorm:"not null;foreignKey:CustomerId;"`
}
type Order2 struct {
Id uint `gorm:"primaryKey"`
Description string
// nullable - nullable
CustomerId *uint `gorm:"null;foreignKey:CustomerId;"`
}
type Order3 struct {
Id uint `gorm:"primaryKey"`
// nullable - unspecified
Status *string
Description string
}
type Order4 struct {
Id uint `gorm:"primaryKey"`
// not nullable - unspecified
Status *string
Description string
}

View File

@@ -0,0 +1,29 @@
package null_safety
type Order5 struct {
Id uint `gorm:"primaryKey"`
Description string
// not nullable - nullable
CustomerId uint `gorm:"null;foreignKey:CustomerId;"` // want "Null safety error in \"Order5\" model, field \"CustomerId\": column nullable policy doesn't match to tag nullable policy"
}
type Order6 struct {
Id uint `gorm:"primaryKey"`
Description string
// nullable - not nullable
CustomerId *uint `gorm:"not null;foreignKey:CustomerId;"` // want "Null safety error in \"Order6\" model, field \"CustomerId\": column nullable policy doesn't match to tag nullable policy"
}
type Order7 struct {
Id uint `gorm:"primaryKey"`
Description string
// not nullable - not nullable, nullable
CustomerId uint `gorm:"not null;foreignKey:CustomerId;null;"` // want "Null safety error: tags \"null\" and \"not null\" are specified at one field"
}
type Order8 struct {
Id uint `gorm:"primaryKey"`
Description string
// nullable - not nullable, nullable
CustomerId *uint `gorm:"not null;foreignKey:CustomerId;null;"` // want "Null safety error: tags \"null\" and \"not null\" are specified at one field"
}