CommitCtx adds a session token and data to the SQLite3Store instance with the given expiry time. If the session token already exists, then the data and expiry time are updated.
(ctx context.Context, token string, b []byte, expiry time.Time)
| 87 | // given expiry time. If the session token already exists, then the data and expiry |
| 88 | // time are updated. |
| 89 | func (p *SQLite3Store) CommitCtx(ctx context.Context, token string, b []byte, expiry time.Time) error { |
| 90 | tx, err := p.db.BeginTx(ctx, nil) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | defer func() { _ = tx.Rollback() }() |
| 95 | |
| 96 | _, err = tx.ExecContext(ctx, ` |
| 97 | INSERT INTO sessions (token, data, expiry) |
| 98 | VALUES (?, ?, ?) |
| 99 | ON CONFLICT(token) DO UPDATE SET |
| 100 | data = excluded.data, |
| 101 | expiry = excluded.expiry |
| 102 | `, token, b, toJulianDay(expiry.UTC())) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | |
| 107 | if err = tx.Commit(); err != nil { |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | // Delete removes a session token and corresponding data from the SQLite3Store |
| 115 | // instance. |
no test coverage detected