Documentation
¶
Index ¶
- Constants
- func IsStructField(u interface{}, field string) bool
- func MapInterfaces(mapObj map[string]interface{}) []interface{}
- func PrettifyCreateTable(sql string) string
- func SetStructFieldValueFromString(obj interface{}, name string, value string) (bool, interface{})
- func StructFieldValueFromString(obj interface{}, name string, value string) (bool, interface{})
- type Builder
- func (b *Builder) CreateTable() string
- func (b *Builder) DatabaseColumnToFieldName(n string) string
- func (b *Builder) Delete(filters *filters.Filters) (string, error)
- func (b *Builder) DeleteByID() string
- func (b *Builder) DeleteReturningID(filters *filters.Filters) (string, error)
- func (b *Builder) DropTable() string
- func (b *Builder) HasAliasedColumnNames() bool
- func (b *Builder) HasModificationFields() bool
- func (b *Builder) Insert() string
- func (b *Builder) InsertOnConflictUpdate() string
- func (b *Builder) PasswordFields() []string
- func (b *Builder) Select(order []string, limit int, offset int, filters *filters.Filters) (string, error)
- func (b *Builder) SelectByID() string
- func (b *Builder) SelectCount(filters *filters.Filters) (string, error)
- func (b *Builder) UniqueFields() []string
- func (b *Builder) Update(values map[string]interface{}, filters *filters.Filters) (string, error)
- func (b *Builder) UpdateByID() string
- type BuilderError
- type Options
Constants ¶
const (
DefaultTagName = "sql"
)
Variables ¶
This section is empty.
Functions ¶
func IsStructField ¶
IsStructField checks if a field exists in a struct.
func MapInterfaces ¶
func MapInterfaces(mapObj map[string]interface{}) []interface{}
MapInterfaces returns a slice of interfaces from a map.
func PrettifyCreateTable ¶
PrettifyCreateTable prettifies SQL query to make it more human-readable.
func SetStructFieldValueFromString ¶ added in v0.15.2
SetStructFieldValueFromString sets a field from value that is string (converts it if necessary).
func StructFieldValueFromString ¶
StructFieldValueFromString takes a field value as string and converts it (if possible) to a value type of that field.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder reflects the object to generate and cache PostgreSQL queries (CREATE TABLE, INSERT, UPDATE, etc.). Database table and column names are lowercase with an underscore, and they are generated from field names.
func (*Builder) CreateTable ¶
CreateTable returns an SQL query for creating the table.
func (*Builder) DatabaseColumnToFieldName ¶
DatabaseColumnToFieldName takes a database column and converts it to a struct field name.
func (*Builder) Delete ¶
Delete returns a DELETE query with a WHERE condition built from 'filters' (field-value pairs). Struct fields in the 'filters' argument are sorted alphabetically. Hence, when used with a database connection, their values (or pointers to it) must be sorted as well.
func (*Builder) DeleteByID ¶
DeleteByID returns an SQL query for deleting an object by its ID.
func (*Builder) DeleteReturningID ¶
DeleteReturningID returns a DELETE query with a WHERE condition built from 'filters' (field-value pairs) with RETURNING id. Struct fields in the 'filters' argument are sorted alphabetically. Hence, when used with a database connection, their values (or pointers to it) must be sorted as well.
func (*Builder) HasAliasedColumnNames ¶
HasAliasedColumnNames returns true if any of the fields have column names in the format of "alias.column_name".
func (*Builder) HasModificationFields ¶
HasModificationFields returns true if all the following int64 fields are present: CreatedAt, CreatedBy, ModifiedAt, ModifiedBy.
func (*Builder) InsertOnConflictUpdate ¶
InsertOnConflictUpdate returns an SQL query for inserting when a conflict is detected.
func (*Builder) PasswordFields ¶
PasswordFields returns a list with field names that are passwords.
func (*Builder) Select ¶
func (b *Builder) Select(order []string, limit int, offset int, filters *filters.Filters) (string, error)
Select returns a SELECT query with a WHERE condition built from 'filters' (field-value pairs). Struct fields in the 'filters' argument are sorted alphabetically. Hence, when used with a database connection, their values (or pointers to it) must be sorted as well. Columns in the SELECT query are ordered the same way as they are defined in the struct: SELECT field1_column, field2_column, ... etc.
func (*Builder) SelectByID ¶
SelectByID returns an SQL query for selecting an object by its ID.
func (*Builder) SelectCount ¶
SelectCount returns a SELECT COUNT(*) query to count rows with a WHERE condition built from 'filters' (field-value pairs). Struct fields in the 'filters' argument are sorted alphabetically. Hence, when used with a database connection, their values (or pointers to it) must be sorted as well.
func (*Builder) UniqueFields ¶
UniqueFields returns a list with field names that are unique.
func (*Builder) Update ¶
Update returns an UPDATE query where specified struct fields (columns) are updated and rows match specific WHERE condition built from 'filters' (field-value pairs). Struct fields in 'values' and the 'filters' arguments are sorted alphabetically. Hence, when used with a database connection, their values (or pointers to it) must be sorted as well.
func (*Builder) UpdateByID ¶
UpdateByID returns an SQL query for updating an object by their ID.
type BuilderError ¶
func (*BuilderError) Error ¶
func (e *BuilderError) Error() string