Documentation ¶
Index ¶
- Constants
- Variables
- func Copy[T Cond](ctx context.Context, conn interface{ ... }, arr []T) (err error)
- func Delete[T Cond](ctx context.Context, conn interface{ ... }, in T) (err error)
- func Get[T Cond](ctx context.Context, conn interface{ ... }, out T, list ...any) (err error)
- func GetOrder(before bool, order Direction) (isBackSort bool, qOrder Direction, sign Sign)
- func Insert[T Cond](ctx context.Context, conn interface{ ... }, in T) (err error)
- func Query(q string, arg ...any) query
- func Update[T Cond](ctx context.Context, conn interface{ ... }, in T) (err error)
- func Upset[T Cond](ctx context.Context, conn interface{ ... }, in T) (err error)
- type Cond
- type Direction
- type FieldName
- type FieldNameToText
- type FieldValue
- type FieldValueArray
- type ListRez
- type NullJson
- type Operation
- type QType
- type Request
- type Sign
Constants ¶
const ( DefaultLimit = 10 MaxLimit = 5000 )
Variables ¶
var ErrDuplicateKeyValueViolates = errors.New("duplicate key value violates")
var ErrNoRowAffected = errors.New("no row affected")
var ErrNoRows = errors.New("not found")
var ErrorUnknown = errors.New("unknown error")
Functions ¶
func Copy ¶
func Copy[T Cond]( ctx context.Context, conn interface { PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }, arr []T, ) (err error)
Copy save array of element to database
func Delete ¶
func Delete[T Cond]( ctx context.Context, conn interface { ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) }, in T, ) (err error)
Delete delete of existing 1 entry to database You must fill all object fields for the primary key
func Get ¶
func Get[T Cond]( ctx context.Context, conn interface { QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }, out T, list ...any, ) (err error)
Get get 1 entry. You must fill in at least 1 object field list allows you to set additional conditions for the search
func Insert ¶
func Insert[T Cond]( ctx context.Context, conn interface { QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }, in T, ) (err error)
Insert insert 1 entry to database You must fill in at least 1 object field
func Update ¶
func Update[T Cond]( ctx context.Context, conn interface { ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) }, in T, ) (err error)
Update update of existing 1 entry to database You must fill in at least 1 object field except for the fields for the primary key
func Upset ¶
func Upset[T Cond]( ctx context.Context, conn interface { QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }, in T, ) (err error)
Upset insert or update if exist 1 entry to database You must fill in at least 1 object field except for the fields for the primary key
Types ¶
type Cond ¶
type Cond interface { // FieldByName returns the address of the field of the structure given the name of the constant FieldByName(string) any // ValueByName returns the value of the field of the structure given the name of the constant ValueByName(string) any // New Create an object of type T New() any // Cursor returns a cursor of object // // Used for paginated list Cursor() []byte // Equal returns true if the objects are identical Equal(any) bool // Cols returns a list of table fields // primary - add primary keys to list // queryType - database query type Cols(primary bool, queryType QType) []string // Primaries returns a list of primary keys Primaries() []string // Db returns a name of database Db() string }
type FieldNameToText ¶
type FieldNameToText string
type FieldValue ¶
type FieldValue any
type FieldValueArray ¶
type FieldValueArray []any
func ToFieldValueArray ¶
func ToFieldValueArray[ E any, T interface { []E }, ](in T) FieldValueArray
type ListRez ¶
type ListRez[T Cond] interface { Set([]T) Get() []T Start() []byte Stop() []byte After() bool Before() bool }
func List ¶
func List[T Cond]( ctx context.Context, conn interface { QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }, cursor T, req Request, fieldsOrder []string, list ...any, ) (out ListRez[T], err error)
List getting a paginated list
cursor pointer to the first or last element on the page list allows you to set additional conditions for the search
type Request ¶
type Request interface { // Limit number of elements per page Limit() int // Order sort order ASC or DESC Order() Direction // Before direction of scroll, default forward or backward Before() bool // used for fq, q Query([]FieldName) []any }
func DefaultRequest ¶
func DefaultRequest() Request