Documentation ¶
Index ¶
- Variables
- type ColumnEscaper
- type SqlxSelector
- func (s *SqlxSelector) Select(column string) *SqlxSelector
- func (s *SqlxSelector) SelectAs(column, as string) *SqlxSelector
- func (s *SqlxSelector) SelectStruct(column string, limit ...string) *SqlxSelector
- func (s *SqlxSelector) SelectStructAs(column, as string, limit ...string) *SqlxSelector
- func (s *SqlxSelector) String() string
- func (s *SqlxSelector) StringWithError() (string, error)
- func (s *SqlxSelector) WithColumnEscaper(ce ColumnEscaper) *SqlxSelector
Constants ¶
This section is empty.
Variables ¶
var DefaultColumnEscaper = Backquote
DefaultColumnEscaper is used in New/NewWithMapper
Functions ¶
This section is empty.
Types ¶
type ColumnEscaper ¶ added in v2.2.0
ColumnEscaper is a helper to escape column names
var ( // Backquote for MySQL Backquote ColumnEscaper = func(s string) string { spl := strings.Split(s, ".") for i := range spl { spl[i] = "`" + spl[i] + "`" } return strings.Join(spl, ".") } // Doublequote for SQLite and PostgreSQL Doublequote ColumnEscaper = func(s string) string { spl := strings.Split(s, ".") for i := range spl { spl[i] = doubleQuote(spl[i]) } return strings.Join(spl, ".") } )
type SqlxSelector ¶
type SqlxSelector struct { Errors []error // contains filtered or unexported fields }
SqlxSelector is a generator of columns in SELECT query
func NewWithMapper ¶
func NewWithMapper(dst interface{}, mapper *reflectx.Mapper) (s *SqlxSelector)
NewWithMapper generates SqlxSelector with specified mapper
func (*SqlxSelector) Select ¶
func (s *SqlxSelector) Select(column string) *SqlxSelector
Select adds the column directly to query
func (*SqlxSelector) SelectAs ¶
func (s *SqlxSelector) SelectAs(column, as string) *SqlxSelector
SelectAs adds the column and 'AS' name directly to query
func (*SqlxSelector) SelectStruct ¶
func (s *SqlxSelector) SelectStruct(column string, limit ...string) *SqlxSelector
SelectStruct adds columns specified as 'column' to query to store values 'limit' can specify columns to add ex. SelectStruct("users.*" /* table name */, "id", "name" /* columns to select */)
func (*SqlxSelector) SelectStructAs ¶
func (s *SqlxSelector) SelectStructAs(column, as string, limit ...string) *SqlxSelector
SelectStructAs adds columns specified as 'column' to query to store values specified as 'as' in struct 'limit' can specify columns to add ex. SelectStructAs("users.*" /* table name */, "user." /* 'db:""' name */, "id", "name" /* columns to select */)
func (*SqlxSelector) String ¶
func (s *SqlxSelector) String() string
func (*SqlxSelector) StringWithError ¶
func (s *SqlxSelector) StringWithError() (string, error)
StringWithError returns columns for SELECT as string, but may return an error if something went wrong
func (*SqlxSelector) WithColumnEscaper ¶ added in v2.2.0
func (s *SqlxSelector) WithColumnEscaper(ce ColumnEscaper) *SqlxSelector
WithColumnEscaper specifies a function to escape column names