Beego framework of ORM Module--sqlite

Source: Internet
Author: User
Tags sqlite

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.