Google Go和SQLite:使用哪个库以及如何使用?

huangapple go评论118阅读模式
英文:

Google Go and SQLite: What library to use and how?

问题

我对Google的Go语言还比较新,但我正在尝试通过编写一个简单的应用程序来与SQLite 3数据库进行交互来学习更多。到目前为止,我已经找到了几个不同的SQLite库,但它们似乎都很少维护或没有文档。

我希望在这里有人能够指点我使用哪个库来处理SQLite 3,并给我一些简单的INSERT和SELECT的演示代码。

谢谢您的时间。

英文:

I'm fairly new to Google's Go, but I'm trying to learn more by writing a simple application to talk to an SQLite 3 database. So far I've come across a few different sqlite libraries, but they all seem to be sparsely maintained or have little or no documentation.

I was hoping someone here would be able to point me in the right direction by suggesting a library to use for SQLite 3, and giving me some demo code for simple INSERTs and SELECTs.

Thank you for your time.

答案1

得分: 13

$ go get github.com/mattn/go-sqlite3
sqlite3.go:在函数'_cgo_7e09c699097a_Cfunc_sqlite3_prepare_v2'中:
sqlite3.go:198:2:警告:从不兼容的指针类型传递参数5给'sqlite3_prepare_v2' [默认启用]
/usr/local/include/sqlite3.h:2924:16:注意:期望'const char **',但参数的类型是'char **'
$ # 这些警告是正常的,不用担心
$ mkdir $GOPATH/src/myproject && cd $GOPATH/src/myproject
$ wget https://raw.github.com/mattn/go-sqlite3/master/example/main.go
$ vi main.go # 这是一个使用go-sqlite3的示例

这样就可以开始了。

英文:

Edit: relevant also for Go 1.

With a recent go weekly, and an installed Sqlite3 library on a Linux system, you should:

$ go get github.com/mattn/go-sqlite3
sqlite3.go: In function ‘_cgo_7e09c699097a_Cfunc_sqlite3_prepare_v2’:
sqlite3.go:198:2: warning: passing argument 5 of ‘sqlite3_prepare_v2’ from incompatible pointer type [enabled by default]
/usr/local/include/sqlite3.h:2924:16: note: expected ‘const char **’ but argument is of type ‘char **’
$ # those warnings are OK, don't worry
$ mkdir $GOPATH/src/myproject && cd $GOPATH/src/myproject
$ wget https://raw.github.com/mattn/go-sqlite3/master/example/main.go
$ vi main.go # this is an example how to use go-sqlite3

This should get you started.

答案2

得分: 1

我的第一个建议是,对于sqlite或其他DBMS,限制你的研究范围在实现了新的database/sql API的驱动程序上(在Go Weekly中可用)。它非常干净、高效,并且限制了你的代码对驱动程序的依赖。

关于SQLite,我只找到了这个驱动程序(我不熟悉):
https://github.com/gwenn/gosqlite

英文:

My first advice, for sqlite or other DBMS, is to limit your research to drivers implementing the new database/sql API (available in Go Weekly). It's very clean, efficient, and limit the adherence of your code to the driver.

Regarding SQLite, I've only found this driver (that I don't know) :
https://github.com/gwenn/gosqlite

huangapple
  • 本文由 发表于 2012年2月19日 12:07:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/9346587.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定