db

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package db is the persistent cache of Telega lookup results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache wraps a SQLite connection scoped to antitelega's lookups table.

func Open

func Open(path string, ttl time.Duration) (*Cache, error)

Open creates the parent directory if needed, opens the SQLite file, and applies the schema. ttl is how long a result is considered fresh.

func (*Cache) Close

func (c *Cache) Close() error

Close releases the underlying database.

func (*Cache) Get

func (c *Cache) Get(userID int64) (Lookup, bool, error)

Get returns a cached lookup if it exists and has not expired. Returns (zero, false, nil) if absent or stale.

func (*Cache) GetMany

func (c *Cache) GetMany(userIDs []int64) (map[int64]Lookup, error)

GetMany returns cached fresh lookups for a slice of user IDs. Missing/stale entries are simply not included in the result.

func (*Cache) Put

func (c *Cache) Put(l Lookup) error

Put upserts a lookup entry. checked_at is set to time.Now().

func (*Cache) PutMany

func (c *Cache) PutMany(items []Lookup) error

PutMany upserts many entries in a single transaction.

type Lookup

type Lookup struct {
	UserID      int64
	IsTelega    bool
	DisplayName string
	Username    string
	CheckedAt   time.Time
}

Lookup is a single cache entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL