Pragma is a Go library that provides access to SQLite's PRAGMA operations. Pragmas are special SQLite commands that allow clients to interact with database properties and metadata, as well as perform basic administrative tasks.
go get github.com/deepilla/pragma
Import the database/sql package and an SQLite database driver.
import "database/sql"
import _ "github.com/mattn/go-sqlite3"
Import the pragma package.
import "github.com/deepilla/pragma"
Open a database connection and pass it to the pragma functions.
db, err := sql.Open("sqlite3", "path/to/sqlite.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
indexes, err := pragma.ListIndexes(db, "")
if err != nil {
log.Fatal(err)
}
for _, idx := range indexes {
fmt.Println("Found index", idx.Name, "on table", idx.Table)
}
- Property functions should use code generation.
- Handle pragmas that return values when they are updated.
- Support more database drivers. So far only the go-sqlite3 driver seems to work. Other drivers cause failing tests and even panics (e.g, gosqlite, sqlite).
- Investigate (and fix) tests that don't work as expected (see TODO comments in pragma_test.go).
- Flesh out property tests. Verifying that a database setting has been updated is fine, but we should also confirm that the database behaves as expected with the new setting.
pragma is provided under an MIT License. See the LICENSE file for details.