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

feat(database): add initial firebase database #4

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion .github/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins:
firebase_core: ["tv-7.0"]
firebase_database: []
firebase_database: ["tv-7.0"]
firebase_storage: []
cloud_functions: []
3 changes: 3 additions & 0 deletions packages/firebase_database/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
BasedOnStyle: Google
---
30 changes: 30 additions & 0 deletions packages/firebase_database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
3 changes: 3 additions & 0 deletions packages/firebase_database/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release.
45 changes: 45 additions & 0 deletions packages/firebase_database/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
```
Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.

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.
See the License for the specific language governing permissions and
limitations under the License.
```

```
Copyright 2017 The Chromium Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
44 changes: 44 additions & 0 deletions packages/firebase_database/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# firebase_database_tizen

The [Firebase Database for Flutter](https://pub.dev/packages/firebase_database) implementation for Tizen.

It offers experimental features for using Firebase on Flutter for Tizen. It works by wrapping cross-compiled libraries that are based on the [Firebase C++ SDK](https://github.com/firebase/firebase-cpp-sdk) for Linux.

# Usage

To use this package, you need to include `firebase_database_tizen` as a dependency alongside `firebase_database` in your `pubspec.yaml`. Please note that `firebase_database_tizen` implementation is not officially endorsed for `firebase_database`.

```yaml
dependencies:
firebase_database: 10.0.9
Copy link
Member

Choose a reason for hiding this comment

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

There have been several discussions about fixing frontend package version.
How about adding comment to Limitations to reduce user error?
"Compatibility not guaranteed with versions other than 10.0.0 of the firebase_database package."

This can also be applied to any package that pin a version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, that's not a good idea because the breaking backward-compatibility in their interface packages is not our fault. The wording could imply that minor updates are not allowed due to our limitations.

firebase_database_tizen: ^0.1.0
```

Then you can import `firebase_database` in your Dart code:

```dart
import 'package:firebase_database/firebase_database.dart';
```

## Required privileges

To use this plugin in a Tizen application, you may need to declare the following privileges in your `tizen-manifest.xml` file.

```xml
<privileges>
<privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
```

- `http://tizen.org/privilege/internet` allows the application to access the Internet.

For the details on Tizen privileges, please see [Tizen Docs: API Privileges](https://docs.tizen.org/application/dotnet/get-started/api-privileges).


# Limitations

The following features are currently unavailable as they're not supported by the version of Firebase C++ SDK for Linux that this plugin is currently based on.

- Using Firebase Local Emulator Suite.
- Using `FirebaseDatabase#setPersistenceCacheSizeBytes()` for the on-disk data.
- Using `Query#startAfter()` or `Query#endBefore()` method to add a cursor to a query.
5 changes: 5 additions & 0 deletions packages/firebase_database/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: ../../analysis_options.yaml

linter:
rules:
public_member_api_docs: true
38 changes: 38 additions & 0 deletions packages/firebase_database/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# VS Code related
.vscode/

# Flutter/Dart/Pub related
/pubspec.lock
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json
4 changes: 4 additions & 0 deletions packages/firebase_database/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Example

A test app for firebase_database_tizen plugin (e2e).

5 changes: 5 additions & 0 deletions packages/firebase_database/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# in the LICENSE file.

include: ../analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2022, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:firebase_database/firebase_database.dart';
import 'package:flutter_test/flutter_test.dart';

void setupDataSnapshotTests() {
group('DataSnapshot', () {
late DatabaseReference ref;

setUp(() async {
ref = FirebaseDatabase.instance.ref('tests');

// Wipe the database before each test
await ref.remove();
});

test('it returns the correct key', () async {
final s = await ref.get();
expect(s.key, 'tests');
});

test('it returns a string value', () async {
await ref.set('foo');
final s = await ref.get();
expect(s.value, 'foo');
});

test('it returns a number value', () async {
await ref.set(123);
final s = await ref.get();
expect(s.value, 123);
});

test('it returns a bool value', () async {
await ref.set(false);
final s = await ref.get();
expect(s.value, false);
});

test('it returns a null value', () async {
await ref.set(null);
final s = await ref.get();
expect(s.value, isNull);
});

test('it returns a List value', () async {
final data = [
'a',
2,
true,
['foo'],
{
0: 'hello',
1: 'foo',
}
];
await ref.set(data);
final s = await ref.get();
expect(
s.value,
equals([
'a',
2,
true,
['foo'],
['hello', 'foo']
]),
);
});

test('it returns a Map value', () async {
final data = {'foo': 'bar'};
await ref.set(data);
final s = await ref.get();
expect(s.value, equals(data));
});

test('non-string Map keys are converted to strings', () async {
final data = {1: 'foo', 2: 'bar', 'foo': 'bar'};
await ref.set(data);
final s = await ref.get();
expect(s.value, equals({'1': 'foo', '2': 'bar', 'foo': 'bar'}));
});

test('setWithPriority returns the correct priority', () async {
await ref.setWithPriority('foo', 1);
final s = await ref.get();
expect(s.priority, 1);
});

test('setPriority returns the correct priority', () async {
await ref.set('foo');
await ref.setPriority(2);
final s = await ref.get();
expect(s.priority, 2);
});

test('exists returns true', () async {
await ref.set('foo');
final s = await ref.get();
expect(s.exists, isTrue);
});

test('exists returns false', () async {
final s = await ref.get();
expect(s.exists, isFalse);
});

test('hasChild returns false', () async {
final s = await ref.get();
expect(s.hasChild('bar'), isFalse);
});

test('hasChild returns true', () async {
await ref.set({
'foo': {'bar': 'baz'}
});
final s = await ref.get();
expect(s.hasChild('bar'), isFalse);
});

test('child returns the correct snapshot for lists', () async {
await ref.set([0, 1]);
final s = await ref.get();
expect(s.child('1'), isA<DataSnapshot>());
expect(s.child('1').value, 1);
});

test('child returns the correct snapshot', () async {
await ref.set({
'foo': {'bar': 'baz'}
});
final s = await ref.get();
expect(s.child('foo/bar'), isA<DataSnapshot>());
expect(s.child('foo/bar').value, 'baz');
});

test('children returns the children in order', () async {
await ref.set({
'a': 3,
'b': 2,
'c': 1,
});
final s = await ref.orderByValue().get();

List<DataSnapshot> children = s.children.toList();
expect(children[0].value, 1);
expect(children[1].value, 2);
expect(children[2].value, 3);
});
});
}
Loading