We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
db.Exec()
db.Create()
type Example struct { Id int `gorm:"primaryKey;autoIncrement;"` CreatedAt time.Time UpdatedAt time.Time Name string } func main() { db, err := gorm.Open(sqlite.Open("test.db")) if err != nil { panic(err) } db.AutoMigrate(new(Example)) example := Example{Name: "Tome"} db.Debug().Create(&example) }
[37.259ms] [rows:1] INSERT INTO `examples` (`created_at`,`updated_at`,`name`) VALUES ("2024-10-23 10:53:07.42","2024-10-23 10:53:07.42","Tome") RETURNING `id`
type Example struct { Id int `gorm:"primaryKey;autoIncrement;"` CreatedAt time.Time UpdatedAt time.Time Name string } func main() { db, err := gorm.Open(sqlite.Open("test.db")) if err != nil { panic(err) } db.AutoMigrate(new(Example)) now := time.Now() example := Example{Name: "Tome", Id: 1, CreatedAt: now, UpdatedAt: now} sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { return tx.Create(&example) }) fmt.Println("sql:", sql) db.Exec(sql) }
sql: INSERT INTO `examples` (`created_at`,`updated_at`,`name`,`id`) VALUES ("2024-10-23 10:58:19.003","2024-10-23 10:58:19.003","Tome",1) RETURNING `id`
The text was updated successfully, but these errors were encountered:
No branches or pull requests
When using
db.Create()
to create a column containing the time, it will contain the time zoneusing
db.Exec()
The text was updated successfully, but these errors were encountered: