Documentation
¶
Overview ¶
Package sqlite implements store.Store on SQLite (modernc.org/sqlite, no cgo). Several edge processes on one host can share the file: WAL mode, immediate transactions and a busy timeout serialize the writers.
Index ¶
- type Store
- func (s *Store) AcquireLease(ctx context.Context, name, holder string, now, ttlMs int64) (bool, error)
- func (s *Store) AppendEvent(ctx context.Context, e store.Event, ds []store.Delivery) (int64, error)
- func (s *Store) ChatLabels(ctx context.Context, session, chatID string) ([]store.Label, error)
- func (s *Store) ClaimDeliveries(ctx context.Context, holder string, now, lockMs int64, limit int) ([]store.Delivery, error)
- func (s *Store) Close() error
- func (s *Store) CompleteDelivery(ctx context.Context, id int64) error
- func (s *Store) CreateAPIKey(ctx context.Context, k store.APIKey) error
- func (s *Store) CreateSession(ctx context.Context, x store.Session) error
- func (s *Store) DeleteAPIKey(ctx context.Context, id string) error
- func (s *Store) DeleteChat(ctx context.Context, session, id string) error
- func (s *Store) DeleteChatMessages(ctx context.Context, session, chatID string) error
- func (s *Store) DeleteMessage(ctx context.Context, session, id string) error
- func (s *Store) DeleteSession(ctx context.Context, name string) error
- func (s *Store) EventsAfter(ctx context.Context, after int64, limit int) ([]store.Event, error)
- func (s *Store) GetAPIKey(ctx context.Context, id string) (store.APIKey, error)
- func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (store.APIKey, error)
- func (s *Store) GetChat(ctx context.Context, session, id string) (store.Chat, error)
- func (s *Store) GetContact(ctx context.Context, session, id string) (store.Contact, error)
- func (s *Store) GetLabel(ctx context.Context, session, id string) (store.Label, error)
- func (s *Store) GetMessage(ctx context.Context, session, id string) (store.Message, error)
- func (s *Store) GetMessageByWAID(ctx context.Context, session, waID string) (store.Message, error)
- func (s *Store) GetPoll(ctx context.Context, session, waID string) (store.Poll, error)
- func (s *Store) GetSession(ctx context.Context, name string) (store.Session, error)
- func (s *Store) LabelChats(ctx context.Context, session, labelID string) ([]string, error)
- func (s *Store) LastEventSeq(ctx context.Context) (int64, error)
- func (s *Store) LeaseHolder(ctx context.Context, name string, now int64) (string, error)
- func (s *Store) ListAPIKeys(ctx context.Context) ([]store.APIKey, error)
- func (s *Store) ListChats(ctx context.Context, session string, f store.ChatFilter) ([]store.Chat, error)
- func (s *Store) ListContacts(ctx context.Context, session string, limit, offset int) ([]store.Contact, error)
- func (s *Store) ListLabels(ctx context.Context, session string) ([]store.Label, error)
- func (s *Store) ListMessages(ctx context.Context, session, chatID string, f store.MessageFilter) ([]store.Message, error)
- func (s *Store) ListPresences(ctx context.Context, session, chatID string) ([]store.Presence, error)
- func (s *Store) ListSessions(ctx context.Context) ([]store.Session, error)
- func (s *Store) MessageAlias(ctx context.Context, session, waID string) (string, error)
- func (s *Store) PatchChat(ctx context.Context, session, id string, p store.ChatPatch) error
- func (s *Store) PollSecret(ctx context.Context, session, waID string) ([]byte, error)
- func (s *Store) PostponeDelivery(ctx context.Context, id int64, nextAt int64) error
- func (s *Store) PruneEvents(ctx context.Context, before int64) error
- func (s *Store) PurgeSession(ctx context.Context, name string) error
- func (s *Store) PutMessageAlias(ctx context.Context, session, waID, id string) error
- func (s *Store) PutPoll(ctx context.Context, session string, p store.Poll) error
- func (s *Store) PutPollSecret(ctx context.Context, session, waID string, secret []byte) error
- func (s *Store) PutPresence(ctx context.Context, p store.Presence) error
- func (s *Store) PutStatusRecipients(ctx context.Context, session, waID string, recipients []string) error
- func (s *Store) ReleaseLease(ctx context.Context, name, holder string) error
- func (s *Store) RetryDelivery(ctx context.Context, id int64, lastErr string, nextAt int64) error
- func (s *Store) SetAck(ctx context.Context, session string, waIDs []string, ack int) error
- func (s *Store) SetChatLabel(ctx context.Context, session, labelID, chatID string, on bool) error
- func (s *Store) SetEventCheckpoint(ctx context.Context, session string, seq, ts int64) error
- func (s *Store) StatusRecipients(ctx context.Context, session, waID string) ([]string, error)
- func (s *Store) TouchChat(ctx context.Context, session, id, name string, ts int64, lastMessageID string, ...) error
- func (s *Store) UpdateAPIKey(ctx context.Context, k store.APIKey) error
- func (s *Store) UpdateAck(ctx context.Context, session string, waIDs []string, ack int) error
- func (s *Store) UpdateSession(ctx context.Context, name string, p store.SessionPatch) (store.Session, error)
- func (s *Store) UpsertChat(ctx context.Context, c store.Chat) error
- func (s *Store) UpsertContact(ctx context.Context, c store.Contact) error
- func (s *Store) UpsertLabel(ctx context.Context, l store.Label) error
- func (s *Store) UpsertMessages(ctx context.Context, ms []store.Message) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the SQLite engine.
func (*Store) AcquireLease ¶
func (s *Store) AcquireLease(ctx context.Context, name, holder string, now, ttlMs int64) (bool, error)
AcquireLease takes the lease when free, expired or already ours.
func (*Store) AppendEvent ¶
AppendEvent stores the event and its deliveries atomically.
func (*Store) ChatLabels ¶
ChatLabels returns the labels a chat has.
func (*Store) ClaimDeliveries ¶
func (s *Store) ClaimDeliveries(ctx context.Context, holder string, now, lockMs int64, limit int) ([]store.Delivery, error)
ClaimDeliveries locks due deliveries for holder.
func (*Store) CompleteDelivery ¶
CompleteDelivery removes a delivered request.
func (*Store) CreateAPIKey ¶
CreateAPIKey inserts a key.
func (*Store) CreateSession ¶
CreateSession inserts a session; ErrConflict when the name is taken.
func (*Store) DeleteAPIKey ¶
DeleteAPIKey removes a key.
func (*Store) DeleteChat ¶
DeleteChat removes a chat and its messages.
func (*Store) DeleteChatMessages ¶
DeleteChatMessages removes every message of a chat.
func (*Store) DeleteMessage ¶
DeleteMessage removes one message.
func (*Store) DeleteSession ¶
DeleteSession removes the session row only; see PurgeSession.
func (*Store) EventsAfter ¶
EventsAfter returns events with seq > after, oldest first.
func (*Store) GetAPIKeyByHash ¶
GetAPIKeyByHash looks a key up by the hash of its value.
func (*Store) GetContact ¶
GetContact returns one contact.
func (*Store) GetMessage ¶
GetMessage returns one message by its WAHA id.
func (*Store) GetMessageByWAID ¶
GetMessageByWAID returns the newest message with WhatsApp id waID.
func (*Store) GetSession ¶
GetSession returns one session.
func (*Store) LabelChats ¶
LabelChats returns the chat ids under a label.
func (*Store) LastEventSeq ¶
LastEventSeq is the newest event's seq, 0 when there is none.
func (*Store) LeaseHolder ¶
LeaseHolder is who holds a live lease, "" when nobody does.
func (*Store) ListAPIKeys ¶
ListAPIKeys returns every key, oldest first.
func (*Store) ListChats ¶
func (s *Store) ListChats(ctx context.Context, session string, f store.ChatFilter) ([]store.Chat, error)
ListChats pages chats.
func (*Store) ListContacts ¶
func (s *Store) ListContacts(ctx context.Context, session string, limit, offset int) ([]store.Contact, error)
ListContacts pages contacts by id.
func (*Store) ListLabels ¶
ListLabels returns the labels that are not deleted.
func (*Store) ListMessages ¶
func (s *Store) ListMessages(ctx context.Context, session, chatID string, f store.MessageFilter) ([]store.Message, error)
ListMessages pages one chat's messages (every chat's for ""), newest first unless Ascending.
func (*Store) ListPresences ¶
func (s *Store) ListPresences(ctx context.Context, session, chatID string) ([]store.Presence, error)
ListPresences returns the presences of one chat, or of all, by chat and update order.
func (*Store) ListSessions ¶
ListSessions returns every session, by name.
func (*Store) MessageAlias ¶ added in v0.1.3
MessageAlias returns the id recorded for waID.
func (*Store) PollSecret ¶
PollSecret returns a poll's secret.
func (*Store) PostponeDelivery ¶
PostponeDelivery unlocks a claimed delivery, due at nextAt, without counting an attempt.
func (*Store) PruneEvents ¶
PruneEvents drops events created before the given time.
func (*Store) PurgeSession ¶
PurgeSession removes the session and everything stored for it.
func (*Store) PutMessageAlias ¶ added in v0.1.3
PutMessageAlias records the id an unstored event of mine went out under.
func (*Store) PutPollSecret ¶
PutPollSecret records a poll's secret.
func (*Store) PutPresence ¶
PutPresence replaces a participant's presence in a chat.
func (*Store) PutStatusRecipients ¶
func (s *Store) PutStatusRecipients(ctx context.Context, session, waID string, recipients []string) error
PutStatusRecipients records who a status went to.
func (*Store) ReleaseLease ¶
ReleaseLease drops the lease if holder has it.
func (*Store) RetryDelivery ¶
RetryDelivery reschedules a failed attempt, or drops it when nextAt is 0.
func (*Store) SetChatLabel ¶
SetChatLabel adds or removes a chat from a label.
func (*Store) SetEventCheckpoint ¶
SetEventCheckpoint records the last core event processed for a session.
func (*Store) StatusRecipients ¶
StatusRecipients returns who a status went to.
func (*Store) TouchChat ¶
func (s *Store) TouchChat(ctx context.Context, session, id, name string, ts int64, lastMessageID string, unread int) error
TouchChat records a message in a chat without touching its flags.
func (*Store) UpdateAPIKey ¶
UpdateAPIKey rewrites a key's flags and sessions (never its hash).
func (*Store) UpdateSession ¶
func (s *Store) UpdateSession(ctx context.Context, name string, p store.SessionPatch) (store.Session, error)
UpdateSession applies a patch and returns the updated session.
func (*Store) UpsertChat ¶
UpsertChat inserts or replaces a chat. The conversation timestamp and last message only move forward, so an old history chunk cannot rewind them.
func (*Store) UpsertContact ¶
UpsertContact inserts or merges a contact; empty names do not erase.
func (*Store) UpsertLabel ¶
UpsertLabel inserts or replaces a label.