summaryrefslogtreecommitdiff
path: root/internal/storage/sql_rows.go
blob: f89c191212797963f0af37e50071d605a7d88b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package storage

import (
	"database/sql"

	"github.com/jmoiron/sqlx"

	"github.com/authelia/authelia/v4/internal/model"
)

// ConsentPreConfigRows holds and assists with retrieving multiple model.OAuth2ConsentSession rows.
type ConsentPreConfigRows struct {
	rows *sqlx.Rows
}

// Next is the row iterator.
func (r *ConsentPreConfigRows) Next() bool {
	if r.rows == nil {
		return false
	}

	return r.rows.Next()
}

// Close the rows.
func (r *ConsentPreConfigRows) Close() (err error) {
	if r.rows == nil {
		return nil
	}

	return r.rows.Close()
}

// Get returns the *model.OAuth2ConsentSession or scan error.
func (r *ConsentPreConfigRows) Get() (config *model.OAuth2ConsentPreConfig, err error) {
	if r.rows == nil {
		return nil, sql.ErrNoRows
	}

	config = &model.OAuth2ConsentPreConfig{}

	if err = r.rows.StructScan(config); err != nil {
		return nil, err
	}

	return config, nil
}