init static method

Future<Database> init(
  1. String tableName
)

Opens the database and ensures tableName exists.

Implementation

static Future<Database> init(String tableName) async {
  final normalizedTableName = normalizeTableName(tableName);

  _database ??= await openDatabase(
    join(await getDatabasesPath(), 'flow_queue.db'),
    version: 1,
  );

  await _database!.execute('''
    CREATE TABLE IF NOT EXISTS $normalizedTableName (
      process_id TEXT PRIMARY KEY,
      parent_process_id TEXT,
      process_name TEXT NOT NULL,
      state TEXT NOT NULL,
      retry_count INTEGER DEFAULT 0,
      priority INTEGER NOT NULL,
      created_at INTEGER NOT NULL
    )
  ''');

  return _database!;
}