Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Go and SQLite: What library to use and how? [closed]

Tags:

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.

like image 497
Seth Avatar asked Feb 19 '12 04:02

Seth


People also ask

Which method do you need to use to execute select statement and returns a cursor over the resultSet in SQLite?

Execute the SELECT query using the cursor. execute() method. Get resultSet (all rows) from the cursor object using a cursor. fetchall() .


2 Answers

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.

like image 121
Elazar Leibovich Avatar answered Oct 21 '22 15:10

Elazar Leibovich


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

like image 39
Denys Séguret Avatar answered Oct 21 '22 16:10

Denys Séguret