2020-02-02 03:35:01 +03:00
|
|
|
package callbacks
|
|
|
|
|
2020-02-02 09:40:44 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
2020-02-03 05:40:03 +03:00
|
|
|
"github.com/jinzhu/gorm/clause"
|
2020-02-02 09:40:44 +03:00
|
|
|
)
|
2020-02-02 03:35:01 +03:00
|
|
|
|
|
|
|
func BeforeCreate(db *gorm.DB) {
|
|
|
|
// before save
|
|
|
|
// before create
|
|
|
|
|
|
|
|
// assign timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func SaveBeforeAssociations(db *gorm.DB) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func Create(db *gorm.DB) {
|
2020-02-03 05:40:03 +03:00
|
|
|
db.Statement.AddClauseIfNotExists(clause.Insert{
|
|
|
|
Table: clause.Table{Table: db.Statement.Table},
|
|
|
|
})
|
|
|
|
|
2020-02-04 03:56:15 +03:00
|
|
|
db.Statement.Build("INSERT", "VALUES", "ON_CONFLICT")
|
2020-02-03 05:40:03 +03:00
|
|
|
result, err := db.DB.ExecContext(db.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(result)
|
2020-02-02 09:40:44 +03:00
|
|
|
fmt.Println(db.Statement.SQL.String(), db.Statement.Vars)
|
2020-02-02 03:35:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func SaveAfterAssociations(db *gorm.DB) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func AfterCreate(db *gorm.DB) {
|
|
|
|
// after save
|
|
|
|
// after create
|
|
|
|
}
|