cpd/lib/database/db.dart

34 lines
824 B
Dart
Raw Permalink Normal View History

import 'package:cpd/database/todo_db.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
import 'db_interface.dart';
class HabitDatabase implements HabitDbInterface{
2024-05-24 00:01:08 +02:00
late Database _database;
@override
2024-05-24 00:01:08 +02:00
Future<Database> get database async {
_database = await _initialize();
return _database;
}
Future<Database> _initialize() async {
final path = await fullPath;
var database = await openDatabase(
path,
version: 1,
onCreate: create,
singleInstance: true,
);
return database;
}
Future<void> create(Database database, int version) async => await TodoDB().createTable(database);
@override
Future<String> get fullPath async {
const name = 'habit.db';
final path = await getDatabasesPath();
return join(path, name);
}
}