Title says it all. I'm using gorm (golang orm) to connect to a MS SQL db.
time.Time gets me datetime2 which is a different dataType. Any suggestions?
Structure:
type (
ACDepartements struct {
DEPTID int `gorm:"column:DEPTID;primary_key;not null;"`
DEPTNAME string `gorm:"column:DEPTNAME;size:30;"`
SUPDEPTID int `gorm:"column:SUPDEPTID;not null;"`
InheritParentSch int16 `gorm:"column:InheritParentSch;size:5;"`
InheritDeptSch int16 `gorm:"column:InheritDeptSch;"`
InheritDeptSchClass int16 `gorm:"column:InheritDeptSchClass;"`
AutoSchPlan int16 `gorm:"column:AutoSchPlan;"`
InLate int16 `gorm:"column:InLate;"`
OutEarly int16 `gorm:"column:OutEarly;"`
InheritDeptRule int16 `gorm:"column:InheritDeptRule;"`
MinAutoSchInterval int `gorm:"column:MinAutoSchInterval;"`
RegisterOT int16 `gorm:"column:RegisterOT;"`
DefaultSchId int `gorm:"column:DefaultSchId;not null;"`
ATT int16 `gorm:"column:ATT;"`
Holiday int16 `gorm:"column:Holiday;"`
OverTime int16 `gorm:"column:OverTime;"`
ChangeOperator string `gorm:"size:50;"`
ChangeTime time.Time
CreateOperator string `gorm:"size:50;"`
CreateTime time.Time
DeleteOperator string `gorm:"size:50;"`
DeleteTime time.Time
Status int
Code string `gorm:"size:50;"`
Type string `gorm:"size:50;"`
Invalidate time.Time
}
)
Connection:
func buildAcDB() *gorm.DB {
connectionString := os.Getenv("MS_SQL")
acDB, err := gorm.Open("mssql", connectionString)
if err != nil {
panic("Failed to create connection pool. Error: " + err.Error())
}
gorm.DefaultCallback.Create().Remove("mssql:set_identity_insert")
return acDB
}
Server:
func Start(db *gorm.DB, acDB *gorm.DB) {
Other stuff......
defer acDB.Close()
acDB.AutoMigrate(microlab.ACDepartements{})
}
Problem:
If I check the data structure of my created table, time variables have datetime2 instead of datetime as I want. Also int16 are int instead of smallint but I guess that doesn't matter that much.