repo

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit = 10
	MaxLimit     = 5000
)

Variables

View Source
var ErrDuplicateKeyValueViolates = errors.New("duplicate key value violates")
View Source
var ErrNoRowAffected = errors.New("no row affected")
View Source
var ErrNoRows = errors.New("not found")
View Source
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 GetOrder

func GetOrder(before bool, order Direction) (isBackSort bool, qOrder Direction, sign Sign)

GetOrder returns sort order and sign

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 Query

func Query(q string, arg ...any) query

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 Direction

type Direction int8

Direction sort order

const (
	ASC Direction = iota
	DESC
)

func (Direction) String

func (d Direction) String() string

type FieldName

type FieldName 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

func NewList

func NewList[T Cond](in []T, isCursor bool, lim int, before bool) ListRez[T]

type NullJson

type NullJson struct {
	Handler func(value []byte, ok bool)
}

func (*NullJson) Scan

func (ns *NullJson) Scan(value any) error

type Operation

type Operation int
const (
	END Operation = iota
	// AND
	AND
	// NOT
	NOT
	// OR
	OR
	// =
	EQ
	// <=
	LE
	// >=
	GE
	// <
	L
	// >
	G
	// (
	SB
	// )
	EB
	// ~*
	EQA
)

func (Operation) String

func (o Operation) String() string

type QType

type QType int8

QType database query type

const (
	QSelect QType = iota
	QInsert
	QUpdate
)

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

func NewRequest

func NewRequest(limit int, order Direction, before bool, fq, q string) Request

type Sign

type Sign int8

func (Sign) Sign

func (i Sign) Sign() string

Jump to

Keyboard shortcuts

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