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)
| 54 | // If the session token is not found or is expired, the returned exists flag will |
| 55 | // be set to false. |
| 56 | func (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 |
no test coverage detected