Documentation ¶
Overview ¶
Package sql implements the logic required to analyze the links between SQL tables (represented as structs in the Go source code).
Index ¶
Constants ¶
const ExhaustiveSQLTypeSwitch = "ExhaustiveSQLTypeSwitch"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builtin ¶
type Builtin struct {
// contains filtered or unexported fields
}
Builtin is a SQL type which does not require additional definitions
func (Builtin) IsNullable ¶
IsNullable returns `true` if the type comes from a sql.NullXXX type.
type Column ¶
type Column struct { // SQLType is the resolved SQL type SQLType Type // Field is the Go struct field yielding this column Field an.StructField }
type ForeignKey ¶
type ForeignKey struct { // F has underlying type int64, sql.NullInt64 or similar F an.StructField // Target is the foreign table being referenced Target TableName // IsUnique is true if an SQL UNIQUE constraint // was added as special comment IsUnique bool }
ForeignKey is a struct field used as (single) SQL foreign key.
func (ForeignKey) IsNullable ¶
func (fk ForeignKey) IsNullable() bool
IsNullable returns true if the key is optional.
func (ForeignKey) OnDelete ¶
func (fk ForeignKey) OnDelete() string
OnDelete returns the action defined by the tag `gomacro-sql-on-delete:"<action>"`, or an empty string.
func (ForeignKey) TargetIDType ¶
func (fk ForeignKey) TargetIDType() types.Type
TargetIDType returns the type used for the IDs of the target table. For nullable fields, it is the wrapped type, not the wrapper struct.
type Table ¶
type Table struct { Name *types.Named // Columns only exposes exported struct fields. Columns []Column // CustomComments are the user provided constraints // defined with `// gomacro:SQL <constraint>` comments CustomConstraints []string // contains filtered or unexported fields }
Table is a Struct used as SQL table.
func SelectTables ¶
SelectTables returns the SQL tables found in the given analysis.
func (Table) AdditionalUniqueCols ¶
`AdditionalUniqueCols` returns the columns which have a UNIQUE constraint. The columns returned by `ForeignKeys` are not included, since they usually require additional handling.
func (Table) ForeignKeys ¶
func (ta Table) ForeignKeys() (out []ForeignKey)
ForeignKeys returns the columns which are references into other tables (sorted by name). They are identified by table ID types or with the gomacro-sql-foreign:"<table>" tag.
func (Table) Primary ¶
Primary returns the index of the slice element which is the ID field, or -1 if not found
func (Table) SelectKeys ¶
SelectKeys returns a list of keys for which 'SelectByXXX' and 'DeleteByXXX' functions should be generated.