open static method

Future<Database> open([
  1. String? path
])

Implementation

static Future<Database> open([String? path]) async {
  final db = Database(path: path);
  if (path != null) {
    // Acquire the cross-process file lock before touching the file.
    db._fileLock = DbFileLock(path);
    await db._fileLock!.acquire();
    // Reap any half-written temp files left behind by a crashed
    // writer (sibling `<path>.tmp` / `<path>-wal.tmp`).
    await db._reapStaleTempFiles();
    if (await File(path).exists()) {
      await db._load();
    } else {
      // Fresh file: pick the persist format from the extension.
      final lower = path.toLowerCase();
      if (lower.endsWith('.sqlite') ||
          lower.endsWith('.sqlite3') ||
          lower.endsWith('.db')) {
        db._persistAsSqlite = true;
      }
    }
    // Compute paged-table directory: strip a single known extension.
    db._pagedDir = _derivePagedDir(path);
    await db._restorePagedTables();
  }
  return db;
}