Skip to content

Commit

Permalink
feat: add custom sql segment conditional support #76
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoenixL0911 authored Sep 15, 2023
1 parent bc16a0a commit 4c76c0d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gplus/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,22 @@ func (q *QueryCond[T]) OrInCond(cond bool, column any, val any) *QueryCond[T] {
return q
}

// ApplySQL 拼接 sql
// Case: query.ApplySQL("AND id IN (SELECT user_id FROM app_user WHERE app_id = ? AND app_name = ?)", 1, "TestApp")
func (q *QueryCond[T]) ApplySQL(applySql string, params ...any) *QueryCond[T] {
q.addExpression(&applySqlSegment{applySql: applySql, params: params})
return q
}

// ApplySQLCond 拼接 sql
// Case: query.ApplySQLCond(true,"AND id IN (SELECT user_id FROM app_user WHERE app_id = ? AND app_name = ?)", 1, "TestApp")
func (q *QueryCond[T]) ApplySQLCond(cond bool, applySql string, params ...any) *QueryCond[T] {
if cond {
return q.ApplySQL(applySql, params...)
}
return q
}

func (q *QueryCond[T]) addExpression(sqlSegments ...SqlSegment) {
if len(sqlSegments) == 1 {
q.handleSingle(sqlSegments[0])
Expand Down

0 comments on commit 4c76c0d

Please sign in to comment.