mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-01 15:00:00 +00:00
2dc9fc1626
* start moving to bun * changing more stuff * more * and yet more * tests passing * seems stable now * more big changes * small fix * little fixes
55 lines
896 B
Go
55 lines
896 B
Go
package bun
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"reflect"
|
|
)
|
|
|
|
type scanModel struct {
|
|
db *DB
|
|
|
|
dest []interface{}
|
|
scanIndex int
|
|
}
|
|
|
|
var _ model = (*scanModel)(nil)
|
|
|
|
func newScanModel(db *DB, dest []interface{}) *scanModel {
|
|
return &scanModel{
|
|
db: db,
|
|
dest: dest,
|
|
}
|
|
}
|
|
|
|
func (m *scanModel) Value() interface{} {
|
|
return m.dest
|
|
}
|
|
|
|
func (m *scanModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, error) {
|
|
if !rows.Next() {
|
|
return 0, rows.Err()
|
|
}
|
|
|
|
dest := makeDest(m, len(m.dest))
|
|
|
|
m.scanIndex = 0
|
|
if err := rows.Scan(dest...); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return 1, nil
|
|
}
|
|
|
|
func (m *scanModel) ScanRow(ctx context.Context, rows *sql.Rows) error {
|
|
return rows.Scan(m.dest...)
|
|
}
|
|
|
|
func (m *scanModel) Scan(src interface{}) error {
|
|
dest := reflect.ValueOf(m.dest[m.scanIndex])
|
|
m.scanIndex++
|
|
|
|
scanner := m.db.dialect.Scanner(dest.Type())
|
|
return scanner(dest, src)
|
|
}
|