Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

  1. import 'dart:async';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:path/path.dart';
  4. import 'package:sqflite/sqflite.dart';
  5. Future<Database> getDatabaseConnection() async {
  6. WidgetsFlutterBinding.ensureInitialized();
  7. final database = openDatabase(
  8. // Set the path to the database. Note: Using the `join` function from the
  9. // `path` package is best practice to ensure the path is correctly
  10. // constructed for each platform.
  11. join(await getDatabasesPath(), 'envelope.db'),
  12. // When the database is first created, create a table to store dogs.
  13. onCreate: (db, version) {
  14. // Run the CREATE TABLE statement on the database.
  15. return db.execute(
  16. '''
  17. CREATE TABLE IF NOT EXISTS friends(
  18. id BLOB PRIMARY KEY,
  19. user_id BLOB,
  20. friend_id BLOB,
  21. friend_id_decrypted BLOB,
  22. accepted_at TEXT
  23. );
  24. ''',
  25. );
  26. },
  27. // Set the version. This executes the onCreate function and provides a
  28. // path to perform database upgrades and downgrades.
  29. version: 1,
  30. );
  31. return database;
  32. }