···
+
_ "github.com/mattn/go-sqlite3"
+
type SqliteStore struct {
+
type SqliteStoreOpt func(*SqliteStore)
+
func WithTableName(name string) SqliteStoreOpt {
+
return func(s *SqliteStore) {
+
func NewSQLiteStore(dbPath string, opts ...SqliteStoreOpt) (*SqliteStore, error) {
+
db, err := sql.Open("sqlite3", dbPath)
+
return nil, fmt.Errorf("failed to open sqlite database: %w", err)
+
for _, o := range opts {
+
if err := store.init(); err != nil {
+
func (s *SqliteStore) init() error {
+
createTable := fmt.Sprintf(`
+
create table if not exists %s (
+
_, err := s.db.Exec(createTable)
+
func (s *SqliteStore) Set(knot string, cursor int64) {
+
insert into %s (knot, cursor)
+
on conflict(knot) do update set cursor=excluded.cursor;
+
_, err := s.db.Exec(query, knot, cursor)
+
func (s *SqliteStore) Get(knot string) (cursor int64) {
+
select cursor from %s where knot = ?;
+
err := s.db.QueryRow(query, knot).Scan(&cursor)
+
if err != sql.ErrNoRows {