create static method

Future<PagedTable> create(
  1. String basePath, {
  2. required List<PagedColumn> columns,
  3. required String primaryKey,
  4. int pageSize = 4096,
  5. int cacheCapacity = 64,
})

Create a brand-new paged table. Refuses to overwrite an existing <basePath>.meta.json.

Implementation

static Future<PagedTable> create(
  String basePath, {
  required List<PagedColumn> columns,
  required String primaryKey,
  int pageSize = 4096,
  int cacheCapacity = 64,
}) async {
  final pkIdx = columns.indexWhere((c) => c.name == primaryKey);
  if (pkIdx < 0) {
    throw ArgumentError.value(
        primaryKey, 'primaryKey', 'not found in columns');
  }
  final metaFile = File('$basePath.meta.json');
  if (await metaFile.exists()) {
    throw StateError(
        'PagedTable: metadata already exists at ${metaFile.path}');
  }
  // Write schema first so a crash before any heap/index writes leaves
  // a recoverable empty table.
  await _writeMeta(basePath, columns, pkIdx, const [], pageSize: pageSize);
  return _openWith(basePath, columns, pkIdx, const [],
      pageSize: pageSize, cacheCapacity: cacheCapacity);
}