pqtgo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2016 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Space is a shorthand composition option that holds space.
	Space = &CompositionOpts{
		Joint: " ",
	}
	// And is a shorthand composition option that holds AND operator.
	And = &CompositionOpts{
		Joint: " AND ",
	}
	// Or is a shorthand composition option that holds OR operator.
	Or = &CompositionOpts{
		Joint: " OR ",
	}
	// Comma is a shorthand composition option that holds comma.
	Comma = &CompositionOpts{
		Joint: ", ",
	}
)

Functions

func WriteCompositionQueryInt64 added in v0.2.0

func WriteCompositionQueryInt64(i *qtypes.Int64, sel string, com *Composer, opt *CompositionOpts) (err error)

WriteCompositionQueryInt64 ...

func WriteCompositionQueryString added in v0.2.0

func WriteCompositionQueryString(s *qtypes.String, sel string, com *Composer, opt *CompositionOpts) (err error)

WriteCompositionQueryString ...

Types

type BuiltinType

type BuiltinType types.BasicKind

BuiltinType ...

func (BuiltinType) Fingerprint

func (bt BuiltinType) Fingerprint() string

Fingerprint implements Type interface.

func (BuiltinType) String

func (bt BuiltinType) String() string

type Composer added in v0.2.0

type Composer struct {
	Dirty bool
	// contains filtered or unexported fields
}

Composer holds buffer, arguments and placeholders count. In combination with external buffet can be also used to also generate sub-queries. To do that simply write buffer to the parent buffer, composer will hold all arguments and remember number of last placeholder.

func NewComposer added in v0.2.0

func NewComposer(size int64) *Composer

NewComposer allocates new Composer with inner slice of arguments of given size.

func (*Composer) Add added in v0.2.0

func (c *Composer) Add(arg interface{})

Add appends list with new element.

func (*Composer) Args added in v0.2.0

func (c *Composer) Args() []interface{}

Args returns all arguments stored as a slice.

func (*Composer) Len added in v0.2.0

func (c *Composer) Len() int

Len returns number of arguments.

func (*Composer) Read added in v0.2.0

func (c *Composer) Read(b []byte) (int, error)

Read implements io Reader interface.

Example
com := NewComposer(0)
buf := bytes.NewBufferString("SELECT * FROM user")
arg := 1

// lets imagine that not always argument is present
if arg > 0 {
	_, _ = com.WriteString("age = ")
	_ = com.WritePlaceholder()
	com.Add(arg)
	com.Dirty = true // something was written, lets mark composer as dirty
}

if com.Dirty {
	buf.WriteString(" WHERE ")
	buf.ReadFrom(com)
}

fmt.Println(strings.TrimSpace(
	buf.String(),
))
fmt.Print(com.Args())
Output:

SELECT * FROM user WHERE age = $1
[1]

func (*Composer) ResetBuf added in v0.2.0

func (c *Composer) ResetBuf()

ResetBuf resets internal buffer.

func (*Composer) String added in v0.2.0

func (c *Composer) String() string

String implements fmt Stringer interface.

func (*Composer) Write added in v0.2.0

func (c *Composer) Write(b []byte) (int, error)

Write implements io Writer interface.

func (*Composer) WritePlaceholder added in v0.2.0

func (c *Composer) WritePlaceholder() error

WritePlaceholder writes appropriate placeholder to the query buffer based on current state of the composer.

func (*Composer) WriteString added in v0.2.0

func (c *Composer) WriteString(s string) (int, error)

WriteString appends the contents of s to the query buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with bytes ErrTooLarge.

type CompositionOpts added in v0.2.0

type CompositionOpts struct {
	Joint                         string
	PlaceholderFunc, SelectorFunc string
	Cast                          string
}

CompositionOpts is a container for modification that can be applied.

type CompositionWriter added in v0.2.0

type CompositionWriter interface {
	// WriteComposition is a function that allow custom struct type to be used as a part of criteria.
	// It gives possibility to write custom query based on object that implements this interface.
	WriteComposition(string, *Composer, *CompositionOpts) error
}

CompositionWriter is a simple wrapper for WriteComposition function.

type CustomType

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

CustomType ...

func TypeCustom

func TypeCustom(m, o, c interface{}) CustomType

TypeCustom ...

func (CustomType) Fingerprint

func (ct CustomType) Fingerprint() string

Fingerprint implements Type interface.

func (CustomType) String

func (ct CustomType) String() string

String implements Stringer interface.

type Generator

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

Generator ...

func NewGenerator

func NewGenerator() *Generator

NewGenerator ...

func (*Generator) AddImport

func (g *Generator) AddImport(i string) *Generator

AddImport ...

func (*Generator) Generate

func (g *Generator) Generate(s *pqt.Schema) ([]byte, error)

Generate ...

func (*Generator) GenerateTo

func (g *Generator) GenerateTo(s *pqt.Schema, w io.Writer) error

GenerateTo ...

func (*Generator) SetAcronyms

func (g *Generator) SetAcronyms(acronyms map[string]string) *Generator

SetAcronyms ...

func (*Generator) SetImports

func (g *Generator) SetImports(imports ...string) *Generator

SetImports ...

func (*Generator) SetPackage

func (g *Generator) SetPackage(pkg string) *Generator

SetPackage ...

Jump to

Keyboard shortcuts

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