Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c744c21
commit 4dedd63
Showing
14 changed files
with
801 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:edge_db_benchmarks/models/embedding.dart'; | ||
import 'package:isar/isar.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
class IsarDB { | ||
late final Isar _isar; | ||
|
||
IsarDB._privateConstructor(); | ||
|
||
static final IsarDB instance = IsarDB._privateConstructor(); | ||
|
||
Future<void> init() async { | ||
final docsDir = await getApplicationDocumentsDirectory(); | ||
final path = join(docsDir.path, "embeddings.isar.db"); | ||
final directory = Directory(path); | ||
if (await directory.exists()) { | ||
await directory.delete(recursive: true); | ||
} | ||
await directory.create(recursive: true); | ||
_isar = await Isar.open( | ||
[EmbeddingSchema], | ||
directory: path, | ||
); | ||
} | ||
|
||
Future<void> put(Embedding embedding) { | ||
return _isar.writeTxn(() async { | ||
await _isar.embeddings.put(embedding); | ||
}); | ||
} | ||
|
||
Future<void> putMany(List<Embedding> embeddings) { | ||
return _isar.writeTxn(() async { | ||
await _isar.embeddings.putAll(embeddings); | ||
}); | ||
} | ||
|
||
Future<List<Embedding>> embeddings() { | ||
return _isar.embeddings.filter().embeddingIsNotEmpty().findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.