SQLite without Cgo
On Saturday morning I experimented a bit. Whenever I used SQLite in a Go application, I used the popular package mattn/go-sqlite3. Not a bad choice, after all it implements the database/sql interface. One drawback, however, is the need for a C compiler, since Cgo is used to run the original SQLite code in the background.
But there is also a version of SQLite that has been transpiled from C to Go and can thus be compiled without Cgo. This also implements the database/sql interface, but it is not so easy to implement custom SQL functions with it.
Another library that tries to simplify the use of this Go variant and that also allows the easy implentation of custom functions is the package zombiezen/go-sqlite. This does not implement the standard database interface, but it is also quite easy to use and may even have some advantages.
I considered using this version in GoBlog to make my blog software easier to compile for other systems or to avoid the need for a C compiler. But in order not to start directly with such a huge project, I decided to use the library first for my URL shortener (GoShort). This was quite simple.
But what I need to investigate further before using it in GoBlog is the performance. While the performance of SQLite’s C code may be better, using the C interface introduces new performance drawbacks. I have started some benchmarks on this topic and created an issue thread.
Tags: Go GoBlog GoShort SQLite