Seth Seth - 4 months ago 6x
SQL Question

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

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.


Edit: relevant also for Go 1.

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

$ go get
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
$ vi main.go # this is an example how to use go-sqlite3

This should get you started.