package sqlstore
import "go.mau.fi/whatsmeow/store/sqlstore"
Package sqlstore contains an SQL-backed implementation of the interfaces in the store package.
Package sqlstore contains an SQL-backed implementation of the interfaces in the store package.
Index ¶
- Variables
- type CachedLIDMap
- func NewCachedLIDMap(db *dbutil.Database) *CachedLIDMap
- func (s *CachedLIDMap) FillCache(ctx context.Context) error
- func (s *CachedLIDMap) GetLIDForPN(ctx context.Context, pn types.JID) (types.JID, error)
- func (s *CachedLIDMap) GetPNForLID(ctx context.Context, lid types.JID) (types.JID, error)
- func (s *CachedLIDMap) PutLIDMapping(ctx context.Context, lid, pn types.JID) error
- func (s *CachedLIDMap) PutManyLIDMappings(ctx context.Context, mappings []store.LIDMapping) error
- type Container
- func New(ctx context.Context, dialect, address string, log waLog.Logger) (*Container, error)
- func NewWithDB(db *sql.DB, dialect string, log waLog.Logger) *Container
- func NewWithWrappedDB(wrapped *dbutil.Database, log waLog.Logger) *Container
- func (c *Container) Close() error
- func (c *Container) DeleteDevice(ctx context.Context, store *store.Device) error
- func (c *Container) GetAllDevices(ctx context.Context) ([]*store.Device, error)
- func (c *Container) GetDevice(ctx context.Context, jid types.JID) (*store.Device, error)
- func (c *Container) GetFirstDevice(ctx context.Context) (*store.Device, error)
- func (c *Container) NewDevice() *store.Device
- func (c *Container) PutDevice(ctx context.Context, device *store.Device) error
- func (c *Container) Upgrade(ctx context.Context) error
- type SQLStore
- func NewSQLStore(c *Container, jid types.JID) *SQLStore
- func (s *SQLStore) ClearBufferedEventPlaintext(ctx context.Context, ciphertextHash [32]byte) error
- func (s *SQLStore) DeleteAllIdentities(ctx context.Context, phone string) error
- func (s *SQLStore) DeleteAllSessions(ctx context.Context, phone string) error
- func (s *SQLStore) DeleteAppStateMutationMACs(ctx context.Context, name string, indexMACs [][]byte) (err error)
- func (s *SQLStore) DeleteAppStateVersion(ctx context.Context, name string) error
- func (s *SQLStore) DeleteIdentity(ctx context.Context, address string) error
- func (s *SQLStore) DeleteOldBufferedHashes(ctx context.Context) error
- func (s *SQLStore) DeleteSession(ctx context.Context, address string) error
- func (s *SQLStore) DoDecryptionTxn(ctx context.Context, fn func(context.Context) error) error
- func (s *SQLStore) GenOnePreKey(ctx context.Context) (*keys.PreKey, error)
- func (s *SQLStore) GetAllContacts(ctx context.Context) (map[types.JID]types.ContactInfo, error)
- func (s *SQLStore) GetAppStateMutationMAC(ctx context.Context, name string, indexMAC []byte) (valueMAC []byte, err error)
- func (s *SQLStore) GetAppStateSyncKey(ctx context.Context, id []byte) (*store.AppStateSyncKey, error)
- func (s *SQLStore) GetAppStateVersion(ctx context.Context, name string) (version uint64, hash [128]byte, err error)
- func (s *SQLStore) GetBufferedEvent(ctx context.Context, ciphertextHash [32]byte) (*store.BufferedEvent, error)
- func (s *SQLStore) GetChatSettings(ctx context.Context, chat types.JID) (settings types.LocalChatSettings, err error)
- func (s *SQLStore) GetContact(ctx context.Context, user types.JID) (types.ContactInfo, error)
- func (s *SQLStore) GetLatestAppStateSyncKeyID(ctx context.Context) ([]byte, error)
- func (s *SQLStore) GetMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID) (secret []byte, err error)
- func (s *SQLStore) GetOrGenPreKeys(ctx context.Context, count uint32) ([]*keys.PreKey, error)
- func (s *SQLStore) GetPreKey(ctx context.Context, id uint32) (*keys.PreKey, error)
- func (s *SQLStore) GetPrivacyToken(ctx context.Context, user types.JID) (*store.PrivacyToken, error)
- func (s *SQLStore) GetSenderKey(ctx context.Context, group, user string) (key []byte, err error)
- func (s *SQLStore) GetSession(ctx context.Context, address string) (session []byte, err error)
- func (s *SQLStore) HasSession(ctx context.Context, address string) (has bool, err error)
- func (s *SQLStore) IsTrustedIdentity(ctx context.Context, address string, key [32]byte) (bool, error)
- func (s *SQLStore) MarkPreKeysAsUploaded(ctx context.Context, upToID uint32) error
- func (s *SQLStore) MigratePNToLID(ctx context.Context, pn, lid types.JID) error
- func (s *SQLStore) PutAllContactNames(ctx context.Context, contacts []store.ContactEntry) error
- func (s *SQLStore) PutAppStateMutationMACs(ctx context.Context, name string, version uint64, mutations []store.AppStateMutationMAC) error
- func (s *SQLStore) PutAppStateSyncKey(ctx context.Context, id []byte, key store.AppStateSyncKey) error
- func (s *SQLStore) PutAppStateVersion(ctx context.Context, name string, version uint64, hash [128]byte) error
- func (s *SQLStore) PutArchived(ctx context.Context, chat types.JID, archived bool) error
- func (s *SQLStore) PutBufferedEvent(ctx context.Context, ciphertextHash [32]byte, plaintext []byte, serverTimestamp time.Time) error
- func (s *SQLStore) PutBusinessName(ctx context.Context, user types.JID, businessName string) (bool, string, error)
- func (s *SQLStore) PutContactName(ctx context.Context, user types.JID, firstName, fullName string) error
- func (s *SQLStore) PutIdentity(ctx context.Context, address string, key [32]byte) error
- func (s *SQLStore) PutMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID, secret []byte) (err error)
- func (s *SQLStore) PutMessageSecrets(ctx context.Context, inserts []store.MessageSecretInsert) (err error)
- func (s *SQLStore) PutMutedUntil(ctx context.Context, chat types.JID, mutedUntil time.Time) error
- func (s *SQLStore) PutPinned(ctx context.Context, chat types.JID, pinned bool) error
- func (s *SQLStore) PutPrivacyTokens(ctx context.Context, tokens ...store.PrivacyToken) error
- func (s *SQLStore) PutPushName(ctx context.Context, user types.JID, pushName string) (bool, string, error)
- func (s *SQLStore) PutSenderKey(ctx context.Context, group, user string, session []byte) error
- func (s *SQLStore) PutSession(ctx context.Context, address string, session []byte) error
- func (s *SQLStore) RemovePreKey(ctx context.Context, id uint32) error
- func (s *SQLStore) UploadedPreKeyCount(ctx context.Context) (count int, err error)
Variables ¶
ErrDeviceIDMustBeSet is the error returned by PutDevice if you try to save a device before knowing its JID.
ErrInvalidLength is returned by some database getters if the database returned a byte array with an unexpected length. This should be impossible, as the database schema contains CHECK()s for all the relevant columns.
PostgresArrayWrapper is a function to wrap array values before passing them to the sql package.
When using github.com/lib/pq, you should set
whatsmeow.PostgresArrayWrapper = pq.Array
Types ¶
type CachedLIDMap ¶
type CachedLIDMap struct {
// contains filtered or unexported fields
}
func NewCachedLIDMap ¶
func NewCachedLIDMap(db *dbutil.Database) *CachedLIDMap
func (*CachedLIDMap) FillCache ¶
func (s *CachedLIDMap) FillCache(ctx context.Context) error
func (*CachedLIDMap) GetLIDForPN ¶
func (*CachedLIDMap) GetPNForLID ¶
func (*CachedLIDMap) PutLIDMapping ¶
func (*CachedLIDMap) PutManyLIDMappings ¶
func (s *CachedLIDMap) PutManyLIDMappings(ctx context.Context, mappings []store.LIDMapping) error
type Container ¶
type Container struct { LIDMap *CachedLIDMap // contains filtered or unexported fields }
Container is a wrapper for a SQL database that can contain multiple whatsmeow sessions.
func New ¶
New connects to the given SQL database and wraps it in a Container.
Only SQLite and Postgres are currently fully supported.
The logger can be nil and will default to a no-op logger.
When using SQLite, it's strongly recommended to enable foreign keys by adding `?_foreign_keys=true`:
container, err := sqlstore.New(context.Background(), "sqlite3", "file:yoursqlitefile.db?_foreign_keys=on", nil)
func NewWithDB ¶
NewWithDB wraps an existing SQL connection in a Container.
Only SQLite and Postgres are currently fully supported.
The logger can be nil and will default to a no-op logger.
When using SQLite, it's strongly recommended to enable foreign keys by adding `?_foreign_keys=true`:
db, err := sql.Open("sqlite3", "file:yoursqlitefile.db?_foreign_keys=on") if err != nil { panic(err) } container := sqlstore.NewWithDB(db, "sqlite3", nil)
This method does not call Upgrade automatically like New does, so you must call it yourself:
container := sqlstore.NewWithDB(...) err := container.Upgrade()
func NewWithWrappedDB ¶
func (*Container) Close ¶
Close will close the container's database
func (*Container) DeleteDevice ¶
DeleteDevice deletes the given device from this database. This should be called through Device.Delete()
func (*Container) GetAllDevices ¶
GetAllDevices finds all the devices in the database.
func (*Container) GetDevice ¶
GetDevice finds the device with the specified JID in the database.
If the device is not found, nil is returned instead.
Note that the parameter usually must be an AD-JID.
func (*Container) GetFirstDevice ¶
GetFirstDevice is a convenience method for getting the first device in the store. If there are no devices, then a new device will be created. You should only use this if you don't want to have multiple sessions simultaneously.
func (*Container) NewDevice ¶
NewDevice creates a new device in this database.
No data is actually stored before Save is called. However, the pairing process will automatically call Save after a successful pairing, so you most likely don't need to call it yourself.
func (*Container) PutDevice ¶
PutDevice stores the given device in this database. This should be called through Device.Save() (which usually doesn't need to be called manually, as the library does that automatically when relevant).
func (*Container) Upgrade ¶
Upgrade upgrades the database from the current to the latest version available.
type SQLStore ¶
func NewSQLStore ¶
NewSQLStore creates a new SQLStore with the given database container and user JID. It contains implementations of all the different stores in the store package.
In general, you should use Container.NewDevice or Container.GetDevice instead of this.
func (*SQLStore) ClearBufferedEventPlaintext ¶
func (*SQLStore) DeleteAllIdentities ¶
func (*SQLStore) DeleteAllSessions ¶
func (*SQLStore) DeleteAppStateMutationMACs ¶
func (s *SQLStore) DeleteAppStateMutationMACs(ctx context.Context, name string, indexMACs [][]byte) (err error)
func (*SQLStore) DeleteAppStateVersion ¶
func (*SQLStore) DeleteIdentity ¶
func (*SQLStore) DeleteOldBufferedHashes ¶
func (*SQLStore) DeleteSession ¶
func (*SQLStore) DoDecryptionTxn ¶
func (*SQLStore) GenOnePreKey ¶
func (*SQLStore) GetAllContacts ¶
func (*SQLStore) GetAppStateMutationMAC ¶
func (s *SQLStore) GetAppStateMutationMAC(ctx context.Context, name string, indexMAC []byte) (valueMAC []byte, err error)
func (*SQLStore) GetAppStateSyncKey ¶
func (s *SQLStore) GetAppStateSyncKey(ctx context.Context, id []byte) (*store.AppStateSyncKey, error)
func (*SQLStore) GetAppStateVersion ¶
func (s *SQLStore) GetAppStateVersion(ctx context.Context, name string) (version uint64, hash [128]byte, err error)
func (*SQLStore) GetBufferedEvent ¶
func (s *SQLStore) GetBufferedEvent(ctx context.Context, ciphertextHash [32]byte) (*store.BufferedEvent, error)
func (*SQLStore) GetChatSettings ¶
func (s *SQLStore) GetChatSettings(ctx context.Context, chat types.JID) (settings types.LocalChatSettings, err error)
func (*SQLStore) GetContact ¶
func (*SQLStore) GetLatestAppStateSyncKeyID ¶
func (*SQLStore) GetMessageSecret ¶
func (s *SQLStore) GetMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID) (secret []byte, err error)
func (*SQLStore) GetOrGenPreKeys ¶
func (*SQLStore) GetPreKey ¶
func (*SQLStore) GetPrivacyToken ¶
func (s *SQLStore) GetPrivacyToken(ctx context.Context, user types.JID) (*store.PrivacyToken, error)
func (*SQLStore) GetSenderKey ¶
func (*SQLStore) GetSession ¶
func (*SQLStore) HasSession ¶
func (*SQLStore) IsTrustedIdentity ¶
func (s *SQLStore) IsTrustedIdentity(ctx context.Context, address string, key [32]byte) (bool, error)
func (*SQLStore) MarkPreKeysAsUploaded ¶
func (*SQLStore) MigratePNToLID ¶
func (*SQLStore) PutAllContactNames ¶
func (*SQLStore) PutAppStateMutationMACs ¶
func (s *SQLStore) PutAppStateMutationMACs(ctx context.Context, name string, version uint64, mutations []store.AppStateMutationMAC) error
func (*SQLStore) PutAppStateSyncKey ¶
func (s *SQLStore) PutAppStateSyncKey(ctx context.Context, id []byte, key store.AppStateSyncKey) error
func (*SQLStore) PutAppStateVersion ¶
func (s *SQLStore) PutAppStateVersion(ctx context.Context, name string, version uint64, hash [128]byte) error
func (*SQLStore) PutArchived ¶
func (*SQLStore) PutBufferedEvent ¶
func (s *SQLStore) PutBufferedEvent(ctx context.Context, ciphertextHash [32]byte, plaintext []byte, serverTimestamp time.Time) error
func (*SQLStore) PutBusinessName ¶
func (s *SQLStore) PutBusinessName(ctx context.Context, user types.JID, businessName string) (bool, string, error)
func (*SQLStore) PutContactName ¶
func (s *SQLStore) PutContactName(ctx context.Context, user types.JID, firstName, fullName string) error
func (*SQLStore) PutIdentity ¶
func (*SQLStore) PutMessageSecret ¶
func (s *SQLStore) PutMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID, secret []byte) (err error)
func (*SQLStore) PutMessageSecrets ¶
func (s *SQLStore) PutMessageSecrets(ctx context.Context, inserts []store.MessageSecretInsert) (err error)
func (*SQLStore) PutMutedUntil ¶
func (*SQLStore) PutPinned ¶
func (*SQLStore) PutPrivacyTokens ¶
func (*SQLStore) PutPushName ¶
func (s *SQLStore) PutPushName(ctx context.Context, user types.JID, pushName string) (bool, string, error)
func (*SQLStore) PutSenderKey ¶
func (*SQLStore) PutSession ¶
func (*SQLStore) RemovePreKey ¶
func (*SQLStore) UploadedPreKeyCount ¶
Source Files ¶
container.go lidmap.go store.go
Directories ¶
Path | Synopsis |
---|---|
store/sqlstore/upgrades |
- Version
- v0.0.0-20250527134344-0b502af800ee (latest)
- Published
- May 27, 2025
- Platform
- linux/amd64
- Imports
- 21 packages
- Last checked
- 6 days ago –
Tools for package owners.