Documentation ¶
Index ¶
- Variables
- func WriteCompositionQueryInt64(i *qtypes.Int64, sel string, com *Composer, opt *CompositionOpts) (err error)
- func WriteCompositionQueryString(s *qtypes.String, sel string, com *Composer, opt *CompositionOpts) (err error)
- type BuiltinType
- type Composer
- func (c *Composer) Add(arg interface{})
- func (c *Composer) Args() []interface{}
- func (c *Composer) Len() int
- func (c *Composer) Read(b []byte) (int, error)
- func (c *Composer) ResetBuf()
- func (c *Composer) String() string
- func (c *Composer) Write(b []byte) (int, error)
- func (c *Composer) WritePlaceholder() error
- func (c *Composer) WriteString(s string) (int, error)
- type CompositionOpts
- type CompositionWriter
- type CustomType
- type Generator
- func (g *Generator) AddImport(i string) *Generator
- func (g *Generator) Generate(s *pqt.Schema) ([]byte, error)
- func (g *Generator) GenerateTo(s *pqt.Schema, w io.Writer) error
- func (g *Generator) SetAcronyms(acronyms map[string]string) *Generator
- func (g *Generator) SetImports(imports ...string) *Generator
- func (g *Generator) SetPackage(pkg string) *Generator
- func (g *Generator) SetPostgresVersion(ver float32) *Generator
- func (g *Generator) SetVisibility(v Visibility) *Generator
- type Visibility
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
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) Read ¶ added in v0.2.0
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) WritePlaceholder ¶ added in v0.2.0
WritePlaceholder writes appropriate placeholder to the query buffer based on current state of the composer.
func (*Composer) WriteString ¶ added in v0.2.0
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
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 (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 (*Generator) GenerateTo ¶
GenerateTo ...
func (*Generator) SetAcronyms ¶
SetAcronyms ...
func (*Generator) SetImports ¶
SetImports ...
func (*Generator) SetPostgresVersion ¶ added in v0.5.0
SetPostgresVersion sets version of postgres for which code will be generated.
func (*Generator) SetVisibility ¶ added in v0.6.0
func (g *Generator) SetVisibility(v Visibility) *Generator
SetVisibility sets visibility that each struct, function, method or property will get.
type Visibility ¶ added in v0.6.0
type Visibility string
const ( Public Visibility = "public" Private Visibility = "private" )