Skip to content

Commit 4c91830

Browse files
buenaflorbitsandfoxes
authored andcommitted
flutter v9: update drift (#13495)
Closes getsentry/sentry-dart#2782 Should only be merged once Flutter v9 is GA
1 parent 79e33b2 commit 4c91830

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

includes/dart-integrations/drift-instrumentation.mdx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ platforms:
1010
- flutter
1111
---
1212

13-
<Include name="feature-stage-beta.mdx" />
14-
15-
_(New in version 7.13.1)_
16-
1713
Drift is a library for easily managing SQLite databases within Flutter applications.
1814
The [sentry_drift](https://pub.dev/packages/sentry_drift) package provides `Drift` support for database performance instrumentation and allows you to track the performance of your queries.
1915

@@ -34,23 +30,30 @@ Add the `sentry_drift` dependency to install the Drift database instrumentation.
3430

3531
```yml {filename:pubspec.yaml}
3632
dependencies:
37-
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter', '7.13.1') }}
38-
sentry_drift: ^{{@inject packages.version('sentry.dart.drift', '7.13.1') }}
33+
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter', '9.0.0') }}
34+
sentry_drift: ^{{@inject packages.version('sentry.dart.drift', '9.0.0') }}
3935
```
4036
41-
## Configure
37+
## Setup
4238
43-
Inject `SentryQueryExecutor` into a `Drift` database instance:
39+
Add the `SentryQueryInterceptor` to a `QueryExecutor` or `DatabaseConnection`.
40+
Read the [Drift documentation](https://drift.simonbinder.eu/examples/tracing/) for more information on how to use interceptors in Drift.
4441

45-
```dart
46-
import 'package:drift/native.dart';
47-
import 'package:sentry_drift/sentry_drift.dart';
42+
```dart {tabTitle: 'QueryExecutor'}
43+
final interceptor = SentryQueryInterceptor(databaseName: 'my_database_name');
44+
final executor = inMemoryExecutor().interceptWith(interceptor);
45+
46+
// AppDatabase is an example of the auto-generated database class by Drift.
47+
final database = AppDatabase(executor);
48+
```
4849

49-
final executor = SentryQueryExecutor(
50-
() => NativeDatabase.memory(), // You can also provide your own database opener
51-
databaseName: 'my_db_name',
52-
);
53-
final database = AppDatabase(executor); // AppDatabase is an example of the auto-generated database class by Drift.
50+
```dart {tabTitle: 'DatabaseConnection'}
51+
final interceptor = SentryQueryInterceptor(databaseName: 'my_database_name');
52+
// AppDatabase is an example of the auto-generated database class by Drift.
53+
final database = AppDatabase(inMemoryExecutor());
54+
await database.runWithInterceptor(interceptor: interceptor, () async {
55+
// Only database operations in this block will reach the interceptor.
56+
});
5457
```
5558

5659
## Verify
@@ -71,10 +74,8 @@ Future<void> driftTest() async {
7174
'op',
7275
bindToScope: true
7376
);
74-
final executor = SentryQueryExecutor(
75-
() => NativeDatabase.memory(),
76-
databaseName: 'your_db_name',
77-
);
77+
final interceptor = SentryQueryInterceptor(databaseName: 'my_database_name');
78+
final executor = inMemoryExecutor().interceptWith(interceptor);
7879
final db = AppDatabase(executor);
7980
8081
await db.into(db.todoItems).insert(

0 commit comments

Comments
 (0)