Compare commits
No commits in common. "89db9e14e2e61266550ec1f1041fe5cdb4244384" and "6358d12d10f9924317b41dbe8ce580c42784333f" have entirely different histories.
89db9e14e2
...
6358d12d10
@ -10,7 +10,6 @@ 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"
|
||||
)
|
||||
|
||||
@ -38,20 +37,32 @@ func SchemaFromDB(db *sqlx.DB) Schema {
|
||||
ret := Schema{Tables: map[string]Table{}, Indexes: map[string]Index{}}
|
||||
|
||||
var tables []Table
|
||||
PanicIf(db.Select(&tables, `select name, is_strict, is_without_rowid from tables`))
|
||||
err := db.Select(&tables, `select name, is_strict, is_without_rowid from tables`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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]))
|
||||
|
||||
PanicIf(db.Select(&tbl.Columns, `select * from columns where table_name = ?`, tbl.TableName))
|
||||
err = db.Select(&tbl.Columns, `select * from columns where table_name = ?`, tbl.TableName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ret.Tables[tbl.TableName] = tbl
|
||||
}
|
||||
|
||||
var indexes []Index
|
||||
PanicIf(db.Select(&indexes, `select index_name, table_name, is_unique from indexes`))
|
||||
err = db.Select(&indexes, `select index_name, table_name, is_unique from indexes`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, idx := range indexes {
|
||||
PanicIf(db.Select(&idx.Columns, `select column_name from index_columns where index_name = ? order by rank`, idx.Name))
|
||||
err = db.Select(&idx.Columns, `select column_name from index_columns where index_name = ? order by rank`, idx.Name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ret.Indexes[idx.Name] = idx
|
||||
}
|
||||
return ret
|
||||
|
||||
@ -39,7 +39,6 @@ type Index struct {
|
||||
Columns []string
|
||||
IsUnique bool `db:"is_unique"`
|
||||
// TODO: `where ...` for partial indexes
|
||||
// TODO: identify columns that are expressions
|
||||
}
|
||||
|
||||
type Schema struct {
|
||||
|
||||
@ -33,8 +33,7 @@ create temporary view indexes as
|
||||
|
||||
create temporary view index_columns as
|
||||
select indexes.index_name,
|
||||
idx_cols.cid as column_idx,
|
||||
ifnull(idx_cols.name, '') as column_name,
|
||||
idx_cols.name as column_name,
|
||||
idx_cols.seqno as rank
|
||||
from indexes
|
||||
join pragma_index_info(indexes.index_name) as idx_cols;
|
||||
|
||||
@ -43,7 +43,6 @@ create table foods (rowid integer primary key,
|
||||
cook_ratio real not null default 1
|
||||
) strict;
|
||||
create index foods_protein on foods(protein);
|
||||
create index foods_fake_index on foods(protein + 1);
|
||||
|
||||
|
||||
create table units (rowid integer primary key,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user