Documentation
¶
Index ¶
- Variables
- func AutoMigrate(pool *pgxpool.Pool, driver string, models ...interface{}) error
- func Columns(v interface{}, dialect string) ([]string, []string, error)
- func DeleteSchema(v interface{}, dialect string) (string, error)
- func GetTableName(v interface{}) string
- func GetType(model any) any
- func InsertSchema(v interface{}, dialect string) (string, []interface{}, error)
- func IsPointer(v interface{}) bool
- func IsPointerToArrayOfStructPointer(v interface{}) bool
- func IsSlice(v interface{}) bool
- func IsStruct(v interface{}) bool
- func IsStructPointer(v interface{}) bool
- func NewStructPointer(model interface{}) any
- func OrmType(v *reflect.Value) string
- func Schema(v interface{}, dialect string) (string, error)
- func SnakeCase(s string) string
- func UpdateSchema(v interface{}, filter *query.QueryFilter, dialect string) (string, []interface{}, error)
- type Constraint
- type Field
- func (f *Field) FKExists(constraint_name string) bool
- func (f *Field) IsAutoIncrement() bool
- func (f *Field) IsConstraint(tagName string) bool
- func (field *Field) IsForeignKey() bool
- func (f *Field) IsPrimaryKey() bool
- func (f *Field) IsPrimaryKeyAndZero() bool
- func (f *Field) PrintTags()
- func (f *Field) PrintType(sqlType string, dialect string)
- func (f *Field) String() string
- func (f *Field) WriteFieldConstraints(k, v string)
- type ForeignKey
- type TableSchema
- func (table *TableSchema) DeleteSchema(dialect string) string
- func (t *TableSchema) Flush()
- func (table *TableSchema) InsertSchema(v interface{}, dialect string) (string, []interface{})
- func (t *TableSchema) String(dialect string) string
- func (table *TableSchema) UpdateSchema(v interface{}, dialect string) (string, []interface{})
- func (t *TableSchema) WriteColumns(dialect string)
- func (t *TableSchema) WriteCompositeUnique()
- func (t *TableSchema) WriteHeader()
- func (t *TableSchema) WritePrimaryKey()
- func (t *TableSchema) WriteUniqueFields()
Constants ¶
This section is empty.
Variables ¶
var ForeignKeys = make(map[string][]*ForeignKey)
Functions ¶
func AutoMigrate ¶
Creates all tables, constraints and relations. NB: This does not alter existing table schema and is not recommendated as a solid migration option.
func DeleteSchema ¶
Returns the string for DELETE statement
func GetTableName ¶
func GetTableName(v interface{}) string
func GetType ¶
Initializes a pointer to the underlying model struct model must be a struct pointer e.g model := &Model{}
func InsertSchema ¶
Returns the string for the Insert query
func IsPointerToArrayOfStructPointer ¶
func IsPointerToArrayOfStructPointer(v interface{}) bool
v must be a of the form *[]*Model{}
func IsStructPointer ¶
func IsStructPointer(v interface{}) bool
Returns true if v is a pointer to a struct
func NewStructPointer ¶
func NewStructPointer(model interface{}) any
Creates a new struct pointer from a *[]*Model
func Schema ¶
Calls GetTableSchema to generate the sql for creating the table and all constraints. If you are interested in the TableSchema data structure call schema.GetTableSchema
func UpdateSchema ¶
func UpdateSchema(v interface{}, filter *query.QueryFilter, dialect string) (string, []interface{}, error)
Returns the string for the UpdateQuery
Types ¶
type Constraint ¶
type Field ¶
type Field struct { Name string Type string Tags map[string]string ReflectObjType *reflect.StructField ReflectObjValue *reflect.Value Table *TableSchema // contains filtered or unexported fields }
Field is the data structure that stores data about a single struct field
func (*Field) FKExists ¶
Checks if a foreign key with constraint constraint_name exists in a global map of foreign keys
func (*Field) IsAutoIncrement ¶
func (*Field) IsConstraint ¶
func (*Field) IsForeignKey ¶
func (*Field) IsPrimaryKey ¶
func (*Field) IsPrimaryKeyAndZero ¶
func (*Field) String ¶
Returns the complete string representing the schema of a single column
e.g : name varchar(200) not null unique
func (*Field) WriteFieldConstraints ¶
Write field tags representing constraints to the underlying field bytes.Buffer
type ForeignKey ¶
type ForeignKey struct { ConstraintName string FK string OnDelete string OnUpdate string TableName string ParentTable string ParentPkColumn string }
func (*ForeignKey) String ¶
func (fk *ForeignKey) String() string
type TableSchema ¶
type TableSchema struct { TableName string Fields []*Field PrimaryKey *Field ForeignKeys map[string]*ForeignKey UniqueFields []*Field CompositeIndexes map[string][]*Field Constraints []*Constraint // contains filtered or unexported fields }
func GetTableSchema ¶
func GetTableSchema(m interface{}, dialect string) (*TableSchema, error)
Generates the table schema for struct m
Returns a pointer to TableSchema and an error if m is not a struct or pointer to a struct
func (*TableSchema) DeleteSchema ¶
func (table *TableSchema) DeleteSchema(dialect string) string
Returns the sql string for deleting the table with a trailing empty space Warning: Does not include the where clause
func (*TableSchema) Flush ¶
func (t *TableSchema) Flush()
func (*TableSchema) InsertSchema ¶
func (table *TableSchema) InsertSchema(v interface{}, dialect string) (string, []interface{})
Returns the sql string for creating the table
func (*TableSchema) String ¶
func (t *TableSchema) String(dialect string) string
Returns the sql string for creating the table
func (*TableSchema) UpdateSchema ¶
func (table *TableSchema) UpdateSchema(v interface{}, dialect string) (string, []interface{})
Returns the sql string for updating the table
func (*TableSchema) WriteColumns ¶
func (t *TableSchema) WriteColumns(dialect string)
func (*TableSchema) WriteCompositeUnique ¶
func (t *TableSchema) WriteCompositeUnique()
func (*TableSchema) WriteHeader ¶
func (t *TableSchema) WriteHeader()
func (*TableSchema) WritePrimaryKey ¶
func (t *TableSchema) WritePrimaryKey()
func (*TableSchema) WriteUniqueFields ¶
func (t *TableSchema) WriteUniqueFields()