go download all packages
go mod || go get .commonly used go packages
package main
 
import (
    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/sqlite"
)
 
type Product struct {
  gorm.Model
  Code string
  Price uint
}
 
func main() {
  db, err := gorm.Open("sqlite3", "test.db")
  if err != nil {
    panic("failed to connect database")
  }
  defer db.Close()
 
  // Migrate the schema
  db.AutoMigrate(&Product{})
 
  // Create
  db.Create(&Product{Code: "L1212", Price: 1000})
 
  // Read
  var product Product
  db.First(&product, 1) // find product with id 1
  db.First(&product, "code = ?", "L1212")
 
  // Update - update product's price to 2000
  db.Model(&product).Update("Price", 2000)
 
  // Delete - delete product
  db.Delete(&product)Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us
