Skip to content

Add WEB-support for CoreStoreSembastImp #436

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

Merged
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ await Parse().initialize(
```

If you want to use secure storage or use the Flutter web/desktop SDK, please change to the below instance of CoreStorage as it has no dependencies on Flutter.

**The `CoreStoreSembastImp` does not encrypt the data!** (Web is not safe anyway. Encrypt fields manually as needed.)
```dart

await Parse().initialize(
Expand Down
1 change: 1 addition & 0 deletions lib/parse_server_sdk_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:parse_server_sdk/src/network/parse_websocket.dart'
import 'package:path/path.dart' as path;
import 'package:sembast/sembast.dart';
import 'package:sembast/sembast_io.dart';
import 'package:sembast_web/sembast_web.dart';
import 'package:uuid/uuid.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:xxtea/xxtea.dart';
Expand Down
13 changes: 10 additions & 3 deletions lib/src/storage/core_store_sem_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ class CoreStoreSembastImp implements CoreStore {
static Future<CoreStore> getInstance(String dbPath,
{DatabaseFactory factory, String password = 'flutter_sdk'}) async {
if (_instance == null) {
factory ??= databaseFactoryIo;
final SembastCodec codec = getXXTeaSembastCodec(password: password);
final Database db = await factory.openDatabase(dbPath, codec: codec);
factory ??= !parseIsWeb ? databaseFactoryIo : databaseFactoryWeb;
assert(() {
if (parseIsWeb) {
print(
'Warning: CoreStoreSembastImp of the Parse_Server_SDK does not encrypt the database on WEB.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this on stackoverflow.
I have to remember this trick, it's super useful.

}
return true;
}());
final Database db = await factory.openDatabase(dbPath,
codec: !parseIsWeb ? getXXTeaSembastCodec(password: password) : null);
_instance =
CoreStoreSembastImp._internal(db, StoreRef<String, String>.main());
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:

#Database
sembast: ^2.4.7+6
sembast_web: '>=1.0.0'
xxtea: ^2.0.3
shared_preferences: ^0.5.10 # only used in the flutter part

Expand Down