Skip to main content

Database

Whixp uses the Hive database as a built-in approach to handle the primitive parts of the package with the local system.

Managing the stream resumption ID and saving this unique ID to the local database requires a local database solution. In addition to this ID, the user needs to save the last acknowledged stanzas, unacknowledged stanzas, and other properties related to this XEP. We will discuss what stream resumption is and why it is beneficial.

By default, this plugin is enabled in Whixp, and you cannot disable it now. Therefore, you need to declare the database path whether you are using this package in a Dart application or a Flutter application.

warning

If you forget to declare the database path, you will encounter an exception related to this error.

The exception will be similar to the one below:

Unhandled exception:
PathNotFoundException: Creation failed, path = '' (OS Error: No such file or directory, errno = 2)

To declare the path in the properties, you can assign any name you like to the internalDatabasePath parameter.

final whixp = Whixp(host: 'localhost', internalDatabasePath: 'anonymous');

This property behaves differently in a Flutter application. It would help if you retrieved the application's local path from the operating system. You can achieve this using packages such as path_provider or by creating the desired folder within the retrieved directory.

import 'package:path_provider/path_provider.dart';

late final io.Directory _currentDirectory;

void main() {
_currentDirectory = await getApplicationDocumentsDirectory();

final whixpPath = '${_currentDirectory.path}/example';

final whixp = Whixp(host: 'localhost', internalDatabasePath: whixpPath);
}