From 94e315c845f9301176c6812ff851b73f1b6d30f4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 4 Sep 2024 08:58:30 -0500 Subject: [PATCH] open database --- mobile/lib/main.dart | 2 ++ mobile/lib/utils/sqlite.dart | 22 ++++++++++++++++++++++ mobile/pubspec.lock | 2 +- mobile/pubspec.yaml | 3 ++- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 mobile/lib/utils/sqlite.dart diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index dc1df746cb..0bd51c9b3a 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -9,6 +9,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_displaymode/flutter_displaymode.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/extensions/build_context_extensions.dart'; +import 'package:immich_mobile/utils/sqlite.dart'; import 'package:timezone/data/latest.dart'; import 'package:immich_mobile/constants/locales.dart'; import 'package:immich_mobile/services/background.service.dart'; @@ -54,6 +55,7 @@ void main() async { Future initApp() async { await EasyLocalization.ensureInitialized(); + await openSqliteDatabase(); if (kReleaseMode && Platform.isAndroid) { try { diff --git a/mobile/lib/utils/sqlite.dart b/mobile/lib/utils/sqlite.dart new file mode 100644 index 0000000000..c08924ba86 --- /dev/null +++ b/mobile/lib/utils/sqlite.dart @@ -0,0 +1,22 @@ +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; + +Future openSqliteDatabase() async { + final database = openDatabase( + // Set the path to the database. Note: Using the `join` function from the + // `path` package is best practice to ensure the path is correctly + // constructed for each platform. + join(await getDatabasesPath(), 'immich_database.db'), + + // When the database is first created, create a table to store dogs. + onCreate: (db, version) { + // Run the CREATE TABLE statement on the database. + return db.execute( + 'CREATE TABLE dogs(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)', + ); + }, + // Set the version. This executes the onCreate function and provides a + // path to perform database upgrades and downgrades. + version: 1, + ); +} diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock index 14b487ce4d..1b93bf6f97 100644 --- a/mobile/pubspec.lock +++ b/mobile/pubspec.lock @@ -1454,7 +1454,7 @@ packages: source: hosted version: "7.0.0" sqflite: - dependency: transitive + dependency: "direct main" description: name: sqflite sha256: a43e5a27235518c03ca238e7b4732cf35eabe863a369ceba6cbefa537a66f16d diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index 728b90c3f3..4643a9dfa9 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -38,7 +38,7 @@ dependencies: share_plus: ^10.0.0 flutter_displaymode: ^0.6.0 scrollable_positioned_list: ^0.3.8 - path: ^1.8.3 + path: ^1.9.0 path_provider: ^2.1.2 collection: ^1.18.0 http_parser: ^4.0.2 @@ -67,6 +67,7 @@ dependencies: image_picker: ^1.0.7 # only used to select user profile image from system gallery -> we can simply select an image from within immich? logging: ^1.2.0 file_picker: ^8.0.0+1 + sqflite: ^2.3.3+1 # This is uncommented in F-Droid build script # Taken from https://github.com/Myzel394/locus/blob/445013d22ec1d759027d4303bd65b30c5c8588c8/pubspec.yaml#L105