diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml index 2bbd70d..95e2a73 100644 --- a/.github/workflows/ghcr.yml +++ b/.github/workflows/ghcr.yml @@ -3,21 +3,21 @@ name: Deploy Image to GHCR on: push: tags: - - 'v*.*.*' + - "v*.*.*" jobs: build-push: runs-on: ubuntu-latest steps: - - name: 'Checkout GitHub Action' + - name: "Checkout GitHub Action" uses: actions/checkout@main - - name: 'Login to GitHub Container Registry' + - name: "Login to GitHub Container Registry" uses: docker/login-action@v1 with: registry: ghcr.io username: mgdigital password: ${{secrets.GHCR_TOKEN}} - - name: 'Build and push' + - name: "Build and push" run: | docker build . --tag ghcr.io/mgdigital/rarbg-selfhosted:${GITHUB_REF#refs/tags/} --tag ghcr.io/mgdigital/rarbg-selfhosted:latest docker push --all-tags ghcr.io/mgdigital/rarbg-selfhosted diff --git a/sqlitedb/query.go b/sqlitedb/query.go index 5339e24..ac77c48 100644 --- a/sqlitedb/query.go +++ b/sqlitedb/query.go @@ -32,6 +32,28 @@ type SearchQuery struct { } func Query(db *sql.DB, query *SearchQuery) ([]Record, error) { + sqlQuery, err := createQuery(query) + log.WithField("query", sqlQuery).Debug("SQL query") + if err != nil { + return nil, err + } + rows, err := db.Query(sqlQuery) + if err != nil { + return nil, err + } + var records []Record + for rows.Next() { + record := Record{} + err = rows.Scan(&record.Id, &record.Hash, &record.Title, &record.Dt, &record.Cat, &record.Size, &record.ExtId, &record.Imdb) + if err != nil { + return nil, err + } + records = append(records, record) + } + return records, nil +} + +func createQuery(query *SearchQuery) (string, error) { dialect := goqu.Dialect("sqlite3") var expressions []goqu.Expression if len(query.Query) > 0 { @@ -56,22 +78,5 @@ func Query(db *sql.DB, query *SearchQuery) ([]Record, error) { } ds := dialect.From("items").Where(expressions...).Order(goqu.C("dt").Desc()).Limit(query.Limit).Offset(query.Offset) sqlQuery, _, err := ds.ToSQL() - log.WithField("query", sqlQuery).Debug("SQL query") - if err != nil { - return nil, err - } - rows, err := db.Query(sqlQuery) - if err != nil { - return nil, err - } - var records []Record - for rows.Next() { - record := Record{} - err = rows.Scan(&record.Id, &record.Hash, &record.Title, &record.Dt, &record.Cat, &record.Size, &record.ExtId, &record.Imdb) - if err != nil { - return nil, err - } - records = append(records, record) - } - return records, nil + return sqlQuery, err }