Created
October 30, 2019 00:33
-
-
Save anta40/2b211317eb0df13424e65c5844b3605c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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