Documentation
¶
Index ¶
- Constants
- func AND(args ...string) string
- func EQ(fieldName string, value any) string
- func IS(fieldName string, value any) string
- func LIKE(fieldName string, value any) string
- func OR(args ...string) string
- func ValidOrderType(val string) bool
- type Query
- func (q *Query) CrossJoin(table string) *Query
- func (q *Query) FullJoin(table string, on string) *Query
- func (q *Query) GroupBy(columns ...string) *Query
- func (q *Query) Having(condition string) *Query
- func (q *Query) InnerJoin(table string, on string) *Query
- func (q *Query) LeftJoin(table string, on string) *Query
- func (q *Query) Limit(val string) *Query
- func (q *Query) Offset(val string) *Query
- func (q *Query) Order(by string, orderType string) *Query
- func (q *Query) RightJoin(table string, on string) *Query
- func (q *Query) String() string
- func (q *Query) Where() *Where
- type Where
Examples ¶
Constants ¶
View Source
const ( // DESC is descending order DESC = "DESC" // ASC is ascending order ASC = "ASC" )
Variables ¶
This section is empty.
Functions ¶
func ValidOrderType ¶
ValidOrderType checks if the given string is a valid ordering type
Types ¶
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Example ¶
query := New("SELECT * FROM test_table").LeftJoin("test_posts", "test_table.id=test_posts.user_id").Order("name", DESC).Limit("5").Offset("1")
query.Where().
OR(EQ("name", "testname"), EQ("age", "12")).
AND(EQ("id", "123"), EQ("email", "test@mail.com")).
LIKE("name", "%testname")
fmt.Println(query.String())
Output: SELECT * FROM test_table LEFT JOIN test_posts ON test_table.id=test_posts.user_id WHERE (name = 'testname' OR age = '12') AND (id = '123' AND email = 'test@mail.com') AND name LIKE '%testname' ORDER BY name DESC LIMIT 5 OFFSET 1
type Where ¶
type Where struct {
// contains filtered or unexported fields
}
The Where struct represents the WHERE clause in a SQL query. It contains a chunks slice to hold the individual WHERE conditions.
Click to show internal directories.
Click to hide internal directories.