Move schema parsing to its own package
All checks were successful
CI / release-test (push) Successful in 4s
All checks were successful
CI / release-test (push) Successful in 4s
This commit is contained in:
34
pkg/schema/table.go
Normal file
34
pkg/schema/table.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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:"strict"`
|
||||
Columns []Column
|
||||
|
||||
TypeIDName string
|
||||
VarName string
|
||||
TypeName string
|
||||
}
|
||||
|
||||
// Schema is a container for a bunch of Tables, indexed by table name.
|
||||
type Schema map[string]Table
|
||||
Reference in New Issue
Block a user