package db import ( "database/sql" "errors" ) // false on a fresh db, so the client replays from 0 instead of the live tail func GetCursor(e Execer) (timeUs int64, ok bool, err error) { err = e.QueryRow(`select last_time_us from jetstream_cursor where id = 0`).Scan(&timeUs) if errors.Is(err, sql.ErrNoRows) { return 0, false, nil } return timeUs, err == nil, err } // max keeps a rewound replay from dragging the cursor back func SaveCursor(e Execer, timeUs int64) error { _, err := e.Exec( `insert into jetstream_cursor (id, last_time_us) values (0, ?) on conflict(id) do update set last_time_us = max(last_time_us, excluded.last_time_us)`, timeUs, ) return err } func GetBootstrapUs(e Execer) int64 { var us int64 _ = e.QueryRow(`select time_us from ingest_bootstrap where id = 0`).Scan(&us) return us }