client

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EQ   = "\"%s\".\"%s\" = %s"
	NEQ  = "\"%s\".\"%s\" != %s"
	GT   = "\"%s\".\"%s\" > %s"
	GTE  = "\"%s\".\"%s\" >= %s"
	LT   = "\"%s\".\"%s\" < %s"
	LTE  = "\"%s\".\"%s\" <= %s"
	NIL  = "\"%s\".\"%s\" IS NIL"
	NNIL = "\"%s\".\"%s\" IS NOT NIL"
	ANY  = "\"%s\".\"%s\" = ANY(%s)"
	NANY = "\"%s\".\"%s\" != ANY(%s)"
)

Variables

View Source
var ErrFinalRow = errors.New("there is no new row")
View Source
var NotFoundError = errors.New("not found")

Functions

func CreateAddRelationQuery

func CreateAddRelationQuery(relationshipTable, id, relationshipID string, idValue, relationshipIDValue any) (string, pgx.NamedArgs)

func CreateAggregateQuery

func CreateAggregateQuery(list []*WhereList, model Model, aggregate *Aggregate) (string, pgx.NamedArgs)

func CreateBulkInsertQuery added in v0.2.0

func CreateBulkInsertQuery(args pgx.NamedArgs, fieldsList []map[string]any, fieldsListList [][]string) (string, string)

func CreateInsertQuery

func CreateInsertQuery(fields map[string]any, fieldsList []string) (string, string, pgx.NamedArgs)

func CreateSelectListQuery

func CreateSelectListQuery(list []*WhereList, model Model, result Result, orders []*Order, paging *Paging) (string, []any, pgx.NamedArgs)

func CreateSelectQuery

func CreateSelectQuery(list []*WhereList, model Model, result Result) (string, []any, pgx.NamedArgs)

func CreateUpdateQuery

func CreateUpdateQuery(fields map[string]any, fieldsList []string) (string, pgx.NamedArgs)

func DeleteRelationQuery

func DeleteRelationQuery(relationshipTable, id, relationshipID string, idValue, relationshipIDValue any) (string, pgx.NamedArgs)

func IsExistRelationQuery

func IsExistRelationQuery(relationshipTable, id, relationshipID string, idValue, relationshipIDValue any) (string, pgx.NamedArgs)

func ScanFirstRow

func ScanFirstRow(rows pgx.Rows, model Model, selectedAddress []any) error

func ScanListFirstRow

func ScanListFirstRow(rows pgx.Rows, model Model, selectedAddress []any) error

func ScanListNextRows

func ScanListNextRows(rows pgx.Rows, model Model, selectedAddress []any) error

func ScanNextRows

func ScanNextRows(rows pgx.Rows, model Model, selectedAddress []any) error

func ScanValues

func ScanValues(rows pgx.Rows, selectedAddress []any) error

Types

type Aggregate

type Aggregate struct {
	// contains filtered or unexported fields
}

func (*Aggregate) Avg

func (a *Aggregate) Avg(field string, value any)

func (*Aggregate) Count

func (a *Aggregate) Count(field string, value any)

func (*Aggregate) Field

func (a *Aggregate) Field(field string, value any)

func (*Aggregate) GroupBy

func (a *Aggregate) GroupBy(tableName string)

func (*Aggregate) Max

func (a *Aggregate) Max(field string, value any)

func (*Aggregate) Min

func (a *Aggregate) Min(field string, value any)

func (*Aggregate) Sum

func (a *Aggregate) Sum(field string, value any)

type Client

type Client struct {
	Database DatabaseClient
}

func NewClient

func NewClient(d DatabaseClient) *Client

func (*Client) AddManyToManyRelation

func (receiver *Client) AddManyToManyRelation(ctx context.Context, relationshipTable, id, relationshipID string, idValue, relationshipIDValue any) error

func (*Client) Aggregate

func (receiver *Client) Aggregate(ctx context.Context, list []*WhereList, model Model, aggregate *Aggregate) (func() error, error)

func (*Client) BulkCreate added in v0.2.0

func (receiver *Client) BulkCreate(ctx context.Context, tableName string, fieldsList []map[string]any, fieldsListList [][]string) error

func (*Client) BulkDelete added in v0.2.0

func (receiver *Client) BulkDelete(ctx context.Context, tableName string, idName string, idValue []any) error

func (*Client) BulkUpdate added in v0.2.0

func (receiver *Client) BulkUpdate(ctx context.Context, tableName string, fields map[string]any, fieldsList []string, idName string, idValue []any) error

func (*Client) Create

func (receiver *Client) Create(ctx context.Context, tableName string, fields map[string]any, fieldsList []string, serialFields []*SelectedField) error

func (*Client) Delete

func (receiver *Client) Delete(ctx context.Context, tableName string, idName string, idValue any) error

func (*Client) DeleteManyToManyRelation

func (receiver *Client) DeleteManyToManyRelation(ctx context.Context, relationshipTable, id, relationshipID string, idValue, relationshipIDValue any) error

func (*Client) ExistManyToManyRelation

func (receiver *Client) ExistManyToManyRelation(ctx context.Context, relationshipTable, id, relationshipID string, idValue, relationshipIDValue any) (bool, error)

func (*Client) Get

func (receiver *Client) Get(ctx context.Context, list []*WhereList, model Model, result Result) error

func (*Client) List

func (receiver *Client) List(ctx context.Context, list []*WhereList, model Model, result Result, orders []*Order, paging *Paging) error

func (*Client) Refresh

func (receiver *Client) Refresh(ctx context.Context, model Model, result Result, idName string, idValue any) error

func (*Client) Update

func (receiver *Client) Update(ctx context.Context, tableName string, fields map[string]any, fieldslist []string, idName string, idValue any) error

type DatabaseClient

type DatabaseClient interface {
	Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	BeginHook()
	EndHook()
}

type DatabaseTransactionClient

type DatabaseTransactionClient interface {
	DatabaseClient
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

type Model

type Model interface {
	GetDBName() string
	GetRelationList() *RelationList
	ScanResult()
	SetResult(result Result)
}

type OperationInfo

type OperationInfo struct {
	TableName     string
	OperationType OperationType
}

func NewOperationInfo

func NewOperationInfo(tableName string, operationType OperationType) *OperationInfo

type OperationType

type OperationType string
const (
	OperationTypeGet        OperationType = "GET"
	OperationTypeRefresh    OperationType = "REFRESH"
	OperationTypeCreate     OperationType = "CREATE"
	OperationTypeUpdate     OperationType = "UPDATE"
	OperationTypeDelete     OperationType = "DELETE"
	OperationTypeList       OperationType = "LIST"
	OperationTypeBulkCreate OperationType = "BULK_CREATE"
	OperationTypeBulkUpdate OperationType = "BULK_UPDATE"
	OperationTypeBulkDelete OperationType = "BULK_DELETE"
)

type Order

type Order struct {
	Desc  bool
	Field string
}

func (Order) String

func (o Order) String() string

type Paging

type Paging struct {
	Skip  int
	Limit int
}

func (Paging) String

func (p Paging) String() string

type Relation

type Relation struct {
	RelationModel    Model
	RelationResult   Result
	RelationTable    string
	RelationWhere    *RelationCondition
	RelationJoinType RelationJoinType
	Where            []*WhereList
	ManyToManyTable  string
}

func (*Relation) SetJoinType added in v0.3.0

func (r *Relation) SetJoinType(t RelationJoinType) *Relation

type RelationCondition

type RelationCondition struct {
	RelationValue      string
	TableValue         string
	RelationTableValue string
}

func (*RelationCondition) String

func (r *RelationCondition) String(tableName, relationTableName string) string

type RelationJoinType added in v0.3.0

type RelationJoinType string
const (
	RelationJoinTypeDefault RelationJoinType = ""
	RelationJoinTypeLeft    RelationJoinType = "LEFT"
	RelationJoinTypeRight   RelationJoinType = "RIGHT"
	RelationJoinTypeFull    RelationJoinType = "FULL"
	RelationJoinTypeInner   RelationJoinType = "INNER"
)

type RelationList

type RelationList struct {
	Relations   []*Relation
	RelationMap map[string]*Relation
}

type RelationModel

type RelationModel interface {
	GetDBName() string
	IsExist() bool
}

type Res

type Res struct {
	SqlString string
	Names     []string
	Values    []any
}

type Result

type Result interface {
	GetDBName() string
	GetSelectedFields() []*SelectedField
	GetRelations() []Result
	IsExist() bool
}

type SelectedField

type SelectedField struct {
	Name  string
	Value any
}

type Where

type Where struct {
	Type     string
	Name     string
	HasValue bool
	Value    any
}

func (*Where) GetSqlString

func (w *Where) GetSqlString(tableName string) string

type WhereList

type WhereList struct {
	Items []*Where
}

func (*WhereList) Parse

func (w *WhereList) Parse(tableName string) *Res

Jump to

Keyboard shortcuts

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