sqlite

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 Open

func Open(ctx context.Context, path string) (*Store, error)

Open opens (creating if needed) the database at path and migrates it.

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

func (s *Store) AppendEvent(ctx context.Context, e store.Event, ds []store.Delivery) (int64, error)

AppendEvent stores the event and its deliveries atomically.

func (*Store) ChatLabels

func (s *Store) ChatLabels(ctx context.Context, session, chatID string) ([]store.Label, error)

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) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) CompleteDelivery

func (s *Store) CompleteDelivery(ctx context.Context, id int64) error

CompleteDelivery removes a delivered request.

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(ctx context.Context, k store.APIKey) error

CreateAPIKey inserts a key.

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, x store.Session) error

CreateSession inserts a session; ErrConflict when the name is taken.

func (*Store) DeleteAPIKey

func (s *Store) DeleteAPIKey(ctx context.Context, id string) error

DeleteAPIKey removes a key.

func (*Store) DeleteChat

func (s *Store) DeleteChat(ctx context.Context, session, id string) error

DeleteChat removes a chat and its messages.

func (*Store) DeleteChatMessages

func (s *Store) DeleteChatMessages(ctx context.Context, session, chatID string) error

DeleteChatMessages removes every message of a chat.

func (*Store) DeleteMessage

func (s *Store) DeleteMessage(ctx context.Context, session, id string) error

DeleteMessage removes one message.

func (*Store) DeleteSession

func (s *Store) DeleteSession(ctx context.Context, name string) error

DeleteSession removes the session row only; see PurgeSession.

func (*Store) EventsAfter

func (s *Store) EventsAfter(ctx context.Context, after int64, limit int) ([]store.Event, error)

EventsAfter returns events with seq > after, oldest first.

func (*Store) GetAPIKey

func (s *Store) GetAPIKey(ctx context.Context, id string) (store.APIKey, error)

GetAPIKey looks a key up by id.

func (*Store) GetAPIKeyByHash

func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (store.APIKey, error)

GetAPIKeyByHash looks a key up by the hash of its value.

func (*Store) GetChat

func (s *Store) GetChat(ctx context.Context, session, id string) (store.Chat, error)

GetChat returns one chat.

func (*Store) GetContact

func (s *Store) GetContact(ctx context.Context, session, id string) (store.Contact, error)

GetContact returns one contact.

func (*Store) GetLabel

func (s *Store) GetLabel(ctx context.Context, session, id string) (store.Label, error)

GetLabel returns one label, deleted or not.

func (*Store) GetMessage

func (s *Store) GetMessage(ctx context.Context, session, id string) (store.Message, error)

GetMessage returns one message by its WAHA id.

func (*Store) GetMessageByWAID

func (s *Store) GetMessageByWAID(ctx context.Context, session, waID string) (store.Message, error)

GetMessageByWAID returns the newest message with WhatsApp id waID.

func (*Store) GetPoll

func (s *Store) GetPoll(ctx context.Context, session, waID string) (store.Poll, error)

GetPoll returns a sent poll.

func (*Store) GetSession

func (s *Store) GetSession(ctx context.Context, name string) (store.Session, error)

GetSession returns one session.

func (*Store) LabelChats

func (s *Store) LabelChats(ctx context.Context, session, labelID string) ([]string, error)

LabelChats returns the chat ids under a label.

func (*Store) LastEventSeq

func (s *Store) LastEventSeq(ctx context.Context) (int64, error)

LastEventSeq is the newest event's seq, 0 when there is none.

func (*Store) LeaseHolder

func (s *Store) LeaseHolder(ctx context.Context, name string, now int64) (string, error)

LeaseHolder is who holds a live lease, "" when nobody does.

func (*Store) ListAPIKeys

func (s *Store) ListAPIKeys(ctx context.Context) ([]store.APIKey, error)

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

func (s *Store) ListLabels(ctx context.Context, session string) ([]store.Label, error)

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

func (s *Store) ListSessions(ctx context.Context) ([]store.Session, error)

ListSessions returns every session, by name.

func (*Store) MessageAlias added in v0.1.3

func (s *Store) MessageAlias(ctx context.Context, session, waID string) (string, error)

MessageAlias returns the id recorded for waID.

func (*Store) PatchChat

func (s *Store) PatchChat(ctx context.Context, session, id string, p store.ChatPatch) error

PatchChat sets the given flags, creating the chat when needed.

func (*Store) PollSecret

func (s *Store) PollSecret(ctx context.Context, session, waID string) ([]byte, error)

PollSecret returns a poll's secret.

func (*Store) PostponeDelivery

func (s *Store) PostponeDelivery(ctx context.Context, id int64, nextAt int64) error

PostponeDelivery unlocks a claimed delivery, due at nextAt, without counting an attempt.

func (*Store) PruneEvents

func (s *Store) PruneEvents(ctx context.Context, before int64) error

PruneEvents drops events created before the given time.

func (*Store) PurgeSession

func (s *Store) PurgeSession(ctx context.Context, name string) error

PurgeSession removes the session and everything stored for it.

func (*Store) PutMessageAlias added in v0.1.3

func (s *Store) PutMessageAlias(ctx context.Context, session, waID, id string) error

PutMessageAlias records the id an unstored event of mine went out under.

func (*Store) PutPoll

func (s *Store) PutPoll(ctx context.Context, session string, p store.Poll) error

PutPoll records a sent poll.

func (*Store) PutPollSecret

func (s *Store) PutPollSecret(ctx context.Context, session, waID string, secret []byte) error

PutPollSecret records a poll's secret.

func (*Store) PutPresence

func (s *Store) PutPresence(ctx context.Context, p store.Presence) error

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

func (s *Store) ReleaseLease(ctx context.Context, name, holder string) error

ReleaseLease drops the lease if holder has it.

func (*Store) RetryDelivery

func (s *Store) RetryDelivery(ctx context.Context, id int64, lastErr string, nextAt int64) error

RetryDelivery reschedules a failed attempt, or drops it when nextAt is 0.

func (*Store) SetAck

func (s *Store) SetAck(ctx context.Context, session string, waIDs []string, ack int) error

SetAck sets the ack of the given messages, lowering it if need be.

func (*Store) SetChatLabel

func (s *Store) SetChatLabel(ctx context.Context, session, labelID, chatID string, on bool) error

SetChatLabel adds or removes a chat from a label.

func (*Store) SetEventCheckpoint

func (s *Store) SetEventCheckpoint(ctx context.Context, session string, seq, ts int64) error

SetEventCheckpoint records the last core event processed for a session.

func (*Store) StatusRecipients

func (s *Store) StatusRecipients(ctx context.Context, session, waID string) ([]string, error)

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

func (s *Store) UpdateAPIKey(ctx context.Context, k store.APIKey) error

UpdateAPIKey rewrites a key's flags and sessions (never its hash).

func (*Store) UpdateAck

func (s *Store) UpdateAck(ctx context.Context, session string, waIDs []string, ack int) error

UpdateAck raises the ack of the given messages, never lowering it.

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

func (s *Store) UpsertChat(ctx context.Context, c store.Chat) error

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

func (s *Store) UpsertContact(ctx context.Context, c store.Contact) error

UpsertContact inserts or merges a contact; empty names do not erase.

func (*Store) UpsertLabel

func (s *Store) UpsertLabel(ctx context.Context, l store.Label) error

UpsertLabel inserts or replaces a label.

func (*Store) UpsertMessages

func (s *Store) UpsertMessages(ctx context.Context, ms []store.Message) error

UpsertMessages inserts or replaces messages. A replayed message keeps the higher of the stored and the new ack, in its column and in its body.

Jump to

Keyboard shortcuts

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