Lesson 45 of 60 · Go
Embedding a SQLite Database with `modernc.org/sqlite`
Duration: 20 minutes
SQLite in Go
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
modernc.org/sqlite is a pure‑Go SQLite driver.
$ go get modernc.org/sqlite
import (
"database/sql"
_ "modernc.org/sqlite"
)
func main() {
db, _ := sql.Open("sqlite", ":memory:")
db.Exec(`CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT)`)
db.Exec(`INSERT INTO users(name) VALUES(?)`, "Alice")
var name string
db.QueryRow(`SELECT name FROM users WHERE id=?`, 1).Scan(&name)
fmt.Println(name) // Alice
}