sqlquery

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 3 Imported by: 4

README

sqlquery

Build Status Go Report Card go.dev reference

A collection of helpers to deal with sql queries.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteQuery

func DeleteQuery(flavor Flavor, tableName string, id interface{}) (string, []interface{})

DeleteQuery returns compiled DELETE string and args.

func DeleteWithOptionsQuery added in v1.3.0

func DeleteWithOptionsQuery(tableName string, options *DeleteOptions) (string, []interface{})

DeleteWithOptionsQuery returns compiled DELETE string and args from DeleteOptions.

func FindAllQuery

func FindAllQuery(tableName string, options *FindAllOptions) (string, []interface{})

FindAllQuery returns compiled SELECT string and args.

func FindQuery

func FindQuery(tableName string, options *FindOptions) (string, []interface{})

FindQuery returns compiled SELECT string and args.

func InsertQuery

func InsertQuery(flavor Flavor, tag, tableName string, structValue interface{}) (string, []interface{})

InsertQuery returns compiled INSERT string and args.

func UpdateQuery

func UpdateQuery(flavor Flavor, tag, tableName string, id interface{}, structValue interface{}) (string, []interface{})

UpdateQuery returns compiled UPDATE string and args.

func UpdateWithOptionsQuery added in v1.3.0

func UpdateWithOptionsQuery(tableName string, options *UpdateOptions) (string, []interface{})

UpdateWithOptionsQuery returns compiled UPDATE string and args from UpdateOptions.

Types

type DeleteOptions added in v1.3.0

type DeleteOptions struct {
	Flavor  Flavor
	Filters map[string]interface{}
}

DeleteOptions provides configuration for DeleteWithOptionsQuery function.

func NewDeleteOptions added in v1.3.0

func NewDeleteOptions(flavor Flavor) *DeleteOptions

NewDeleteOptions returns a DeleteOptions.

func (*DeleteOptions) WithFilter added in v1.3.0

func (d *DeleteOptions) WithFilter(field string, value interface{}) *DeleteOptions

WithFilter is a helper function to construct functional options that sets Filters field.

type FindAllOptions

type FindAllOptions struct {
	Flavor        Flavor
	Fields        []string
	Filters       map[string]interface{}
	Limit         int
	Offset        int
	OrderBy       string
	ForUpdate     bool
	ForUpdateMode string
}

FindAllOptions provides configuration for FindAllQuery function.

func NewFindAllOptions

func NewFindAllOptions(flavor Flavor) *FindAllOptions

NewFindAllOptions returns a FindAllOptions.

func (*FindAllOptions) WithFields

func (f *FindAllOptions) WithFields(fields []string) *FindAllOptions

WithFields is a helper function to construct functional options that sets Fields field.

func (*FindAllOptions) WithFilter

func (f *FindAllOptions) WithFilter(field string, value interface{}) *FindAllOptions

WithFilter is a helper function to construct functional options that sets Filters field.

func (*FindAllOptions) WithForUpdate added in v1.1.0

func (f *FindAllOptions) WithForUpdate(mode string) *FindAllOptions

WithForUpdate is a helper function to construct functional options that sets ForUpdate and ForUpdateMode fields.

func (*FindAllOptions) WithLimit

func (f *FindAllOptions) WithLimit(limit int) *FindAllOptions

WithLimit is a helper function to construct functional options that sets Limit field.

func (*FindAllOptions) WithOffset

func (f *FindAllOptions) WithOffset(offset int) *FindAllOptions

WithOffset is a helper function to construct functional options that sets Offset field.

func (*FindAllOptions) WithOrderBy

func (f *FindAllOptions) WithOrderBy(orderBy string) *FindAllOptions

WithOrderBy is a helper function to construct functional options that sets OrderBy field.

type FindOptions

type FindOptions struct {
	Flavor        Flavor
	Fields        []string
	Filters       map[string]interface{}
	ForUpdate     bool
	ForUpdateMode string
}

FindOptions provides configuration for FindQuery function.

func NewFindOptions

func NewFindOptions(flavor Flavor) *FindOptions

NewFindOptions returns a FindOptions.

func (*FindOptions) WithFields

func (f *FindOptions) WithFields(fields []string) *FindOptions

WithFields is a helper function to construct functional options that sets Fields field.

func (*FindOptions) WithFilter

func (f *FindOptions) WithFilter(field string, value interface{}) *FindOptions

WithFilter is a helper function to construct functional options that sets Filters field.

func (*FindOptions) WithForUpdate added in v1.4.0

func (f *FindOptions) WithForUpdate(mode string) *FindOptions

WithForUpdate is a helper function to construct functional options that sets ForUpdate and ForUpdateMode fields.

type Flavor

type Flavor int

Flavor is the flag to control the format of compiled sql.

const (
	MySQLFlavor Flavor = iota + 1
	PostgreSQLFlavor
	SQLiteFlavor
)

Supported flavors.

type UpdateOptions added in v1.3.0

type UpdateOptions struct {
	Flavor      Flavor
	Assignments map[string]interface{}
	Filters     map[string]interface{}
}

UpdateOptions provides configuration for UpdateWithOptionsQuery function.

func NewUpdateOptions added in v1.3.0

func NewUpdateOptions(flavor Flavor) *UpdateOptions

NewUpdateOptions returns a UpdateOptions.

func (*UpdateOptions) WithAssignment added in v1.3.0

func (u *UpdateOptions) WithAssignment(field string, value interface{}) *UpdateOptions

WithAssignment is a helper function to construct functional options that sets assignments.

func (*UpdateOptions) WithFilter added in v1.3.0

func (u *UpdateOptions) WithFilter(field string, value interface{}) *UpdateOptions

WithFilter is a helper function to construct functional options that sets Filters field.

Jump to

Keyboard shortcuts

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