SQLite3 is a lightweight, file-based SQL database. It is very useful to quickly build persistence for API. It leverages the SQL language and a relational database. In this section, we see how to interact with SQLite3 from Go.
All SQLite3 operations are going to be done using the go-sqlite3 library. We can install that package using the following command:
go get github.com/mattn/go-sqlite3
The special thing about this library is that it uses the internal sql package of Go. We usually import database/sql and use SQL to execute database queries on the database (here, SQLite3):
import "database/sql"
Now, we can use the following steps to create a database driver and then execute the SQL commands on it using the Query method:
- Let's create a file in this path:
touch -p $GOPATH/src/github.com/git-user/chapter4/sqliteExample/main.go...