Skip to Content
Signet

SQLite

Bundled SQLite Store adapter and its migrations.

Signet ships a SQLite adapter in github.com/shakibdshy/signet-auth/store/sqlite. It uses modernc.org/sqlite, so no CGO is required.

go get github.com/shakibdshy/signet-auth/store/sqlite
go get modernc.org/sqlite

Setup

import (
	"database/sql"

	"github.com/shakibdshy/signet-auth/store/sqlite"
	_ "modernc.org/sqlite"
)

db, err := sql.Open("sqlite", "file:signet.db?_pragma=foreign_keys(1)")
if err != nil {
	log.Fatal(err)
}
defer db.Close()

store := sqlite.New(db)
if err := store.Migrate(ctx); err != nil {
	log.Fatal(err)
}
cfg.Store = store

Migrate applies embedded, idempotent SQL and enables PRAGMA foreign_keys = ON. When using a connection pool, include foreign_keys=1 in the DSN so every connection has the pragma set. The caller owns the *sql.DB and its lifecycle.

The DSN above creates signet.db in the working directory. Use a different path for production and back it up like any other database.

See Storage for the Store contracts and schema, and PostgreSQL for the other bundled adapter.

On this page