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.
Execute the SELECT query using the cursor. execute() method. Get resultSet (all rows) from the cursor object using a cursor. fetchall() .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With