Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sample expressions #287

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (e aliasExpr) ToSql() (sql string, args []interface{}, err error) {
}

// Eq is syntactic sugar for use with Where/Having/Set methods.
// Ex:
// .Where(Eq{"id": 1}) == "id = ?"
type Eq map[string]interface{}

func (eq Eq) toSQL(useNotOpr bool) (sql string, args []interface{}, err error) {
Expand Down Expand Up @@ -221,7 +223,7 @@ func (neq NotEq) ToSql() (sql string, args []interface{}, err error) {

// Like is syntactic sugar for use with LIKE conditions.
// Ex:
// .Where(Like{"name": "%irrel"})
// .Where(Like{"name": "%irrel"}) == "name LIKE ?"
type Like map[string]interface{}

func (lk Like) toSql(opr string) (sql string, args []interface{}, err error) {
Expand Down Expand Up @@ -260,7 +262,7 @@ func (lk Like) ToSql() (sql string, args []interface{}, err error) {

// NotLike is syntactic sugar for use with LIKE conditions.
// Ex:
// .Where(NotLike{"name": "%irrel"})
// .Where(NotLike{"name": "%irrel"}) == "name NOT LIKE ?"
type NotLike Like

func (nlk NotLike) ToSql() (sql string, args []interface{}, err error) {
Expand All @@ -269,7 +271,7 @@ func (nlk NotLike) ToSql() (sql string, args []interface{}, err error) {

// ILike is syntactic sugar for use with ILIKE conditions.
// Ex:
// .Where(ILike{"name": "sq%"})
// .Where(ILike{"name": "sq%"}) == "name ILIKE ?"
type ILike Like

func (ilk ILike) ToSql() (sql string, args []interface{}, err error) {
Expand All @@ -278,7 +280,7 @@ func (ilk ILike) ToSql() (sql string, args []interface{}, err error) {

// NotILike is syntactic sugar for use with ILIKE conditions.
// Ex:
// .Where(NotILike{"name": "sq%"})
// .Where(NotILike{"name": "sq%"}) == "name NOT ILIKE ?"
type NotILike Like

func (nilk NotILike) ToSql() (sql string, args []interface{}, err error) {
Expand All @@ -287,7 +289,7 @@ func (nilk NotILike) ToSql() (sql string, args []interface{}, err error) {

// Lt is syntactic sugar for use with Where/Having/Set methods.
// Ex:
// .Where(Lt{"id": 1})
// .Where(Lt{"id": 1}) == "id < 1"
type Lt map[string]interface{}

func (lt Lt) toSql(opposite, orEq bool) (sql string, args []interface{}, err error) {
Expand Down