您的位置 首页 golang

MacOS 安装 go-sqlite3 问题与解决

如果直接下载的话,报错如下:

 go get github.com/mattn/go-sqlite3
go get: module github.com/mattn/go-sqlite3: reading  504 Gateway Timeout
  

第一步

  Mac OS X 
1. 经过 Homebrewn 安装: html

brew install pkgconfig
brew install sqlite3
  

执行结果如下:

 ➜  ~ brew install pkgconfig
Warning: pkg-config 0.29.2_3 is already installed and up-to-date.
To reinstall 0.29.2_3, run:
  brew reinstall pkg-config
➜  ~ brew install sqlite3
Warning: sqlite 3.37.0 is already installed and up-to-date.
To reinstall 3.37.0, run:
  brew reinstall sqlite
  

第二步

 brew link pkgconfig --force
brew link sqlite3 --force
  

第三步

 go get github.com/mattn/go-sqlite3
  

结果如下:

 go: downloading github.com/mattn/go-sqlite3 v1.14.9
  

sqllite 测试用例

 package mysql

import (
 "fmt"
 "testing"

 "github.com/jinzhu/gorm"
 //_ "github.com/jinzhu/gorm/dialects/sqlite"
 _ "github.com/mattn/go-sqlite3"
)

type Product  struct  {
 gorm.Model
 Code  string
 Price uint
}

func (Product) TableName() string {
 return "hax_products"
}
func Test(t *testing.T) {
 db, err := gorm.Open("sqlite3", "test.db")
 if err != nil {
  panic("failed to connect database")
 }
 defer db.Close()
 gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
  return "hax_" + defaultTableName
 }
 db.LogMode(true)
 // Migrate the schema
 db.AutoMigrate(∏{})
 db.Create(∏{Code: "L1212", Price: 1000})
 var product Product
 db.First(&product, 1)
 var products []Product
 db.Find(&products)
 fmt.Printf("Total count %d", len(products))
}
  

macos 安装有问题,可以参考 这个解决

欢迎关注:程序员财富自由之路

在这里插入图片描述

参考资料

  • go get github.com/mattn/go-sqlite3

文章来源:智云一二三科技

文章标题:MacOS 安装 go-sqlite3 问题与解决

文章地址:https://www.zhihuclub.com/101877.shtml

关于作者: 智云科技

热门文章

网站地图