db

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOffset = 0
	DefaultPage   = 1
	DefaultLimit  = 10
)

Variables

View Source
var (
	ErrorRecordNotFound      error = NewError(404, "record not found")
	ErrorRecordAlreadyExists error = NewError(409, "record already exists")
)
View Source
var EmptyJsonArray = &JsonArray{
	JSONText: emptyJSONArray,
	Valid:    true,
}
View Source
var EmptyJsonObject = &JsonObject{
	JSONText: emptyJSON,
	Valid:    true,
}

Functions

func BuildPlaceholder

func BuildPlaceholder(count int) string

func PlaceholderRepeat

func PlaceholderRepeat(placeholder string, repeat int) []string

func ToDriverValueFromStringArray

func ToDriverValueFromStringArray(collection []string) []driver.Value

Types

type Error added in v0.3.0

type Error struct {
	Code    int
	Message string
}

func NewError added in v0.3.0

func NewError(code int, message string) Error

func (Error) Error added in v0.3.0

func (e Error) Error() string

func (Error) ErrorCode added in v0.3.0

func (e Error) ErrorCode() int

type FilterIn

type FilterIn struct {
	Field  string
	Values []interface{}
}

type FilterIns

type FilterIns []FilterIn

type FilterItem

type FilterItem struct {
	Field string
	Op    Operator
	Value interface{}
}

type FilterItems

type FilterItems []FilterItem

type Filters

type Filters struct {
	Ands FilterItems
	Ors  FilterItems
	Ins  FilterIns
	In   *FilterIn
}

func (*Filters) Build

func (f *Filters) Build(separator string) (string, []interface{})

func (*Filters) BuildWithWherePrefix

func (f *Filters) BuildWithWherePrefix(separator string) (string, []interface{})

func (*Filters) FindField

func (f *Filters) FindField(fl string, fb FindBy) Filters

type FindBy

type FindBy string
const (
	FindByExact  FindBy = "exact"
	FindByPrefix FindBy = "prefix"
)

func (FindBy) Match

func (t FindBy) Match(input, target string) bool

type IHelper

type IHelper interface {
	BuildSqlAndArgs() (string, []interface{})
	BuildSqlAndArgsWithWherePrefix() (string, []interface{})
	BuildSqlAndArgsFilterOnly() (string, []interface{})
	BuildSqlAndArgsFilterOnlyWithWherePrefix() (string, []interface{})

	OrdersBy() OrdersBy
	Filters() *Filters
	Pagination() *Pagination
}

func NewHelper

func NewHelper(separator Separator, opts ...IHelperOption) IHelper

type IHelperOption

type IHelperOption interface {
	// contains filtered or unexported methods
}

func WithFilters

func WithFilters(v Filters) IHelperOption

func WithOrderBy

func WithOrderBy(v OrderBy) IHelperOption

func WithOrdersBy

func WithOrdersBy(v OrdersBy) IHelperOption

func WithPagination

func WithPagination(page, limit int) IHelperOption

type JsonArray

type JsonArray struct {
	types.JSONText
	Valid bool
}

func ToJsonArray

func ToJsonArray(v []interface{}) *JsonArray

func (*JsonArray) Scan

func (n *JsonArray) Scan(value interface{}) error

func (JsonArray) Value

func (n JsonArray) Value() (driver.Value, error)

type JsonObject

type JsonObject struct {
	types.JSONText
	Valid bool
}

func ToJsonObjectFromInterface

func ToJsonObjectFromInterface(v interface{}) *JsonObject

func ToJsonObjectFromMap

func ToJsonObjectFromMap(v map[string]interface{}) *JsonObject

func (*JsonObject) Scan

func (n *JsonObject) Scan(value interface{}) error

Scan implements the Scanner interface.

func (JsonObject) Value

func (n JsonObject) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Manager

type Manager interface {
	MustConnect(ctx context.Context) Manager
	Connect(ctx context.Context) error
	SqlMock() sqlmock.Sqlmock

	Rebind(query string) string

	Query(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) *sqlx.Row
	NamedQuery(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	MustExec(ctx context.Context, query string, args ...interface{}) sql.Result
	NamedExec(ctx context.Context, query string, arg interface{}) (sql.Result, error)

	MustBegin(ctx context.Context, opts *sql.TxOptions) *sqlx.Tx
	Begin(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)

	Prepare(ctx context.Context, query string) (*sqlx.Stmt, error)
	PrepareNamed(ctx context.Context, query string) (*sqlx.NamedStmt, error)

	DSN() string
	Driver() SupportedDriver
	Ping() error
	SetTelemetry(tm telemetry.Manager) Manager
}

func New

func New(driver SupportedDriver, dsn string, opts ...Option) Manager

func NewNoop added in v0.3.0

func NewNoop() Manager

func NewWithMock

func NewWithMock() Manager

type NullableTime

type NullableTime sql.NullTime

func (NullableTime) Base

func (a NullableTime) Base() *sql.NullTime

func (NullableTime) From

func (a NullableTime) From(dt *time.Time) NullableTime

func (NullableTime) GetTime

func (a NullableTime) GetTime() *time.Time

func (*NullableTime) Scan

func (a *NullableTime) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (*NullableTime) Value

func (a *NullableTime) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Operator

type Operator string
const (
	OpEq    Operator = "="
	OpNotEq Operator = "<>"
	OpGt    Operator = ">"
	OpLt    Operator = "<"
	OpGte   Operator = ">="
	OpLte   Operator = "<="
	OpLike  Operator = "LIKE"
)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithMaxIdleConnection

func WithMaxIdleConnection(v int) Option

func WithMaxOpenConnection

func WithMaxOpenConnection(v int) Option

func WithOTelConnect

func WithOTelConnect(v bool) Option

func WithScope

func WithScope(v string) Option

func WithTelemetry added in v0.2.1

func WithTelemetry(v telemetry.Manager) Option

func WithTelemetryEnabled added in v0.2.1

func WithTelemetryEnabled(v bool) Option

type OrderBy

type OrderBy struct {
	Field string
	Sort  Sort
}

type OrdersBy

type OrdersBy []OrderBy

func (OrdersBy) Build

func (o OrdersBy) Build() string

func (OrdersBy) BuildWithSpacePrefix

func (o OrdersBy) BuildWithSpacePrefix() string

func (OrdersBy) FindField

func (o OrdersBy) FindField(fl string, fb FindBy) OrdersBy

type Pagination

type Pagination struct {
	Page  int
	Limit int
	// contains filtered or unexported fields
}

func (Pagination) Build

func (p Pagination) Build() string

func (Pagination) BuildWithSpacePrefix

func (p Pagination) BuildWithSpacePrefix() string

type PqArrayOfString

type PqArrayOfString pq.StringArray

func (*PqArrayOfString) Scan

func (a *PqArrayOfString) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (PqArrayOfString) Value

func (a PqArrayOfString) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Separator

type Separator string
const (
	SeparatorAND Separator = "AND"
	SeparatorOR  Separator = "OR"
)

func (Separator) String

func (s Separator) String() string

func (Separator) StringWithSpace

func (s Separator) StringWithSpace() string

type Sort

type Sort string
const (
	SortAsc  Sort = "asc"
	SortDesc Sort = "desc"
	SortNone Sort = "none"
)

func (Sort) String

func (t Sort) String() string

func (Sort) Valid

func (t Sort) Valid() bool

type SupportedDriver

type SupportedDriver string
const (
	DriverMySQL      SupportedDriver = "mysql"
	DriverPostgreSQL SupportedDriver = "postgres"
	// DriverSqlServer ref: https://gist.github.com/rossnelson/cbb192d314b6c89b7148e919ab25986c
	DriverSqlServer SupportedDriver = "mssql"
	DriverMock      SupportedDriver = "sqlmock"
)

func (SupportedDriver) String

func (d SupportedDriver) String() string

func (SupportedDriver) ToSqlBuilderFlavor

func (d SupportedDriver) ToSqlBuilderFlavor() sqlbuilder.Flavor

type ValueKey added in v0.3.6

type ValueKey string
const (
	ValueKeyNow ValueKey = "now"
)

func (ValueKey) String added in v0.3.6

func (k ValueKey) String(driver SupportedDriver) string

Jump to

Keyboard shortcuts

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