schema: enable parsing a schema from an existing sqlx.DB instance
This commit is contained in:
parent
1c56661560
commit
2e50736e67
@ -21,7 +21,6 @@ var create_views string
|
|||||||
func InitDB(sql_schema string) *sqlx.DB {
|
func InitDB(sql_schema string) *sqlx.DB {
|
||||||
db := sqlx.MustOpen("sqlite3", ":memory:")
|
db := sqlx.MustOpen("sqlite3", ":memory:")
|
||||||
db.MustExec(sql_schema)
|
db.MustExec(sql_schema)
|
||||||
db.MustExec(create_views)
|
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +35,7 @@ func SchemaFromSQLFile(filepath string) (Schema, error) {
|
|||||||
// SchemaFromDB takes a DB connection, checks its schema metadata tables, and returns a Schema.
|
// SchemaFromDB takes a DB connection, checks its schema metadata tables, and returns a Schema.
|
||||||
func SchemaFromDB(db *sqlx.DB) Schema {
|
func SchemaFromDB(db *sqlx.DB) Schema {
|
||||||
ret := Schema{Tables: map[string]Table{}, Indexes: map[string]Index{}}
|
ret := Schema{Tables: map[string]Table{}, Indexes: map[string]Index{}}
|
||||||
|
db.MustExec(create_views)
|
||||||
|
|
||||||
var tables []Table
|
var tables []Table
|
||||||
PanicIf(db.Select(&tables, `select name, table_type, is_strict, is_without_rowid from tables`))
|
PanicIf(db.Select(&tables, `select name, table_type, is_strict, is_without_rowid from tables`))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user