Skip to content

Commit bd9aaf6

Browse files
committed
implement more queries and add example
1 parent aa8398d commit bd9aaf6

File tree

10 files changed

+513
-81
lines changed

10 files changed

+513
-81
lines changed

flutter/example/lib/main.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import 'package:flutter/material.dart';
88
import 'package:flutter/services.dart';
99
import 'package:logging/logging.dart';
1010
import 'package:sentry_flutter/sentry_flutter.dart';
11+
import 'package:sentry_sqflite/sentry_sqflite.dart';
12+
import 'package:sqflite/sqflite.dart';
1113
import 'package:universal_platform/universal_platform.dart';
1214
import 'package:feedback/feedback.dart' as feedback;
1315
import 'package:provider/provider.dart';
1416
import 'user_feedback_dialog.dart';
1517
import 'package:dio/dio.dart';
1618
import 'package:sentry_dio/sentry_dio.dart';
1719
import 'package:sentry_logging/sentry_logging.dart';
20+
// import 'package:sqflite_common_ffi/sqflite_ffi.dart';
1821

1922
// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
2023
const String _exampleDsn =
@@ -35,6 +38,7 @@ Future<void> main() async {
3538
),
3639
),
3740
_exampleDsn);
41+
databaseFactory = SentrySqfliteDatabaseFactoryMixin();
3842
}
3943

4044
Future<void> setupSentry(AppRunner appRunner, String dsn) async {
@@ -51,6 +55,7 @@ Future<void> setupSentry(AppRunner appRunner, String dsn) async {
5155
options.reportSilentFlutterErrors = true;
5256
options.attachScreenshot = true;
5357
options.attachViewHierarchy = true;
58+
options.environment = 'dev';
5459
// We can enable Sentry debug logging during development. This is likely
5560
// going to log too much for your app, but can be useful when figuring out
5661
// configuration issues, e.g. finding out why your events are not uploaded.
@@ -132,6 +137,10 @@ class MainScaffold extends StatelessWidget {
132137
child: Column(
133138
children: [
134139
const Center(child: Text('Trigger an action:\n')),
140+
ElevatedButton(
141+
onPressed: () => sqfliteTest(),
142+
child: const Text('sqflite'),
143+
),
135144
ElevatedButton(
136145
onPressed: () => SecondaryScaffold.openSecondaryScaffold(context),
137146
child: const Text('Open another Scaffold'),
@@ -393,6 +402,38 @@ class MainScaffold extends StatelessWidget {
393402
),
394403
);
395404
}
405+
406+
Future<void> sqfliteTest() async {
407+
// sqfliteFfiInit();
408+
// databaseFactory = databaseFactoryFfi;
409+
// databaseFactory = SentryDatabaseFactory(databaseFactoryFfi);
410+
// databaseFactory = SentrySqfliteDatabaseFactoryMixin();
411+
412+
final tr = Sentry.startTransaction(
413+
'sqfliteTest',
414+
'db',
415+
bindToScope: true,
416+
);
417+
418+
var db = await openDatabase(inMemoryDatabasePath);
419+
await db.execute('''
420+
CREATE TABLE Product (
421+
id INTEGER PRIMARY KEY,
422+
title TEXT
423+
)
424+
''');
425+
for (int i = 1; i <= 20; i++) {
426+
await db.insert('Product', <String, Object?>{'title': 'Product $i'});
427+
}
428+
429+
await db.query('Product');
430+
431+
await db.delete('Product', where: 'title = ?', whereArgs: ['Product 1']);
432+
433+
await db.close();
434+
435+
await tr.finish(status: const SpanStatus.ok());
436+
}
396437
}
397438

398439
extension BuildContextExtension on BuildContext {

flutter/example/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ dependencies:
1515
sentry_flutter:
1616
sentry_dio:
1717
sentry_logging:
18+
sentry_sqflite:
1819
universal_platform: ^1.0.0
1920
feedback: ^2.0.0
2021
provider: ^6.0.0
2122
dio: any # This gets constrained by `sentry_dio`
2223
logging: ^1.0.0
24+
sqflite: any
25+
sqflite_common_ffi: ^2.0.0
2326
package_info_plus: ^3.0.0
2427
path_provider: ^2.0.0
2528

flutter/example/pubspec_overrides.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ dependency_overrides:
77
path: ../../dio
88
sentry_logging:
99
path: ../../logging
10+
sentry_sqflite:
11+
path: ../../sqflite

min_version_test/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ dependencies:
3232
sentry_flutter:
3333
sentry_dio:
3434
sentry_logging:
35-
sentry_sqflite:
35+
#sentry_sqflite:
3636
dio: any # This gets constrained by `sentry_dio`
3737
logging: ^1.0.0
38-
sqflite: any # This gets constrained by `sentry_sqflite`
38+
#sqflite: any # This gets constrained by `sentry_sqflite`
3939

4040
dev_dependencies:
4141
flutter_test:
@@ -52,8 +52,8 @@ dependency_overrides:
5252
path: ../dio
5353
sentry_logging:
5454
path: ../logging
55-
sentry_sqflite:
56-
path: ../sqflite
55+
#sentry_sqflite:
56+
# path: ../sqflite
5757

5858
# For information on the generic Dart part of this file, see the
5959
# following page: https://dart.dev/tools/pub/pubspec

sqflite/example/example.dart

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import 'package:sentry/sentry.dart';
2+
import 'package:sqflite_common/sqlite_api.dart';
3+
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
4+
import 'package:sqflite/sqflite.dart';
25

36
Future<void> main() async {
47
// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
@@ -17,18 +20,24 @@ Future<void> main() async {
1720
}
1821

1922
Future<void> runApp() async {
20-
final transaction = Sentry.startTransaction(
21-
'sqflite-query',
22-
'db',
23-
bindToScope: true,
24-
);
23+
sqfliteFfiInit();
24+
// final defaultFactory = databaseFactory;
25+
databaseFactory = SentrySqfliteDatabaseFactory(databaseFactoryFfi)
2526

26-
try {} catch (exception) {
27-
transaction.throwable = exception;
28-
transaction.status = const SpanStatus.internalError();
29-
} finally {
30-
await transaction.finish();
31-
}
27+
var db = await openDatabase(inMemoryDatabasePath);
28+
await db.execute('''
29+
CREATE TABLE Product (
30+
id INTEGER PRIMARY KEY,
31+
title TEXT
32+
)
33+
''');
34+
await db.insert('Product', <String, Object?>{'title': 'Product 1'});
35+
await db.insert('Product', <String, Object?>{'title': 'Product 2'});
3236

33-
await Sentry.close();
37+
var result = await db.query('Product');
38+
expect(result, [
39+
{'id': 1, 'title': 'Product 1'},
40+
{'id': 2, 'title': 'Product 2'}
41+
]);
42+
await db.close();
3443
}

sqflite/lib/sentry_sqflite.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ library sentry_sqflite;
22

33
export 'src/sentry_database.dart';
44
export 'src/sentry_sqflite.dart';
5+
export 'src/sentry_sqflite_database_factory.dart';

0 commit comments

Comments
 (0)