47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package schema
|
|
|
|
// Column represents a single column in a table.
|
|
type Column struct {
|
|
TableName string `db:"table_name"`
|
|
Name string `db:"column_name"`
|
|
Type string `db:"column_type"`
|
|
IsNotNull bool `db:"notnull"`
|
|
HasDefaultValue bool `db:"has_default_value"`
|
|
DefaultValue string `db:"dflt_value"`
|
|
IsPrimaryKey bool `db:"is_primary_key"`
|
|
IsForeignKey bool `db:"is_foreign_key"`
|
|
ForeignKeyTargetTable string `db:"fk_target_table"`
|
|
ForeignKeyTargetColumn string `db:"fk_target_column"`
|
|
}
|
|
|
|
// IsNullableForeignKey is a helper function.
|
|
func (c Column) IsNullableForeignKey() bool {
|
|
return !c.IsNotNull && !c.IsPrimaryKey && c.IsForeignKey
|
|
}
|
|
|
|
// Table is a single SQLite table.
|
|
type Table struct {
|
|
TableName string `db:"name"`
|
|
IsStrict bool `db:"is_strict"`
|
|
IsWithoutRowid bool `db:"is_without_rowid"`
|
|
|
|
Columns []Column
|
|
|
|
TypeIDName string
|
|
VarName string
|
|
TypeName string
|
|
}
|
|
|
|
type Index struct {
|
|
Name string `db:"index_name"`
|
|
TableName string `db:"table_name"`
|
|
Columns []string
|
|
IsUnique bool `db:"is_unique"`
|
|
// TODO: `where ...` for partial indexes
|
|
}
|
|
|
|
type Schema struct {
|
|
Tables map[string]Table
|
|
Indexes map[string]Index
|
|
}
|