fix (codegen): don't duplicate the primary-key getter for 'without rowid' tables
This commit is contained in:
@@ -87,6 +87,10 @@ var generate_model = &cobra.Command{
|
||||
// Skip expression indexes; there's no way to resolve an expression to a real column
|
||||
continue
|
||||
}
|
||||
if index.Origin == "pk" && table.IsWithoutRowid {
|
||||
// Already generated above, as the primary-key getter
|
||||
continue
|
||||
}
|
||||
cols := make([]schema.Column, len(index.Columns))
|
||||
for i, colName := range index.Columns {
|
||||
cols[i] = table.GetColumnByName(colName)
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package schema
|
||||
|
||||
type IndexOrigin string
|
||||
|
||||
const (
|
||||
IndexOriginCreateIndex = IndexOrigin("c")
|
||||
IndexOriginUniqueConstraint = IndexOrigin("u")
|
||||
IndexOriginPrimaryKey = IndexOrigin("pk")
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
Name string `db:"index_name"`
|
||||
TableName string `db:"table_name"`
|
||||
Columns []string
|
||||
IsUnique bool `db:"is_unique"`
|
||||
IsUnique bool `db:"is_unique"`
|
||||
Origin IndexOrigin `db:"origin"`
|
||||
// TODO: `where ...` for partial indexes
|
||||
// TODO: identify columns that are expressions
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func SchemaFromDB(db *sqlx.DB) Schema {
|
||||
}
|
||||
|
||||
var indexes []Index
|
||||
must.Do(db.Select(&indexes, `select index_name, table_name, is_unique from indexes`))
|
||||
must.Do(db.Select(&indexes, `select index_name, table_name, is_unique, origin from indexes`))
|
||||
for _, idx := range indexes {
|
||||
must.Do(db.Select(&idx.Columns, `select column_name from index_columns where index_name = ? order by rank`, idx.Name))
|
||||
ret.Indexes[idx.Name] = idx
|
||||
|
||||
@@ -27,7 +27,8 @@ create temporary view columns as
|
||||
create temporary view indexes as
|
||||
select idx.name as index_name,
|
||||
tables.name as table_name,
|
||||
idx."unique" as is_unique
|
||||
idx."unique" as is_unique,
|
||||
idx.origin as origin
|
||||
from tables
|
||||
join pragma_index_list(tables.name) idx;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user