Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sqflite_sqlcipher support #602

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ As a consequence, it's necessary to have an understanding of SQL and SQLite in o
- typesafe
- reactive
- lightweight
- sqlcipher
- SQL centric
- no hidden magic
- no hidden costs
Expand Down Expand Up @@ -37,10 +38,11 @@ The third dependency is `build_runner` which has to be included as a dev depende
dependencies:
flutter:
sdk: flutter
floor: ^1.2.0
floor: ^1.2.0-sqlcipher
floor_annotation: 1.0.1-sqlcipher

dev_dependencies:
floor_generator: ^1.2.0
floor_generator: ^1.2.0-sqlcipher
build_runner: ^2.1.2
```

Expand Down Expand Up @@ -113,14 +115,14 @@ In this case, the file is named `database.dart`.
// required package imports
import 'dart:async';
import 'package:floor/floor.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:sqflite_sqlcipher/sqflite.dart' as sqflite;

import 'dao/person_dao.dart';
import 'entity/person.dart';

part 'database.g.dart'; // the generated code will be there

@Database(version: 1, entities: [Person])
@Database(version: 1, entities: [Person], password: '123456')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the user has to put the password inside the annotation always? Or is there an option to override this in a code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing the password in the annotation is an option. There is another option. Set the password when building the FloorDatabase object at run time.

Example:

final db = $FloorAppDatabase
    .databaseBuilder(
      /*name*/ 'app_database.db',
      /*password*/ '123456',
    )
    .build();

The priority of the password set at run time is higher than that written in the annotation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuuzed setting password in the annotation means that we have to use a constant for it. I think we should not allow this in order to avoid weak security problems.

abstract class AppDatabase extends FloorDatabase {
PersonDao get personDao;
}
Expand Down Expand Up @@ -165,13 +167,13 @@ For general communication use [floor's Slack](https://join.slack.com/t/floor-flu

## License
Copyright 2021 The Floor Project Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
4 changes: 2 additions & 2 deletions example/lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'dart:async';
import 'package:example/task.dart';
import 'package:example/task_dao.dart';
import 'package:floor/floor.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:sqflite_sqlcipher/sqflite.dart' as sqflite;

part 'database.g.dart';

@Database(version: 1, entities: [Task])
@Database(version: 1, entities: [Task], password: '123456')
abstract class FlutterDatabase extends FloorDatabase {
TaskDao get taskDao;
}
18 changes: 12 additions & 6 deletions example/lib/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading