From ad12b584c89ec594eb3617a998d86ae895413e08 Mon Sep 17 00:00:00 2001 From: Lucas Didur Date: Wed, 3 Apr 2024 12:05:08 -0300 Subject: [PATCH 1/3] feat: add external path suport --- floor/lib/src/sqflite_database_factory.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/floor/lib/src/sqflite_database_factory.dart b/floor/lib/src/sqflite_database_factory.dart index 65aa0614..dc7d02b1 100644 --- a/floor/lib/src/sqflite_database_factory.dart +++ b/floor/lib/src/sqflite_database_factory.dart @@ -19,7 +19,15 @@ final DatabaseFactory sqfliteDatabaseFactory = () { extension DatabaseFactoryExtension on DatabaseFactory { Future getDatabasePath(final String name) async { - final databasesPath = await this.getDatabasesPath(); - return join(databasesPath, name); + late String databasesPath; + + final file = File(name); + if (file.isAbsolute) { + databasesPath = file.path; + } else { + databasesPath = join(await this.getDatabasesPath(), name); + } + + return databasesPath; } } From 342fca1b30b4acb4ac87ca3ec9b13ccd9c67b5a8 Mon Sep 17 00:00:00 2001 From: Lucas Didur Date: Wed, 3 Apr 2024 16:14:02 -0300 Subject: [PATCH 2/3] refactor --- floor/lib/src/sqflite_database_factory.dart | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/floor/lib/src/sqflite_database_factory.dart b/floor/lib/src/sqflite_database_factory.dart index dc7d02b1..876d68b7 100644 --- a/floor/lib/src/sqflite_database_factory.dart +++ b/floor/lib/src/sqflite_database_factory.dart @@ -18,16 +18,17 @@ final DatabaseFactory sqfliteDatabaseFactory = () { }(); extension DatabaseFactoryExtension on DatabaseFactory { - Future getDatabasePath(final String name) async { - late String databasesPath; + Future getDatabasePath(final String name, {String? path}) async { + if(path == null){ + path = await this.getDatabasesPath(); + } + + var dir= Directory(path); - final file = File(name); - if (file.isAbsolute) { - databasesPath = file.path; - } else { - databasesPath = join(await this.getDatabasesPath(), name); + if (!dir.existsSync()) { + dir.create(recursive: true); } - return databasesPath; + return join(dir.path, name); } } From b18caee8a95333ab67c004e0005d6a759b048747 Mon Sep 17 00:00:00 2001 From: Lucas Didur Date: Wed, 3 Apr 2024 16:27:14 -0300 Subject: [PATCH 3/3] refactor --- floor/lib/src/sqflite_database_factory.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/floor/lib/src/sqflite_database_factory.dart b/floor/lib/src/sqflite_database_factory.dart index 876d68b7..dc7d02b1 100644 --- a/floor/lib/src/sqflite_database_factory.dart +++ b/floor/lib/src/sqflite_database_factory.dart @@ -18,17 +18,16 @@ final DatabaseFactory sqfliteDatabaseFactory = () { }(); extension DatabaseFactoryExtension on DatabaseFactory { - Future getDatabasePath(final String name, {String? path}) async { - if(path == null){ - path = await this.getDatabasesPath(); - } - - var dir= Directory(path); + Future getDatabasePath(final String name) async { + late String databasesPath; - if (!dir.existsSync()) { - dir.create(recursive: true); + final file = File(name); + if (file.isAbsolute) { + databasesPath = file.path; + } else { + databasesPath = join(await this.getDatabasesPath(), name); } - return join(dir.path, name); + return databasesPath; } }