Restructure data layer (#2532)

* Add new txn manager interface
* Add txn management to sqlite
* Rename get to getByID
* Add contexts to repository methods
* Update query builders
* Add context to reader writer interfaces
* Use repository in resolver
* Tighten interfaces
* Tighten interfaces in dlna
* Tighten interfaces in match package
* Tighten interfaces in scraper package
* Tighten interfaces in scan code
* Tighten interfaces on autotag package
* Remove ReaderWriter usage
* Merge database package into sqlite
This commit is contained in:
WithoutPants
2022-05-19 17:49:32 +10:00
parent 7b5bd80515
commit 964b559309
244 changed files with 7377 additions and 6699 deletions

View File

@@ -1,6 +1,7 @@
package sqlite
import (
"context"
"fmt"
"strings"
@@ -54,24 +55,24 @@ func (qb queryBuilder) toSQL(includeSortPagination bool) string {
return body
}
func (qb queryBuilder) findIDs() ([]int, error) {
func (qb queryBuilder) findIDs(ctx context.Context) ([]int, error) {
const includeSortPagination = true
sql := qb.toSQL(includeSortPagination)
logger.Tracef("SQL: %s, args: %v", sql, qb.args)
return qb.repository.runIdsQuery(sql, qb.args)
return qb.repository.runIdsQuery(ctx, sql, qb.args)
}
func (qb queryBuilder) executeFind() ([]int, int, error) {
func (qb queryBuilder) executeFind(ctx context.Context) ([]int, int, error) {
if qb.err != nil {
return nil, 0, qb.err
}
body := qb.body()
return qb.repository.executeFindQuery(body, qb.args, qb.sortAndPagination, qb.whereClauses, qb.havingClauses, qb.withClauses, qb.recursiveWith)
return qb.repository.executeFindQuery(ctx, body, qb.args, qb.sortAndPagination, qb.whereClauses, qb.havingClauses, qb.withClauses, qb.recursiveWith)
}
func (qb queryBuilder) executeCount() (int, error) {
func (qb queryBuilder) executeCount(ctx context.Context) (int, error) {
if qb.err != nil {
return 0, qb.err
}
@@ -89,7 +90,7 @@ func (qb queryBuilder) executeCount() (int, error) {
body = qb.repository.buildQueryBody(body, qb.whereClauses, qb.havingClauses)
countQuery := withClause + qb.repository.buildCountQuery(body)
return qb.repository.runCountQuery(countQuery, qb.args)
return qb.repository.runCountQuery(ctx, countQuery, qb.args)
}
func (qb *queryBuilder) addWhere(clauses ...string) {