Documentation
¶
Index ¶
- Constants
- func Connect(path string) (*sql.DB, error)
- func ConnectReadonly(path string) (*sql.DB, error)
- func InsertMessage(db *sql.DB, m Message) error
- func MarkDeleted(db *sql.DB, chatID, messageID int64) error
- func RecordUploadedMedia(db *sql.DB, chatID, messageID int64, text, mediaType, mediaPath string) error
- func UpsertEntity(db *sql.DB, id int64, kind EntityKind, accessHash int64) error
- func UpsertMe(db *sql.DB, r MeRow) error
- type DatabaseMissing
- type EntityKind
- type ListOptions
- type MeRow
- type Message
- type MessageSummary
- type SearchOptions
- type ShowOptions
Constants ¶
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 ¶
Connect opens the DB read-write, applies schema, and runs idempotent migrations. Mirrors tgcli.db.connect.
func ConnectReadonly ¶
ConnectReadonly opens the DB read-only and never writes or migrates. Returns *resolve.DatabaseMissing when the file does not exist.
func InsertMessage ¶
InsertMessage is a test helper for seeding tg_messages.
func MarkDeleted ¶
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 ¶
UpsertEntity persists an (id, kind, access_hash) tuple. Use AccessHash=0 for basic groups.
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 ¶
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.
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.
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 ¶
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.