store

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Schema = `` /* 1811-byte string literal not displayed */

Schema mirrors tgcli/db.py SCHEMA plus the column migrations that Python applies in _migrate (media_path, deleted, left). Go ports the migrated final state in one statement.

Variables

This section is empty.

Functions

func Connect

func Connect(path string) (*sql.DB, error)

Connect opens the DB read-write, applies schema, and runs idempotent migrations. Mirrors tgcli.db.connect.

func ConnectReadonly

func ConnectReadonly(path string) (*sql.DB, error)

ConnectReadonly opens the DB read-only and never writes or migrates. Returns *resolve.DatabaseMissing when the file does not exist.

func InsertMessage

func InsertMessage(db *sql.DB, m Message) error

InsertMessage is a test helper for seeding tg_messages.

func MarkDeleted

func MarkDeleted(db *sql.DB, chatID, messageID int64) error

MarkDeleted is a test helper that sets deleted=1 on a row.

func RecordUploadedMedia

func RecordUploadedMedia(db *sql.DB, chatID, messageID int64, text, mediaType, mediaPath string) error

RecordUploadedMedia upserts the local cache row for a message created by an upload.

func UpsertEntity

func UpsertEntity(db *sql.DB, id int64, kind EntityKind, accessHash int64) error

UpsertEntity persists an (id, kind, access_hash) tuple. Use AccessHash=0 for basic groups.

func UpsertMe

func UpsertMe(db *sql.DB, r MeRow) error

UpsertMe writes or replaces the single self-row in tg_me.

Types

type DatabaseMissing

type DatabaseMissing struct{ Path string }

DatabaseMissing → exit 4 (matches Python tgcli.db.DatabaseMissing).

func (*DatabaseMissing) Error

func (e *DatabaseMissing) Error() string

type EntityKind

type EntityKind string

EntityKind is the access-hash partition. Telegram peer ids are *not* unique across kinds: a user with id 100 and a channel with id 100 are different entities and need different access hashes.

const (
	EntityUser    EntityKind = "user"
	EntityChannel EntityKind = "channel"
	EntityChat    EntityKind = "chat" // basic group, no access_hash
)

func LoadEntity

func LoadEntity(db *sql.DB, id int64) (EntityKind, int64, bool)

LoadEntity returns (kind, access_hash, true) when a row exists, else ("", 0, false).

type ListOptions

type ListOptions struct {
	ChatID         int64
	Since          string // empty = no lower bound (already in YYYY-MM-DDT00:00:00 form)
	Until          string // empty = no upper bound (in YYYY-MM-DDT23:59:59 form)
	Limit          int
	Reverse        bool
	IncludeDeleted bool
}

ListOptions mirrors `list-msgs` with optional inclusive day boundaries.

type MeRow

type MeRow struct {
	UserID      int64
	Username    sql.NullString
	Phone       sql.NullString
	FirstName   sql.NullString
	LastName    sql.NullString
	DisplayName sql.NullString
	IsBot       int
	CachedAt    string
	RawJSON     sql.NullString
}

MeRow mirrors the tg_me table.

func LoadMe

func LoadMe(db *sql.DB) (*MeRow, error)

LoadMe returns the cached self-user row, or sql.ErrNoRows if absent.

type Message

type Message struct {
	ChatID       int64
	MessageID    int64
	SenderID     *int64
	Date         string
	Text         *string
	IsOutgoing   bool
	ReplyToMsgID *int64
	HasMedia     bool
	MediaType    *string
	MediaPath    *string
	RawJSON      *string
}

Message mirrors the Python `_full_message` row shape.

func GetOne

func GetOne(db *sql.DB, chatID, messageID int64, includeDeleted bool) (*Message, error)

GetOne returns the full message row, or sql.ErrNoRows when absent.

type MessageSummary

type MessageSummary struct {
	MessageID  int64
	Date       string
	IsOutgoing bool
	Text       *string
	MediaType  *string
}

MessageSummary mirrors the Python `_message_summary` row shape.

func List

func List(db *sql.DB, opts ListOptions) ([]MessageSummary, error)

List filters by chat + optional date range.

func Search(db *sql.DB, opts SearchOptions) ([]MessageSummary, error)

Search filters tg_messages by chat + LIKE pattern, optionally case-sensitive.

func Show

func Show(db *sql.DB, opts ShowOptions) ([]MessageSummary, error)

Show returns up to Limit messages for ChatID. When IncludeDeleted is false (the Python default), tombstoned rows are excluded.

type SearchOptions

type SearchOptions struct {
	ChatID         int64
	Query          string
	CaseSensitive  bool
	Limit          int
	IncludeDeleted bool
}

SearchOptions mirrors the Python `search` arg surface (sans chat resolver).

type ShowOptions

type ShowOptions struct {
	ChatID         int64
	Limit          int
	Reverse        bool
	IncludeDeleted bool
}

ShowOptions mirrors the Python `show` arg surface.

Jump to

Keyboard shortcuts

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