refactor: use flowutils helpers instead of 'if err != nil'
This commit is contained in:
parent
6358d12d10
commit
f74da53c37
@ -10,6 +10,7 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
. "git.offline-twitter.com/offline-labs/gas-stack/pkg/flowutils"
|
||||
"git.offline-twitter.com/offline-labs/gas-stack/pkg/textutils"
|
||||
)
|
||||
|
||||
@ -37,32 +38,20 @@ func SchemaFromDB(db *sqlx.DB) Schema {
|
||||
ret := Schema{Tables: map[string]Table{}, Indexes: map[string]Index{}}
|
||||
|
||||
var tables []Table
|
||||
err := db.Select(&tables, `select name, is_strict, is_without_rowid from tables`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
PanicIf(db.Select(&tables, `select name, is_strict, is_without_rowid from tables`))
|
||||
for _, tbl := range tables {
|
||||
tbl.TypeName = textutils.SnakeToCamel(inflection.Singular(tbl.TableName))
|
||||
tbl.TypeIDName = tbl.TypeName + "ID"
|
||||
tbl.VarName = strings.ToLower(string(tbl.TableName[0]))
|
||||
|
||||
err = db.Select(&tbl.Columns, `select * from columns where table_name = ?`, tbl.TableName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
PanicIf(db.Select(&tbl.Columns, `select * from columns where table_name = ?`, tbl.TableName))
|
||||
ret.Tables[tbl.TableName] = tbl
|
||||
}
|
||||
|
||||
var indexes []Index
|
||||
err = db.Select(&indexes, `select index_name, table_name, is_unique from indexes`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
PanicIf(db.Select(&indexes, `select index_name, table_name, is_unique from indexes`))
|
||||
for _, idx := range indexes {
|
||||
err = db.Select(&idx.Columns, `select column_name from index_columns where index_name = ? order by rank`, idx.Name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
PanicIf(db.Select(&idx.Columns, `select column_name from index_columns where index_name = ? order by rank`, idx.Name))
|
||||
ret.Indexes[idx.Name] = idx
|
||||
}
|
||||
return ret
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user