init static method

Future<Box> init(
  1. String boxName
)

Initializes a new graph database box with the specified name.

The database will be stored in the application's documents directory with the provided boxName. If a database with this name already exists, it will be opened; otherwise, a new database will be created.

Throws an Exception if the database initialization fails.

Example:

final box = await Box.init('my_graph');

Implementation

static Future<Box> init(String boxName) async {
  final dir = await getApplicationDocumentsDirectory();
  final dbPath = '${dir.path}/$boxName';

  final dbPathPtr = dbPath.toNativeUtf8().cast<ffi.Char>();

  final bindings = gdb.GraphDbBindings(_dylib);

  final handle = bindings.graphdb_init(dbPathPtr);

  malloc.free(dbPathPtr);

  if (handle == ffi.nullptr) {
    throw Exception('Failed to initialize GraphDB at path $dbPath');
  }
  return Box._(bindings, handle);
}