mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Add sqlite filter builder. Add AND, OR, NOT filters to scene filter (#1115)
* Add resolution enum extension * Add filter builder * Use filterBuilder for scene query * Optimise joins * Add binary operators to scene query * Use Query for auto-tag
This commit is contained in:
@@ -11,6 +11,7 @@ type queryBuilder struct {
|
||||
|
||||
body string
|
||||
|
||||
joins joins
|
||||
whereClauses []string
|
||||
havingClauses []string
|
||||
args []interface{}
|
||||
@@ -25,7 +26,10 @@ func (qb queryBuilder) executeFind() ([]int, int, error) {
|
||||
return nil, 0, qb.err
|
||||
}
|
||||
|
||||
return qb.repository.executeFindQuery(qb.body, qb.args, qb.sortAndPagination, qb.whereClauses, qb.havingClauses)
|
||||
body := qb.body
|
||||
body += qb.joins.toSQL()
|
||||
|
||||
return qb.repository.executeFindQuery(body, qb.args, qb.sortAndPagination, qb.whereClauses, qb.havingClauses)
|
||||
}
|
||||
|
||||
func (qb *queryBuilder) addWhere(clauses ...string) {
|
||||
@@ -48,6 +52,48 @@ func (qb *queryBuilder) addArg(args ...interface{}) {
|
||||
qb.args = append(qb.args, args...)
|
||||
}
|
||||
|
||||
func (qb *queryBuilder) join(table, as, onClause string) {
|
||||
newJoin := join{
|
||||
table: table,
|
||||
as: as,
|
||||
onClause: onClause,
|
||||
}
|
||||
|
||||
qb.joins.add(newJoin)
|
||||
}
|
||||
|
||||
func (qb *queryBuilder) addJoins(joins ...join) {
|
||||
qb.joins.add(joins...)
|
||||
}
|
||||
|
||||
func (qb *queryBuilder) addFilter(f *filterBuilder) {
|
||||
err := f.getError()
|
||||
if err != nil {
|
||||
qb.err = err
|
||||
return
|
||||
}
|
||||
|
||||
clause, args := f.generateWhereClauses()
|
||||
if len(clause) > 0 {
|
||||
qb.addWhere(clause)
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
qb.addArg(args...)
|
||||
}
|
||||
|
||||
clause, args = f.generateHavingClauses()
|
||||
if len(clause) > 0 {
|
||||
qb.addHaving(clause)
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
qb.addArg(args...)
|
||||
}
|
||||
|
||||
qb.addJoins(f.getAllJoins()...)
|
||||
}
|
||||
|
||||
func (qb *queryBuilder) handleIntCriterionInput(c *models.IntCriterionInput, column string) {
|
||||
if c != nil {
|
||||
clause, count := getIntCriterionWhereClause(column, *c)
|
||||
|
||||
Reference in New Issue
Block a user