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

Method CommitCtx

pkg/sqlite3store/sqlite3store.go:89–112  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

87// given expiry time. If the session token already exists, then the data and expiry
88// time are updated.
89func (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.

Callers 1

CommitMethod · 0.95

Calls 5

toJulianDayFunction · 0.85
BeginTxMethod · 0.65
RollbackMethod · 0.65
ExecContextMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected