Today, based on the Beego ORM demo Sqlite3 database, a small problem was encountered.
Symptom 1: Download go-sqlite3 (Go get github.com/mattn/go-sqlite3) driver times it's wrong to say that GCC is not in the PATH directory.
Symptom 2: Compile an error when you run the file that imported the Go-sqlite3 driver. GCC is not in the PATH directory.
The cause of the problem: Sqlitle3 is a CGO library that needs to GCD compile C code.
Solution to the problem: Install TDM-GCC or MinGW. (Note: I installed the tdm-gcc,:http://tdm-gcc.tdragon.net/download)
The Beego framework connects and processes the Sqlite3 database.
Models/models.go
1 Package Models2 3 Import (4 "Github.com/astaxie/beego/orm"5 )6 7Type Studentstruct {8Idint //PRIMARY Key9NamestringTenAgeint OneSexstring A score float32 -Addrstring - } the - func init () { -Orm. Registermodel (New(Student)) -}
Main.go
Package Mainimport ("FMT" "Github.com/astaxie/beego" "Github.com/astaxie/beego/orm" "Ormsqlite/models" _ "Github.com/mattn/go-sqlite3" _ "ormsqlite/routers") Func init () {orm. Registerdriver ("SQLite", Orm. Dr_sqlite) Orm. RegisterDatabase ("default","Sqlite3","./datas/test.db") Orm. RUNSYNCDB ("default",false,true)}func Main () {o:=ORM. Neworm () o.using ("default") Stu:=New(models. Student) Stu. Name="bei"Stu. Age= -Stu. Sex="m"Stu. Score= theStu. Addr="Hunan.leiyang"FMT. Println (O.insert (Stu)) Beego. Run ()}
View data in sqlite_db:
Beego framework of ORM Module--sqlite