Flutter
在使用中为数据库创建表之前如何检查数据库是否存在sqflite
?
例如,如果我要创建数据库doggie_database.db
,如何在创建表时过早地检查它的存在?
final Future<Database> database = openDatabase(
// Set the path to the database.
join(await getDatabasesPath(), 'doggie_database.db'),
// When the database is first created, create a table to store dogs.
onCreate: (db, version) {
// Run the CREATE TABLE statement on the database.
return db.execute(
"CREATE TABLE dogs(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)",
);
},
// Set the version. This executes the onCreate function and provides a
// path to perform database upgrades and downgrades.
version: 1,
);