dao

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRows              = sql.ErrNoRows
	ErrConstraintViolation = errors.New("constraint violation")
)

Functions

func EachField added in v0.6.0

func EachField(entity interface{}, fn func(field reflect.StructField, value reflect.Value, column string))

EachField traverse each database field

Types

type AttemptDAO

type AttemptDAO interface {
	BaseDAO[entities.Attempt]
	UpdateStatusToQueued(ctx context.Context, ids []string) error
	UpdateErrorCode(ctx context.Context, id string, status entities.AttemptStatus, code entities.AttemptErrorCode) error
	UpdateDelivery(ctx context.Context, result *AttemptResult) error
	ListUnqueuedForUpdate(ctx context.Context, maxScheduledAt time.Time, limit int) (list []*entities.Attempt, err error)
}

func NewAttemptDao

func NewAttemptDao(db *sqlx.DB, fns ...OptionFunc) AttemptDAO

type AttemptDetailDAO added in v0.2.0

type AttemptDetailDAO interface {
	BaseDAO[entities.AttemptDetail]
	Insert(ctx context.Context, attemptDetail *entities.AttemptDetail) error
}

func NewAttemptDetailDao added in v0.2.0

func NewAttemptDetailDao(db *sqlx.DB, fns ...OptionFunc) AttemptDetailDAO

type AttemptQuery added in v1.1.0

type AttemptQuery struct {
	Query

	IDs        []string
	EventId    *string
	EndpointId *string
	Status     *string
}

func (*AttemptQuery) ToQuery added in v1.1.0

func (q *AttemptQuery) ToQuery() *Query

type AttemptResult

type AttemptResult struct {
	ID          string
	Request     *entities.AttemptRequest
	Response    *entities.AttemptResponse
	AttemptedAt types.Time
	Status      entities.AttemptStatus
	ErrorCode   *entities.AttemptErrorCode
	Exhausted   bool
}

type BaseDAO

type BaseDAO[T any] interface {
	Get(ctx context.Context, id string) (*T, error)
	Select(ctx context.Context, field string, id string) (*T, error)
	Insert(ctx context.Context, entity *T) error
	Update(ctx context.Context, entity *T) error
	Upsert(ctx context.Context, fields []string, entity *T) error
	Delete(ctx context.Context, id string) (bool, error)
	Count(ctx context.Context, query *Query) (int64, error)
	List(ctx context.Context, query *Query) ([]*T, error)
	Cursor(ctx context.Context, query *Query) (Cursor[*T], error)
	BatchInsert(ctx context.Context, entities []*T) error
	Iterate(ctx context.Context, query *Query) *Iterator[T]
}

type Condition added in v1.1.0

type Condition struct {
	Column string
	Op     Operator
	Value  interface{}
}

type Cursor added in v1.1.0

type Cursor[T any] struct {
	Cursor   bool
	Reversed bool
	Data     []T
	// Deprecated
	Total   int64
	HasMore bool
	FirstId *string
	LastId  *string
}

type DAO

type DAO[T Schema] struct {
	// contains filtered or unexported fields
}

func NewDAO

func NewDAO[T Schema](db *sqlx.DB, opts Options) *DAO[T]

func (*DAO[T]) BatchInsert

func (dao *DAO[T]) BatchInsert(ctx context.Context, entities []*T) error

func (*DAO[T]) Count

func (dao *DAO[T]) Count(ctx context.Context, query *Query) (total int64, err error)

func (*DAO[T]) Cursor added in v1.1.0

func (dao *DAO[T]) Cursor(ctx context.Context, query *Query) (cursor Cursor[*T], err error)

func (*DAO[T]) DB

func (dao *DAO[T]) DB(ctx context.Context) Queryable

func (*DAO[T]) Delete

func (dao *DAO[T]) Delete(ctx context.Context, id string) (bool, error)

func (*DAO[T]) Get

func (dao *DAO[T]) Get(ctx context.Context, id string) (entity *T, err error)

func (*DAO[T]) Insert

func (dao *DAO[T]) Insert(ctx context.Context, entity *T) error

func (*DAO[T]) Iterate added in v1.1.0

func (dao *DAO[T]) Iterate(ctx context.Context, query *Query) *Iterator[T]

func (*DAO[T]) List

func (dao *DAO[T]) List(ctx context.Context, query *Query) (list []*T, err error)

func (*DAO[T]) Select added in v0.4.0

func (dao *DAO[T]) Select(ctx context.Context, field string, value string) (entity *T, err error)

func (*DAO[T]) Update

func (dao *DAO[T]) Update(ctx context.Context, entity *T) error

func (*DAO[T]) Upsert added in v0.4.0

func (dao *DAO[T]) Upsert(ctx context.Context, fields []string, entity *T) error

type EndpointDAO

type EndpointDAO interface {
	BaseDAO[entities.Endpoint]
	Disable(ctx context.Context, id string) (bool, error)
}

func NewEndpointDAO

func NewEndpointDAO(db *sqlx.DB, fns ...OptionFunc) EndpointDAO

type EndpointQuery added in v1.1.0

type EndpointQuery struct {
	Query
	Enabled     *bool
	WorkspaceId *string
}

func (*EndpointQuery) ToQuery added in v1.1.0

func (q *EndpointQuery) ToQuery() *Query

type EventDAO

type EventDAO interface {
	BaseDAO[entities.Event]
	BatchInsertIgnoreConflict(ctx context.Context, events []*entities.Event) ([]string, error)
	ListExistingUniqueIDs(ctx context.Context, uniques []string) ([]string, error)
}

func NewEventDao

func NewEventDao(db *sqlx.DB, fns ...OptionFunc) EventDAO

type EventQuery added in v1.1.0

type EventQuery struct {
	Query
}

type Iterator added in v1.1.0

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

func (*Iterator[T]) Current added in v1.1.0

func (it *Iterator[T]) Current() *T

func (*Iterator[T]) Err added in v1.1.0

func (it *Iterator[T]) Err() error

func (*Iterator[T]) Next added in v1.1.0

func (it *Iterator[T]) Next() bool

type Operator added in v1.1.0

type Operator int

Operator SQL operator

const (
	// Equal =
	Equal Operator = iota
	// GreaterThan >
	GreaterThan
	// GreaterThanOrEqual >=
	GreaterThanOrEqual
	// LessThan <
	LessThan
	// LessThanOrEqual <=
	LessThanOrEqual
	// JsonContain @>
	JsonContain
)

type OptionFunc added in v1.0.1

type OptionFunc func(*Options)

func WithInstrumented added in v1.0.1

func WithInstrumented() OptionFunc

func WithPropagateHandler added in v1.0.1

func WithPropagateHandler(fn func(ctx context.Context, opts *Options, id string, entity interface{})) OptionFunc

func WithWorkspace added in v1.0.1

func WithWorkspace(workspace bool) OptionFunc

type Options added in v0.3.0

type Options struct {
	Table            string
	EntityName       string
	Workspace        bool
	CachePropagate   bool
	CacheName        string
	PropagateHandler func(ctx context.Context, opts *Options, id string, entity interface{})
	Instrumented     bool
}

type Order added in v1.1.0

type Order struct {
	Column string
	Sort   Sort
}

func (Order) SQL added in v1.1.0

func (o Order) SQL() string

type PluginDAO added in v0.2.0

type PluginDAO interface {
	BaseDAO[entities.Plugin]
}

func NewPluginDAO added in v0.2.0

func NewPluginDAO(db *sqlx.DB, fns ...OptionFunc) PluginDAO

type PluginQuery added in v1.1.0

type PluginQuery struct {
	Query

	WorkspaceId *string
	EndpointId  *string
	SourceId    *string
	Enabled     *bool
}

func (*PluginQuery) ToQuery added in v1.1.0

func (q *PluginQuery) ToQuery() *Query

type Query added in v1.1.0

type Query struct {
	Offset      int
	Limit       int
	Wheres      []Condition
	Orders      []Order
	CursorModel bool
	Reverse     bool
}

func (*Query) Order added in v1.1.0

func (q *Query) Order(column string, sort Sort) *Query

func (*Query) Page added in v1.1.0

func (q *Query) Page(pageNo, pageSize int)

func (*Query) Where added in v1.1.0

func (q *Query) Where(column string, op Operator, value any) *Query

type Queryable

type Queryable interface {
	sqlx.ExtContext
	GetContext(context.Context, interface{}, string, ...interface{}) error
	SelectContext(context.Context, interface{}, string, ...interface{}) error
}

Queryable is an interface to be used interchangeably for sqlx.Db and sqlx.Tx

type Schema added in v1.1.0

type Schema interface {
	PrimaryKey() string
}

type SchemaMeta added in v1.1.0

type SchemaMeta struct {
	Name string
	// contains filtered or unexported fields
}

func NewSchema added in v1.1.0

func NewSchema[T any](name string) *SchemaMeta

func (*SchemaMeta) Columns added in v1.1.0

func (s *SchemaMeta) Columns() []string

func (*SchemaMeta) HasColumn added in v1.1.0

func (s *SchemaMeta) HasColumn(column string) bool

func (*SchemaMeta) InsertColumns added in v1.1.0

func (s *SchemaMeta) InsertColumns() []string

type Sort added in v1.1.0

type Sort = string
const (
	ASC  Sort = "ASC"
	DESC Sort = "DESC"
)

type SourceDAO

type SourceDAO interface {
	BaseDAO[entities.Source]
}

func NewSourceDAO

func NewSourceDAO(db *sqlx.DB, fns ...OptionFunc) SourceDAO

type SourceQuery added in v1.1.0

type SourceQuery struct {
	Query

	WorkspaceId *string
}

func (*SourceQuery) ToQuery added in v1.1.0

func (q *SourceQuery) ToQuery() *Query

type WorkspaceDAO

type WorkspaceDAO interface {
	BaseDAO[entities.Workspace]
	GetDefault(ctx context.Context) (*entities.Workspace, error)
	GetWorkspace(ctx context.Context, name string) (*entities.Workspace, error)
}

func NewWorkspaceDAO

func NewWorkspaceDAO(db *sqlx.DB, fns ...OptionFunc) WorkspaceDAO

type WorkspaceQuery added in v1.1.0

type WorkspaceQuery struct {
	Query
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL