addTable method Null safety
- String tableName,
- {DatabaseItem? item}
Adds a table to the database
Implementation
Future<void> addTable(String tableName, {DatabaseItem? item}) async {
await ensureDbOpen();
final itemSchema = {
'id': 'STRING PRIMARY KEY',
if (item != null) ...item.schema
};
List<String> columns = [];
itemSchema.forEach((key, value) {
columns.add('$key $value');
});
final sql = 'CREATE TABLE IF NOT EXISTS $tableName(${columns.join(',')})';
await db.execute(sql);
updateTableSchema(tableName, itemSchema.keys.toList());
}