Skip to content

flutter v9: update drift #13495

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 21 additions & 20 deletions includes/dart-integrations/drift-instrumentation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ platforms:
- flutter
---

<Include name="feature-stage-beta.mdx" />

_(New in version 7.13.1)_

Drift is a library for easily managing SQLite databases within Flutter applications.
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.

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

```yml {filename:pubspec.yaml}
dependencies:
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter', '7.13.1') }}
sentry_drift: ^{{@inject packages.version('sentry.dart.drift', '7.13.1') }}
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter', '9.0.0') }}
sentry_drift: ^{{@inject packages.version('sentry.dart.drift', '9.0.0') }}
```

## Configure
## Setup

Inject `SentryQueryExecutor` into a `Drift` database instance:
Add the `SentryQueryInterceptor` to a `QueryExecutor` or `DatabaseConnection`.
Read the [Drift documentation](https://drift.simonbinder.eu/examples/tracing/) for more information on how to use interceptors in Drift.

```dart
import 'package:drift/native.dart';
import 'package:sentry_drift/sentry_drift.dart';
```dart {tabTitle: 'QueryExecutor'}
final interceptor = SentryQueryInterceptor(databaseName: 'my_database_name');
final executor = inMemoryExecutor().interceptWith(interceptor);

// AppDatabase is an example of the auto-generated database class by Drift.
final database = AppDatabase(executor);
```

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

## Verify
Expand All @@ -71,10 +74,8 @@ Future<void> driftTest() async {
'op',
bindToScope: true
);
final executor = SentryQueryExecutor(
() => NativeDatabase.memory(),
databaseName: 'your_db_name',
);
final interceptor = SentryQueryInterceptor(databaseName: 'my_database_name');
final executor = inMemoryExecutor().interceptWith(interceptor);
final db = AppDatabase(executor);

await db.into(db.todoItems).insert(
Expand Down