Skip to content

Instantly share code, notes, and snippets.

@anta40
Created October 30, 2019 00:33
Show Gist options
  • Save anta40/2b211317eb0df13424e65c5844b3605c to your computer and use it in GitHub Desktop.
Save anta40/2b211317eb0df13424e65c5844b3605c to your computer and use it in GitHub Desktop.
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Employee struct {
gorm.Model
ID int
Name string
Email string
Department string
}
func main() {
db, err := gorm.Open("sqlite3", "anta40_test_db.db")
if err != nil {
panic("Database connection failed...")
}
defer db.Close()
db.AutoMigrate(&Employee{})
emp1 := Employee{ID: 80911, Name: "Serge Tankian", Email: "[email protected]", Department: "Legal"}
db.NewRecord(emp1)
db.Create(&emp1)
db.Save(&emp1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment