Documentation ¶
Index ¶
- func ExprValue(val interface{}) interface{}
- func GenerateColumnNames(targetFile, tabledMd string, models ...interface{}) error
- func IsRecordNotFound(err error) bool
- func IsUniqueConstraintError(err error) bool
- type BaseModel
- type ColumnInfo
- type Dao
- func (d *Dao) AddIndex(c context.Context, index, validationMsg string, model Model, columns ...string) error
- func (d *Dao) AddInitialStatements(c context.Context, statement string)
- func (d *Dao) AddListener(m Model, lstnr ListenerFunc)
- func (d *Dao) AddUniqueIndex(c context.Context, index, validationMsg string, model Model, columns ...string) error
- func (d *Dao) ByID(c context.Context, m Model, id uuid.UUID) error
- func (d *Dao) ByStringID(c context.Context, m Model, strID string) error
- func (d *Dao) Clean() error
- func (d *Dao) Create(c context.Context, m Model) error
- func (d *Dao) CreateMulti(c context.Context, modls ...Model) error
- func (d *Dao) CreateOrUpdate(c context.Context, m Model) error
- func (d *Dao) CreateOrUpdateColumns(c context.Context, m Model, ci ...ColumnInfo) error
- func (d *Dao) DbInfo(c context.Context) (string, error)
- func (d *Dao) Delete(c context.Context, m Model) error
- func (d *Dao) GetDeletedByID(c context.Context, m Model, id uuid.UUID) error
- func (d *Dao) Init() error
- func (d *Dao) IsRecordNotFound(err error) bool
- func (d *Dao) Load(c context.Context, m Model) error
- func (d *Dao) Print(v ...interface{})
- func (d *Dao) Query(c context.Context) *Query
- func (d *Dao) Reload(c context.Context, models ...Model) error
- func (d *Dao) UpdateColumnValues(c context.Context, model Model, cols map[string]interface{}) error
- func (d *Dao) UpdateColumns(c context.Context, model Model, ci ...ColumnInfo) error
- type DbHook
- type DbStatsCollector
- type DeletableBaseModel
- type HookCtx
- type Listener
- type ListenerFunc
- type Logger
- type Model
- type Query
- func (q *Query) All(target interface{}) error
- func (q *Query) AllIterator(m Model) (*QueryIterator, error)
- func (q *Query) AllWithPageFull(target interface{}) (pageFull bool, err error)
- func (q *Query) Count(sample Model) (int, error)
- func (q *Query) Filter(column, operation string, value interface{}) *Query
- func (q *Query) FilterExpr(expr ...interface{}) *Query
- func (q *Query) FilterIn(column string, values ...interface{}) *Query
- func (q *Query) FilterInStrings(column string, valuesStrs ...string) *Query
- func (q *Query) FilterIsNotNull(column string) *Query
- func (q *Query) FilterRawExpression(expression string, values ...interface{}) *Query
- func (q *Query) First(target Model) error
- func (q *Query) FulltextSearch(columns []string, values []string) *Query
- func (q *Query) FulltextSubsttringSearch(table string, columns []string, values []string, limit int) (*QueryIterator, error)
- func (q *Query) IncludeDeleted() *Query
- func (q *Query) OrderByAsc(column string) *Query
- func (q *Query) OrderByDesc(column string) *Query
- func (q *Query) OrderByExpression(expr ...interface{}) *Query
- func (q *Query) OrderByRawExpression(expression string, values ...interface{}) *Query
- func (q *Query) RawIterator(sql string, values ...interface{}) (*QueryIterator, error)
- func (q *Query) RawRows(sql string, values ...interface{}) (*sql.Rows, error)
- func (q *Query) WithDefaultPageSize() *Query
- func (q *Query) WithMaxIntPageSize() *Query
- func (q *Query) WithPageNo(n int) *Query
- func (q *Query) WithPageNoString(s string) *Query
- func (q *Query) WithPageSize(s int) *Query
- func (q *Query) WithStringPageNo(n string) *Query
- type QueryIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateColumnNames ¶
func IsRecordNotFound ¶
func IsUniqueConstraintError ¶
Types ¶
type BaseModel ¶
type BaseModel struct { ID uuid.UUID `gorm:"type:uuid;primary_key;"` CreatedAt time.Time UpdatedAt time.Time }
func (*BaseModel) GenerateID ¶
func (bm *BaseModel) GenerateID()
type ColumnInfo ¶
type ColumnInfo func() (string, interface{})
type Dao ¶
type Dao struct { Logger Logger `inject:""` StatsCollector *stats.StatsCollector `inject:"db_stats"` Debug bool // contains filtered or unexported fields }
func (*Dao) AddInitialStatements ¶
func (*Dao) AddListener ¶
func (d *Dao) AddListener(m Model, lstnr ListenerFunc)
func (*Dao) AddUniqueIndex ¶
func (*Dao) CreateOrUpdateColumns ¶
func (*Dao) GetDeletedByID ¶
func (*Dao) IsRecordNotFound ¶
func (*Dao) Print ¶
func (d *Dao) Print(v ...interface{})
Print is used to log sql statements (implementation of gorm.logger)
func (*Dao) UpdateColumnValues ¶
func (*Dao) UpdateColumns ¶
type DbStatsCollector ¶
type DeletableBaseModel ¶
DeletableBaseModel can be used for tables with `deleted_at` columns.
Use GetDeletedByID() to load those entities anyway.
Note that the problem with keeping those in the table are unique columns. For example, a user with `deleted_at` set will still have an email, and any new user can't reuse it. So, if keeping deleted values is important -- maybe it would be better to keep them in another table.
type HookCtx ¶
type Logger ¶
type Logger interface { Debugf(c context.Context, format string, args ...interface{}) Infof(c context.Context, format string, args ...interface{}) Warningf(c context.Context, format string, args ...interface{}) Errorf(c context.Context, format string, args ...interface{}) Errf(c context.Context, err error, format string, args ...interface{}) Criticalf(c context.Context, format string, args ...interface{}) ClearErrorSamples() []string }
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) AllIterator ¶
func (q *Query) AllIterator(m Model) (*QueryIterator, error)
func (*Query) AllWithPageFull ¶
func (*Query) FilterExpr ¶
func (*Query) FilterInStrings ¶
func (*Query) FilterIsNotNull ¶
func (*Query) FilterRawExpression ¶
func (*Query) FulltextSearch ¶
FulltextSearch uses postgresql fulltext, which means the words must be whole (i.e. it won't search by substrings)
func (*Query) FulltextSubsttringSearch ¶
func (q *Query) FulltextSubsttringSearch(table string, columns []string, values []string, limit int) (*QueryIterator, error)
FulltextSubsttringSearch can be slow!
func (*Query) IncludeDeleted ¶
func (*Query) OrderByAsc ¶
func (*Query) OrderByDesc ¶
func (*Query) OrderByExpression ¶
func (*Query) OrderByRawExpression ¶
func (*Query) RawIterator ¶
func (q *Query) RawIterator(sql string, values ...interface{}) (*QueryIterator, error)
func (*Query) WithDefaultPageSize ¶
func (*Query) WithMaxIntPageSize ¶
func (*Query) WithPageNo ¶
func (*Query) WithPageNoString ¶
func (*Query) WithPageSize ¶
func (*Query) WithStringPageNo ¶
type QueryIterator ¶
type QueryIterator struct {
// contains filtered or unexported fields
}
func (QueryIterator) Close ¶
func (qi QueryIterator) Close()
Close closes the rows. It will be called automatically if iterator is iterated until the last line.
func (QueryIterator) Next ¶
func (qi QueryIterator) Next() bool
func (QueryIterator) Scan ¶
func (qi QueryIterator) Scan(target Model) error