Skip to content
Prev Previous commit
Next Next commit
format
  • Loading branch information
buenaflor committed Sep 7, 2023
commit dec3513b2728fd419cf609c584053e9abb2fb76c
11 changes: 6 additions & 5 deletions sqflite/lib/src/sentry_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
@internal Hub? hub,
}) : _hub = hub ?? HubAdapter(),
dbName = _basenameWithoutExtension(_database.path),
super(_database, hub: hub, dbName: _basenameWithoutExtension(_database.path)) {
super(_database,
hub: hub, dbName: _basenameWithoutExtension(_database.path)) {
// ignore: invalid_use_of_internal_member
final options = _hub.options;
options.sdk.addIntegration('SentrySqfliteTracing');
Expand All @@ -66,8 +67,8 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {

/// Gets the part of path after the last separator, and without any trailing file extension.
static String _basenameWithoutExtension(String filePath) {
int lastIndex = filePath.lastIndexOf('/');
int dotIndex = filePath.lastIndexOf('.');
final int lastIndex = filePath.lastIndexOf('/');
final int dotIndex = filePath.lastIndexOf('.');

if (dotIndex == -1 || (lastIndex != -1 && dotIndex < lastIndex)) {
return filePath;
Expand Down Expand Up @@ -143,8 +144,8 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
setDatabaseAttributeData(span, dbName);

Future<T> newAction(Transaction txn) async {
final executor =
SentryDatabaseExecutor(txn, parentSpan: span, hub: _hub, dbName: dbName);
final executor = SentryDatabaseExecutor(txn,
parentSpan: span, hub: _hub, dbName: dbName);
final sentrySqfliteTransaction =
SentrySqfliteTransaction(executor, hub: _hub, dbName: dbName);

Expand Down
3 changes: 2 additions & 1 deletion sqflite/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ ISentrySpan startTransactionShim(
DatabaseExecutor,
],
customMocks: [
MockSpec<Hub>(fallbackGenerators: {#startTransaction: startTransactionShim})
MockSpec<Hub>(
fallbackGenerators: {#startTransaction: startTransactionShim}),
],
)
void main() {}
6 changes: 4 additions & 2 deletions sqflite/test/sentry_batch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ SELECT * FROM Product''';

final span = fixture.tracer.children.last;
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
expect(
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);

await db.close();
});
Expand All @@ -311,7 +312,8 @@ SELECT * FROM Product''';

final span = fixture.tracer.children.last;
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
expect(
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);

await db.close();
});
Expand Down
8 changes: 5 additions & 3 deletions sqflite/test/sentry_database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void main() {
);
expect(insertSpan.context.parentSpanId, trSpan.context.spanId);
expect(insertSpan.status, SpanStatus.ok());
expect(insertSpan.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(
insertSpan.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(insertSpan.data[SentryDatabase.dbNameKey], inMemoryDatabasePath);

expect(
Expand Down Expand Up @@ -147,8 +148,9 @@ void main() {
test('opening db sets currentDbName with db file without extension',
() async {
final db = await fixture.getSut(
database: await openDatabase('path/database/mydatabase.db'),
execute: false);
database: await openDatabase('path/database/mydatabase.db'),
execute: false,
);

expect(db.dbName, 'mydatabase');

Expand Down