1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package client
- import "encoding/json"
- type Clause struct {
- queryAndArgsPars map[string][]any
- }
- func NewClause() *Clause {
- return &Clause{queryAndArgsPars: make(map[string][]any)}
- }
- func (clause *Clause) Common(query string, args ...any) *Clause {
- clause.queryAndArgsPars[query] = args
- return clause
- }
- func (clause *Clause) Equal(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" = ?"] = []any{value}
- return clause
- }
- func (clause *Clause) Like(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" LIKE ?"] = []any{value}
- return clause
- }
- func (clause *Clause) In(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" IN ?"] = []any{value}
- return clause
- }
- func (clause *Clause) NotIn(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" NOT IN ?"] = []any{value}
- return clause
- }
- func (clause *Clause) Not(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" != ?"] = []any{value}
- return clause
- }
- func (clause *Clause) LessThan(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" < ?"] = []any{value}
- return clause
- }
- func (clause *Clause) LessThanAndEqual(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" <= ?"] = []any{value}
- return clause
- }
- func (clause *Clause) GreaterThan(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" > ?"] = []any{value}
- return clause
- }
- func (clause *Clause) GreaterThanAndEqual(columnName string, value any) *Clause {
- clause.queryAndArgsPars[columnName+" >= ?"] = []any{value}
- return clause
- }
- func (clause *Clause) ToJson() ([]byte, error) {
- return json.Marshal(clause.queryAndArgsPars)
- }
|