Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "time"
- "log"
- "fmt"
- "github.com/jinzhu/gorm"
- _ "github.com/jinzhu/gorm/dialects/postgres"
- )
- type Product struct {
- gorm.Model
- Code string
- Birthday time.Time
- }
- func main() {
- db, err := gorm.Open("postgres", "host=localhost user=sdp dbname=sdp sslmode=disable password=sdp")
- if err != nil {
- log.Print(err)
- panic("failed to connect database")
- }
- defer db.Close()
- //db.Set("timezone", "Asia/Tehran")
- db.LogMode(true)
- // Read
- var product Product
- db.First(&product, 1) // find product with id 1
- // Update - update product's price to 2000
- fmt.Println(product.Birthday)
- db.Model(&product).Update("Birthday", time.Now().Add(time.Hour))
- fmt.Println(product.Birthday)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement