MCPcopy
hub / github.com/autobrr/qui / FindCtx

Method FindCtx

pkg/sqlite3store/sqlite3store.go:56–77  ·  view source on GitHub ↗

FindCtx returns the data for a given session token from the SQLite3Store instance. If the session token is not found or is expired, the returned exists flag will be set to false.

(ctx context.Context, token string)

Source from the content-addressed store, hash-verified

54// If the session token is not found or is expired, the returned exists flag will
55// be set to false.
56func (p *SQLite3Store) FindCtx(ctx context.Context, token string) (b []byte, exists bool, err error) {
57 tx, err := p.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
58 if err != nil {
59 return nil, false, err
60 }
61 defer tx.Rollback()
62
63 row := tx.QueryRowContext(ctx, "SELECT data FROM sessions WHERE token = ? AND expiry > ?", token, nowJulianDay())
64 err = row.Scan(&b)
65 if err != nil {
66 if errors.Is(err, sql.ErrNoRows) {
67 return nil, false, nil
68 }
69 return nil, false, err
70 }
71
72 if err = tx.Commit(); err != nil {
73 return nil, false, err
74 }
75
76 return b, true, nil
77}
78
79// Commit adds a session token and data to the SQLite3Store instance with the
80// given expiry time. If the session token already exists, then the data and expiry

Callers 1

FindMethod · 0.95

Calls 7

nowJulianDayFunction · 0.85
ScanMethod · 0.80
BeginTxMethod · 0.65
RollbackMethod · 0.65
QueryRowContextMethod · 0.65
CommitMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected