This repository has been archived on 2025-06-12. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Temperaturdecke/lib/db_test.dart
2024-05-20 19:31:26 +02:00

43 lines
1.2 KiB
Dart

import 'package:drift/drift.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';
import 'package:temperaturdecke/database.dart';
void addWool(BuildContext context, String title, String? manufacture,
Color color) async {
try {
AppDatabase db = Provider.of<AppDatabase>(context, listen: false);
print("adding wool");
db.into(db.wolle).insert(WolleCompanion.insert(
title: title,
color: color.value,
manufacture: manufacture ?? "none",
));
} catch (e) {
// Fehlerbehandlung hier
print('Fehler beim Einfügen: $e');
}
}
void removeWool(BuildContext context, int dId) async {
try {
AppDatabase db = Provider.of<AppDatabase>(context, listen: false);
(db.delete(db.wolle)..where((t) => t.id.isValue(dId))).go();
} catch (e) {
print('Fehler beim Einfügen: $e');
}
}
void deleteEverything(BuildContext context) async {
AppDatabase db = Provider.of<AppDatabase>(context, listen: false);
// you only need this if you've manually enabled foreign keys
// await customStatement('PRAGMA foreign_keys = OFF');
for (final table in db.allTables) {
await db.delete(table).go();
}
;
}