StitchingSQLGo

package module
v0.0.0-...-1ceedbb Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: MIT Imports: 6 Imported by: 0

README

StitchingSQLGo

Stitching SQL by method

Test & Bench

go generate
go test -bench=.

Documentation

Index

Constants

View Source
const (
	EQ    conditionOperator = "="      // Equal (=) Operator
	NEQ   conditionOperator = "!="     // Not Equal (!= or <>) Operator
	GT    conditionOperator = ">"      // Greater Than (>) Operator
	LT    conditionOperator = "<"      // Less Than (<) Operator
	GTEQ  conditionOperator = ">="     // Greater Than or Equal To (>=) Operator
	LTEQ  conditionOperator = "<="     // Less Than or Equal To (<=) Operator
	NGT   conditionOperator = "!>"     // Not Greater Than (!>) Operator
	NLT   conditionOperator = "!<"     // Not Less Than (!<) Operator
	IS    conditionOperator = "is"     // IS Operator
	ISNot conditionOperator = "is not" // IS NOT Operator

)
View Source
const (
	AND whereItemLinker = "and" // 1 = 1 and 2 = 2
	OR  whereItemLinker = "or"  // 1 = 1 or  2 = 2
)

Variables

View Source
var (
	ErrorNilSQL = errors.New("nil SqlBuilder")
)
View Source
var ErrorNotConditionOperator = errors.New("not a condition operator")

Functions

This section is empty.

Types

type Condition

type Condition struct {
	L Field             `validate:"required"`
	O conditionOperator `validate:"required"`
	R interface{}       `validate:"required"`
}

condition

L field O condition operator R value

func (Condition) Condition

func (c Condition) Condition(s *SqlBuilder) error

func (Condition) WhereItem

func (c Condition) WhereItem(s *SqlBuilder) error

type Count

type Count struct {
	F Field
}

func (Count) Field

func (e Count) Field(s *SqlBuilder, isRefTable bool) error

type Delete

type Delete struct {
	Table `validate:"required"`
	Where `validate:"required"`
	Returning
}

postgres https://www.postgresql.org/docs/current/sql-delete.html

func (Delete) Exec

func (d Delete) Exec() (string, []interface{}, error)

func (Delete) ExecWithReturning

func (d Delete) ExecWithReturning() Returning

func (Delete) SQL

func (d Delete) SQL() (string, []interface{}, error)

type Exec

type Exec interface {
	Exec() (string, []interface{}, error)
}

example: insert into table (field) values (value)

type ExecWithReturning

type ExecWithReturning interface {
	Exec
	ExecWithReturning() Returning
}

example: insert into table (field1) values (value1) returning field1

type Field

type Field interface {
	Field(*SqlBuilder, bool) error
}

Where field interface write field into SqlBuilder string builder example: field_1 or table_1.field

type Field1

type Field1 struct{}

func (Field1) Field

func (f Field1) Field(s *SqlBuilder, isRefTable bool) error

type Fields

type Fields []Field

func (Fields) Fields

func (fs Fields) Fields(s *SqlBuilder) error

type For

type For string
const (
	ForUpdate For = "update"
)

func (For) For

func (f For) For(s *SqlBuilder) error

type Insert

type Insert struct {
	Table  `validate:"required"`
	Values map[Field]interface{} `validate:"required,dive,keys,required,endkeys,required"`
	Returning
}

postgres https://www.postgresql.org/docs/current/sql-insert.html

func (Insert) Exec

func (i Insert) Exec() (string, []interface{}, error)

func (Insert) ExecWithReturning

func (i Insert) ExecWithReturning() Returning

func (Insert) SQL

func (i Insert) SQL() (string, []interface{}, error)

type Limit

type Limit uint64

type Offset

type Offset uint64

type OrderBy

type OrderBy map[Field]OrderByKind

type OrderByKind

type OrderByKind string
const (
	ASC  OrderByKind = "asc"
	DESC OrderByKind = "desc"
)

type Query

type Query interface {
	Query() (string, []interface{}, error)
	Fields() Fields
}

example: select field1 from table1 select exists(select field1 from table1)

type Returning

type Returning Fields

func (Returning) Returning

func (r Returning) Returning(s *SqlBuilder) error

type Select

type Select struct {
	FS    Fields `validate:"required"`
	Table `validate:"required"`
	Where
	OrderBy
	Limit
	Offset
	For
}

postgres https://www.postgresql.org/docs/current/sql-select.html

func (Select) Fields

func (slt Select) Fields() Fields

func (Select) Query

func (slt Select) Query() (string, []interface{}, error)

func (Select) SQL

func (slt Select) SQL() (string, []interface{}, error)

type SelectExists

type SelectExists struct {
	FS    Fields `validate:"required"`
	Table `validate:"required"`
	Where
	OrderBy
	Limit
	Offset
	For
}

postgres https://www.postgresql.org/docs/current/sql-select.html

func (SelectExists) Fields

func (slt SelectExists) Fields() Fields

func (SelectExists) Query

func (slt SelectExists) Query() (string, []interface{}, error)

func (SelectExists) SQL

func (slt SelectExists) SQL() (string, []interface{}, error)

type SqlBuilder

type SqlBuilder struct {
	strings.Builder
	// contains filtered or unexported fields
}

type Table

type Table interface {
	Table(*SqlBuilder) error
}

Where table interface write table into SqlBuilder string builder example: table

type Update

type Update struct {
	Table `validate:"required"`
	Set   map[Field]interface{} `validate:"required"`
	Where
	Returning
}

postgres https://www.postgresql.org/docs/current/sql-update.html

func (Update) Exec

func (u Update) Exec() (string, []interface{}, error)

func (Update) ExecWithReturning

func (u Update) ExecWithReturning() Returning

func (Update) SQL

func (u Update) SQL() (string, []interface{}, error)

type Where

type Where WhereItems // `validate:"required,where_items_array_structure"`

type WhereItem

type WhereItem interface {
	WhereItem(*SqlBuilder) error
}

type WhereItems

type WhereItems []WhereItem

func (WhereItems) WhereItem

func (is WhereItems) WhereItem(s *SqlBuilder) error

func (WhereItems) WhereItems

func (is WhereItems) WhereItems(s *SqlBuilder) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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