sqlquery

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 2 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 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.

Types

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{}
}

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.

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.

Jump to

Keyboard shortcuts

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