SQLitemeta is a Go library that provides access to SQLite metadata such as table, column and index information.
go get github.com/deepilla/sqlitemeta
Import the database/sql package along with an SQLite database driver.
import "database/sql"
import _ "github.com/mattn/go-sqlite3"
Import the sqlitemeta package.
import "github.com/deepilla/sqlitemeta"
Open a database connection and pass the handle to the sqlitemeta functions.
db, err := sql.Open("sqlite3", "/path/to/sqlite.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
tables, err := sqlitemeta.TableNames(db)
if err != nil {
log.Fatal(err)
}
for _, tbl := range tables {
indexes, err := sqlitemeta.Indexes(db, tbl)
if err != nil {
log.Fatal(err)
}
fmt.Println("Table", tbl, "has the following indexes")
for _, in := range indexes {
fmt.Println(" -", in.Name)
}
fmt.Println()
}
sqlitemeta is provided under an MIT License. See the LICENSE file for details.