Documentation ¶
Overview ¶
Package sqlstore contains an SQL-backed implementation of the interfaces in the store package.
Index ¶
- Variables
- type Container
- func (c *Container) Close() error
- func (c *Container) DeleteDevice(store *store.Device) error
- func (c *Container) GetAllDevices() ([]*store.Device, error)
- func (c *Container) GetDevice(jid types.JID) (*store.Device, error)
- func (c *Container) GetFirstDevice() (*store.Device, error)
- func (c *Container) NewDevice() *store.Device
- func (c *Container) PutDevice(device *store.Device) error
- func (c *Container) Upgrade() error
- type SQLStore
- func (s *SQLStore) DeleteAllIdentities(phone string) error
- func (s *SQLStore) DeleteAllSessions(phone string) error
- func (s *SQLStore) DeleteAppStateMutationMACs(name string, indexMACs [][]byte) (err error)
- func (s *SQLStore) DeleteAppStateVersion(name string) error
- func (s *SQLStore) DeleteIdentity(address string) error
- func (s *SQLStore) DeleteSession(address string) error
- func (s *SQLStore) GenOnePreKey() (*keys.PreKey, error)
- func (s *SQLStore) GetAllContacts() (map[types.JID]types.ContactInfo, error)
- func (s *SQLStore) GetAppStateMutationMAC(name string, indexMAC []byte) (valueMAC []byte, err error)
- func (s *SQLStore) GetAppStateSyncKey(id []byte) (*store.AppStateSyncKey, error)
- func (s *SQLStore) GetAppStateVersion(name string) (version uint64, hash [128]byte, err error)
- func (s *SQLStore) GetChatSettings(chat types.JID) (settings types.LocalChatSettings, err error)
- func (s *SQLStore) GetContact(user types.JID) (types.ContactInfo, error)
- func (s *SQLStore) GetLatestAppStateSyncKeyID() ([]byte, error)
- func (s *SQLStore) GetMessageSecret(chat, sender types.JID, id types.MessageID) (secret []byte, err error)
- func (s *SQLStore) GetOrGenPreKeys(count uint32) ([]*keys.PreKey, error)
- func (s *SQLStore) GetPreKey(id uint32) (*keys.PreKey, error)
- func (s *SQLStore) GetPrivacyToken(user types.JID) (*store.PrivacyToken, error)
- func (s *SQLStore) GetSenderKey(group, user string) (key []byte, err error)
- func (s *SQLStore) GetSession(address string) (session []byte, err error)
- func (s *SQLStore) HasSession(address string) (has bool, err error)
- func (s *SQLStore) IsTrustedIdentity(address string, key [32]byte) (bool, error)
- func (s *SQLStore) MarkPreKeysAsUploaded(upToID uint32) error
- func (s *SQLStore) PutAllContactNames(contacts []store.ContactEntry) error
- func (s *SQLStore) PutAppStateMutationMACs(name string, version uint64, mutations []store.AppStateMutationMAC) error
- func (s *SQLStore) PutAppStateSyncKey(id []byte, key store.AppStateSyncKey) error
- func (s *SQLStore) PutAppStateVersion(name string, version uint64, hash [128]byte) error
- func (s *SQLStore) PutArchived(chat types.JID, archived bool) error
- func (s *SQLStore) PutBusinessName(user types.JID, businessName string) (bool, string, error)
- func (s *SQLStore) PutContactName(user types.JID, firstName, fullName string) error
- func (s *SQLStore) PutIdentity(address string, key [32]byte) error
- func (s *SQLStore) PutMessageSecret(chat, sender types.JID, id types.MessageID, secret []byte) (err error)
- func (s *SQLStore) PutMessageSecrets(inserts []store.MessageSecretInsert) (err error)
- func (s *SQLStore) PutMutedUntil(chat types.JID, mutedUntil time.Time) error
- func (s *SQLStore) PutPinned(chat types.JID, pinned bool) error
- func (s *SQLStore) PutPrivacyTokens(tokens ...store.PrivacyToken) error
- func (s *SQLStore) PutPushName(user types.JID, pushName string) (bool, string, error)
- func (s *SQLStore) PutSenderKey(group, user string, session []byte) error
- func (s *SQLStore) PutSession(address string, session []byte) error
- func (s *SQLStore) RemovePreKey(id uint32) error
- func (s *SQLStore) UploadedPreKeyCount() (count int, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrDeviceIDMustBeSet = errors.New("device JID must be known before accessing database")
ErrDeviceIDMustBeSet is the error returned by PutDevice if you try to save a device before knowing its JID.
var ErrInvalidLength = errors.New("database returned byte array with illegal length")
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.
var PostgresArrayWrapper func(interface{}) interface { driver.Valuer sql.Scanner }
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
var Upgrades = [...]upgradeFunc{upgradeV1, upgradeV2, upgradeV3, upgradeV4, upgradeV5, upgradeV6}
Upgrades is a list of functions that will upgrade a database to the latest version.
This may be of use if you want to manage the database fully manually, but in most cases you should just call Container.Upgrade to let the library handle everything.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct { DatabaseErrorHandler func(device *store.Device, action string, attemptIndex int, err error) (retry bool) // 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("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 (*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.
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) DeleteAllIdentities ¶
func (*SQLStore) DeleteAllSessions ¶
func (*SQLStore) DeleteAppStateMutationMACs ¶
func (*SQLStore) DeleteAppStateVersion ¶
func (*SQLStore) DeleteIdentity ¶
func (*SQLStore) DeleteSession ¶
func (*SQLStore) GetAllContacts ¶
func (*SQLStore) GetAppStateMutationMAC ¶
func (*SQLStore) GetAppStateSyncKey ¶
func (s *SQLStore) GetAppStateSyncKey(id []byte) (*store.AppStateSyncKey, error)
func (*SQLStore) GetAppStateVersion ¶
func (*SQLStore) GetChatSettings ¶
func (*SQLStore) GetContact ¶
func (*SQLStore) GetLatestAppStateSyncKeyID ¶
func (*SQLStore) GetMessageSecret ¶
func (*SQLStore) GetOrGenPreKeys ¶
func (*SQLStore) GetPrivacyToken ¶
func (*SQLStore) GetSenderKey ¶
func (*SQLStore) GetSession ¶
func (*SQLStore) IsTrustedIdentity ¶
func (*SQLStore) MarkPreKeysAsUploaded ¶
func (*SQLStore) PutAllContactNames ¶
func (s *SQLStore) PutAllContactNames(contacts []store.ContactEntry) error
func (*SQLStore) PutAppStateMutationMACs ¶
func (*SQLStore) PutAppStateSyncKey ¶
func (s *SQLStore) PutAppStateSyncKey(id []byte, key store.AppStateSyncKey) error
func (*SQLStore) PutAppStateVersion ¶
func (*SQLStore) PutBusinessName ¶
func (*SQLStore) PutContactName ¶
func (*SQLStore) PutMessageSecret ¶
func (*SQLStore) PutMessageSecrets ¶
func (s *SQLStore) PutMessageSecrets(inserts []store.MessageSecretInsert) (err error)
func (*SQLStore) PutMutedUntil ¶
func (*SQLStore) PutPrivacyTokens ¶
func (s *SQLStore) PutPrivacyTokens(tokens ...store.PrivacyToken) error