Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fb09b38
setup
denrase Nov 14, 2023
8cefb7e
introduce wrappers for isar and isar_collection, wrap all async methods
denrase Nov 14, 2023
cc31e4b
Merge branch 'main' into feat/isar
denrase Nov 20, 2023
2420ec9
correctly setup tests
denrase Nov 20, 2023
d780a41
test isar & isar collection
denrase Nov 21, 2023
452015f
test throwing isar collection methods
denrase Nov 21, 2023
4ba63b6
add workflow for tests
denrase Nov 21, 2023
988ca81
also bump isar version
denrase Nov 21, 2023
2385a2e
add commented oout entry to craft.yml
denrase Nov 21, 2023
7910e51
Update example app
denrase Nov 21, 2023
5ee8639
Update examples
denrase Nov 21, 2023
b390fae
Add changelog entry
denrase Nov 21, 2023
fe19113
run format
denrase Nov 21, 2023
0b81c7f
Merge branch 'main' into feat/isar
denrase Nov 27, 2023
1caeb4a
fix readme
denrase Nov 27, 2023
9bf5a6d
remove separate isar import
denrase Nov 27, 2023
30e6254
add back isar dependency (used in tests)
denrase Nov 27, 2023
7961474
add generated person.g
denrase Nov 27, 2023
770a4e3
update workflows
denrase Nov 27, 2023
a47a830
add coverage to gitignore
denrase Nov 27, 2023
61cf436
ignore warning in generated mock code
denrase Nov 27, 2023
ead1481
change min coverage to 55
denrase Nov 27, 2023
30fdfa4
Add workaround for issue where UserSchema leads to compile issue on web
denrase Nov 27, 2023
2d4e12e
Merge branch 'main' into feat/isar
denrase Dec 4, 2023
23abf7e
fix changelog
denrase Dec 4, 2023
a4b42fa
update readme files
denrase Dec 5, 2023
34920d4
Merge branch 'main' into feat/isar
denrase Dec 5, 2023
65b6531
Merge branch 'main' into feat/isar
denrase Dec 18, 2023
20e3f8c
fix changelog
denrase Dec 18, 2023
525d3f8
Merge branch 'main' into feat/isar
denrase Dec 19, 2023
cbbaae8
fix changelog
denrase Dec 19, 2023
20d53f5
remove isar generator because of test failure on macOS (missing isar …
denrase Dec 19, 2023
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
Prev Previous commit
Next Next commit
correctly setup tests
  • Loading branch information
denrase committed Nov 20, 2023
commit 2420ec950f8c117ea2c62255a8b0d4ea9273fded
6 changes: 6 additions & 0 deletions isar/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ pubspec.lock
.pub-cache/
.pub/
/build/

# Created by build runner
test/person.g.dart

# Downloaded on demand by tests for correct architecture.
libisar.dylib
157 changes: 100 additions & 57 deletions isar/lib/sentry_isar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library sentry_isar;

import 'package:isar/isar.dart';
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';
Expand All @@ -9,7 +10,6 @@ import 'sentry_span_helper.dart';
/// A sentry wrapper around the Isar Database
@experimental
class SentryIsar implements Isar {

@internal
// ignore: public_member_api_docs
static const dbOp = 'db';
Expand All @@ -33,48 +33,62 @@ class SentryIsar implements Isar {
);

/// ctor of SentryIsar
SentryIsar(this._isar, this._hub);
SentryIsar(this._isar, this._hub) {
_spanHelper.setHub(_hub);
}

/// Open a new Isar instance, wrapped by SentryIsar
static Future<Isar> open(
List<CollectionSchema<dynamic>> schemas, {
required String directory,
String name = Isar.defaultName,
int maxSizeMiB = Isar.defaultMaxSizeMiB,
bool relaxedDurability = true,
CompactCondition? compactOnLaunch,
bool inspector = true,
Hub? hub,
}
) async {
final isar = await Isar.open(
schemas,
directory: directory,
name: name,
maxSizeMiB: maxSizeMiB,
relaxedDurability: relaxedDurability,
compactOnLaunch: compactOnLaunch,
inspector: inspector,
List<CollectionSchema<dynamic>> schemas, {
required String directory,
String name = Isar.defaultName,
int maxSizeMiB = Isar.defaultMaxSizeMiB,
bool relaxedDurability = true,
CompactCondition? compactOnLaunch,
bool inspector = true,
Hub? hub,
}) async {
final spanHelper = SentrySpanHelper(
// ignore: invalid_use_of_internal_member
SentryTraceOrigins.autoDbIsar,
);
return SentryIsar(isar, hub ?? HubAdapter());
final hubToUse = hub ?? HubAdapter();
spanHelper.setHub(hubToUse);

final isar = await spanHelper.asyncWrapInSpan(
'open',
() async {
return await Isar.open(
schemas,
directory: directory,
name: name,
maxSizeMiB: maxSizeMiB,
relaxedDurability: relaxedDurability,
compactOnLaunch: compactOnLaunch,
inspector: inspector,
);
},
dbName: name,
);

return SentryIsar(isar, hubToUse);
}

/// Open a new Isar instance, wrapped by SentryIsar
static Isar openSync(
List<CollectionSchema<dynamic>> schemas, {
required String directory,
String name = Isar.defaultName,
int maxSizeMiB = Isar.defaultMaxSizeMiB,
bool relaxedDurability = true,
CompactCondition? compactOnLaunch,
bool inspector = true,
Hub? hub,
}
) {
required String directory,
String name = Isar.defaultName,
int maxSizeMiB = Isar.defaultMaxSizeMiB,
bool relaxedDurability = true,
CompactCondition? compactOnLaunch,
bool inspector = true,
Hub? hub,
}) {
final isar = Isar.openSync(
schemas,
directory: directory,
name: name,
name: name,
maxSizeMiB: maxSizeMiB,
relaxedDurability: relaxedDurability,
compactOnLaunch: compactOnLaunch,
Expand All @@ -90,9 +104,13 @@ class SentryIsar implements Isar {

@override
Future<void> clear() {
return _spanHelper.asyncWrapInSpan('clear', () {
return _isar.clear();
});
return _spanHelper.asyncWrapInSpan(
'clear',
() {
return _isar.clear();
},
dbName: name,
);
}

@override
Expand All @@ -102,9 +120,13 @@ class SentryIsar implements Isar {

@override
Future<bool> close({bool deleteFromDisk = false}) {
return _spanHelper.asyncWrapInSpan('close', () {
return _isar.close(deleteFromDisk: deleteFromDisk);
});
return _spanHelper.asyncWrapInSpan(
'close',
() {
return _isar.close(deleteFromDisk: deleteFromDisk);
},
dbName: name,
);
}

@override
Expand All @@ -114,9 +136,13 @@ class SentryIsar implements Isar {

@override
Future<void> copyToFile(String targetPath) {
return _spanHelper.asyncWrapInSpan('copyToFile', () {
return _isar.copyToFile(targetPath);
});
return _spanHelper.asyncWrapInSpan(
'copyToFile',
() {
return _isar.copyToFile(targetPath);
},
dbName: name,
);
}

@override
Expand All @@ -133,13 +159,18 @@ class SentryIsar implements Isar {
}

@override
Future<int> getSize({bool includeIndexes = false, bool includeLinks = false}) {
return _spanHelper.asyncWrapInSpan('getSize', () {
return _isar.getSize(
includeIndexes: includeIndexes,
includeLinks: includeLinks,
);
});
Future<int> getSize(
{bool includeIndexes = false, bool includeLinks = false}) {
return _spanHelper.asyncWrapInSpan(
'getSize',
() {
return _isar.getSize(
includeIndexes: includeIndexes,
includeLinks: includeLinks,
);
},
dbName: name,
);
}

@override
Expand All @@ -166,9 +197,13 @@ class SentryIsar implements Isar {

@override
Future<T> txn<T>(Future<T> Function() callback) {
return _spanHelper.asyncWrapInSpan('txn', () {
return _isar.txn(callback);
});
return _spanHelper.asyncWrapInSpan(
'txn',
() {
return _isar.txn(callback);
},
dbName: name,
);
}

@override
Expand All @@ -180,17 +215,25 @@ class SentryIsar implements Isar {
@visibleForTesting
@experimental
Future<void> verify() {
return _spanHelper.asyncWrapInSpan('verify', () {
// ignore: invalid_use_of_visible_for_testing_member
return _isar.verify();
});
return _spanHelper.asyncWrapInSpan(
'verify',
() {
// ignore: invalid_use_of_visible_for_testing_member
return _isar.verify();
},
dbName: name,
);
}

@override
Future<T> writeTxn<T>(Future<T> Function() callback, {bool silent = false}) {
return _spanHelper.asyncWrapInSpan('writeTxn', () {
return _isar.writeTxn(callback, silent: silent);
});
return _spanHelper.asyncWrapInSpan(
'writeTxn',
() {
return _isar.writeTxn(callback, silent: silent);
},
dbName: name,
);
}

@override
Expand Down
45 changes: 25 additions & 20 deletions isar/lib/sentry_isar_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'sentry_span_helper.dart';
/// Sentry wrapper around IsarCollection
@experimental
class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {

final IsarCollection<OBJ> _isarCollection;
final Hub _hub;
final _spanHelper = SentrySpanHelper(
Expand All @@ -32,15 +31,15 @@ class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {
String? property,
}) {
return _isarCollection.buildQuery(
whereClauses: whereClauses,
whereDistinct: whereDistinct,
whereSort: whereSort,
filter: filter,
sortBy: sortBy,
distinctBy: distinctBy,
offset: offset,
limit: limit,
property: property,
whereClauses: whereClauses,
whereDistinct: whereDistinct,
whereSort: whereSort,
filter: filter,
sortBy: sortBy,
distinctBy: distinctBy,
offset: offset,
limit: limit,
property: property,
);
}

Expand Down Expand Up @@ -165,7 +164,8 @@ class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {
}

@override
Future<int> getSize({bool includeIndexes = false, bool includeLinks = false}) {
Future<int> getSize(
{bool includeIndexes = false, bool includeLinks = false}) {
return _spanHelper.asyncWrapInSpan('getSize', () {
return _isarCollection.getSize(
includeIndexes: includeIndexes,
Expand Down Expand Up @@ -239,11 +239,12 @@ class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {
}

@override
List<Id> putAllByIndexSync(String indexName, List<OBJ> objects, {bool saveLinks = true}) {
List<Id> putAllByIndexSync(String indexName, List<OBJ> objects,
{bool saveLinks = true}) {
return _isarCollection.putAllByIndexSync(
indexName,
objects,
saveLinks: saveLinks,
indexName,
objects,
saveLinks: saveLinks,
);
}

Expand All @@ -262,8 +263,9 @@ class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {
@override
Id putByIndexSync(String indexName, OBJ object, {bool saveLinks = true}) {
return _isarCollection.putByIndexSync(
indexName, object,
saveLinks: saveLinks,
indexName,
object,
saveLinks: saveLinks,
);
}

Expand All @@ -288,7 +290,8 @@ class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {
@override
@visibleForTesting
@experimental
Future<void> verifyLink(String linkName, List<int> sourceIds, List<int> targetIds) {
Future<void> verifyLink(
String linkName, List<int> sourceIds, List<int> targetIds) {
return _spanHelper.asyncWrapInSpan('verifyLink', () {
// ignore: invalid_use_of_visible_for_testing_member
return _isarCollection.verifyLink(linkName, sourceIds, targetIds);
Expand All @@ -307,11 +310,13 @@ class SentryIsarCollection<OBJ> implements IsarCollection<OBJ> {

@override
Stream<void> watchObjectLazy(Id id, {bool fireImmediately = false}) {
return _isarCollection.watchObjectLazy(id, fireImmediately: fireImmediately);
return _isarCollection.watchObjectLazy(id,
fireImmediately: fireImmediately);
}

@override
QueryBuilder<OBJ, OBJ, QWhere> where({bool distinct = false, Sort sort = Sort.asc}) {
QueryBuilder<OBJ, OBJ, QWhere> where(
{bool distinct = false, Sort sort = Sort.asc}) {
return _isarCollection.where(distinct: distinct, sort: sort);
}
}
10 changes: 5 additions & 5 deletions isar/lib/sentry_span_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class SentrySpanHelper {
/// @nodoc
@internal
Future<T> asyncWrapInSpan<T>(
String description,
Future<T> Function() execute, {
String? dbName,
}) async {
String description,
Future<T> Function() execute, {
String? dbName,
}) async {
final currentSpan = _hub.getSpan();
final span = currentSpan?.startChild(
SentryIsar.dbOp,
Expand Down Expand Up @@ -57,4 +57,4 @@ class SentrySpanHelper {
await span?.finish();
}
}
}
}
7 changes: 7 additions & 0 deletions isar/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:mockito/annotations.dart';
import 'package:sentry/sentry.dart';

@GenerateMocks([
Hub,
])
void main() {}
Loading