Is there a package that implements the sql.DB interface and stores the database in a file?

I am looking for a Go package that implements the official sql interface but stores everything in a single file as I don’t need advanced functions.

It does not need to behave like a SQL database requiring queries, drivers, or the like.

I believe you’re looking for SQLite:

https://www.sqlite.org/index.html

And here’s an article to get you started:

https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/05.3.html

2 Likes

@Willy I found https://github.com/mattn/go-sqlite3 a pain to use on some platforms because it requires cgo.
Luckily there’s a conversion of this db-driver to pure go: https://pkg.go.dev/modernc.org/sqlite.

Many tutorials don’t mention this option.

how do I confirm that modernc.org/sqlite implements the sql.DB interface? i don’t see it at a glance.

AFAIK it’s a drop-in replacement of mattn/go-sqlite3.
Here’s a simple example from the gitlab-repo: examples/example1/main.go · master · cznic / sqlite · GitLab

I’ve started using GitHub - glebarez/go-sqlite: pure-Go SQLite driver for Go (SQLite embedded), didn’t realize there were so many options…

I had never found that one. Seems to be a fork of modernc with slight modifications to make it more compatible with GORM: https://github.com/glebarez/go-sqlite/issues/96.

Where is the documentation for that package?

All documentation on https://pkg.go.dev/ is generated from the parsed code and the files in the git-repositories (Github/Gitlab/…). It’s a Google Service AFAIK. If you have the links to the repositories, it’s really not that hard to find the (reference) documentation. Or do you mean something else?

1 Like

Here’s the godoc:

https://pkg.go.dev/github.com/glebarez/go-sqlite

I believe it’s minimal on the documentation front because it’s just a SQL driver. Check out the example to get going if you choose to use this module:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.