diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-12-11 14:02:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 14:02:17 +0000 |
commit | ebcacd1bb56d6e37ff743c0430bc91e24d440199 (patch) | |
tree | d9cd72accebe4004e8eb067026ab0158ccff0a1a /syncapi/storage/sqlite3/stream_id_table.go | |
parent | c55361c1b88b272c9a06e7dbc61f60e3effbd063 (diff) |
Give receipts their own stream ID in the database (#1631)
* Give read recipts their own database sequence
* Give receipts their own stream ID
* Change migration names
* Reset sequences
* Add max receipt queries, missing stream_id table entry for SQLite
Diffstat (limited to 'syncapi/storage/sqlite3/stream_id_table.go')
-rw-r--r-- | syncapi/storage/sqlite3/stream_id_table.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/syncapi/storage/sqlite3/stream_id_table.go b/syncapi/storage/sqlite3/stream_id_table.go index e6bdc4fc..f73be422 100644 --- a/syncapi/storage/sqlite3/stream_id_table.go +++ b/syncapi/storage/sqlite3/stream_id_table.go @@ -18,6 +18,8 @@ CREATE TABLE IF NOT EXISTS syncapi_stream_id ( ); INSERT INTO syncapi_stream_id (stream_name, stream_id) VALUES ("global", 0) ON CONFLICT DO NOTHING; +INSERT INTO syncapi_stream_id (stream_name, stream_id) VALUES ("receipt", 0) + ON CONFLICT DO NOTHING; ` const increaseStreamIDStmt = "" + @@ -56,3 +58,13 @@ func (s *streamIDStatements) nextStreamID(ctx context.Context, txn *sql.Tx) (pos err = selectStmt.QueryRowContext(ctx, "global").Scan(&pos) return } + +func (s *streamIDStatements) nextReceiptID(ctx context.Context, txn *sql.Tx) (pos types.StreamPosition, err error) { + increaseStmt := sqlutil.TxStmt(txn, s.increaseStreamIDStmt) + selectStmt := sqlutil.TxStmt(txn, s.selectStreamIDStmt) + if _, err = increaseStmt.ExecContext(ctx, "receipt"); err != nil { + return + } + err = selectStmt.QueryRowContext(ctx, "receipt").Scan(&pos) + return +} |