50 lines
1.3 KiB
Dart
50 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
import 'package:drift/drift.dart';
|
|
import 'package:drift_flutter/drift_flutter.dart';
|
|
|
|
import '../models/enums/temperature_mode.dart';
|
|
import 'database.steps.dart';
|
|
import 'tables/product.dart';
|
|
import 'tables/product_category.dart';
|
|
import 'tables/shopping_list_item.dart';
|
|
import 'tables/storage_location.dart';
|
|
import 'tables/users_table.dart';
|
|
|
|
part 'database.g.dart';
|
|
|
|
part 'crud/product_crud.dart';
|
|
part 'crud/product_category_crud.dart';
|
|
part 'crud/shopping_list_crud.dart';
|
|
part 'crud/storage_locations_crud.dart';
|
|
part 'crud/user_crud.dart';
|
|
|
|
@DriftDatabase(
|
|
tables: [ProductCategory, Product, ShoppingListItem, StorageLocation, User])
|
|
class AppDatabase extends _$AppDatabase {
|
|
AppDatabase() : super(_openConnection());
|
|
|
|
@override
|
|
int get schemaVersion => 2;
|
|
|
|
static QueryExecutor _openConnection() {
|
|
return driftDatabase(name: "groceries_manager_db");
|
|
}
|
|
|
|
@override
|
|
MigrationStrategy get migration {
|
|
return MigrationStrategy(
|
|
onUpgrade: stepByStep(
|
|
from1To2: (m, schema) async {
|
|
m.createTable(schema.user);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
extension BetterConversionStorageLocation on StorageLocationData {
|
|
TemperatureMode get temperatureModeE =>
|
|
TemperatureMode.fromName(temperatureMode);
|
|
}
|