Integration test for fts5 queries

This commit is contained in:
Simon Binder 2019-12-25 14:00:47 +01:00
parent 10b41bafe4
commit 9dbd737087
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
6 changed files with 30 additions and 6 deletions

2
moor/dart_test.yaml Normal file
View File

@ -0,0 +1,2 @@
tags:
integration:

View File

@ -87,7 +87,7 @@ class NoIds extends Table with TableInfo<NoIds, NoId> {
GeneratedBlobColumn get payload => _payload ??= _constructPayload();
GeneratedBlobColumn _constructPayload() {
return GeneratedBlobColumn('payload', $tableName, false,
$customConstraints: 'NOT NULL');
$customConstraints: 'NOT NULL PRIMARY KEY');
}
@override
@ -112,7 +112,7 @@ class NoIds extends Table with TableInfo<NoIds, NoId> {
}
@override
Set<GeneratedColumn> get $primaryKey => <GeneratedColumn>{};
Set<GeneratedColumn> get $primaryKey => {payload};
@override
NoId map(Map<String, dynamic> data, {String tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null;

View File

@ -1,5 +1,5 @@
CREATE TABLE no_ids (
payload BLOB NOT NULL
payload BLOB NOT NULL PRIMARY KEY
) WITHOUT ROWID;
CREATE TABLE with_defaults (

View File

@ -0,0 +1,21 @@
@Tags(['integration'])
import 'package:moor_ffi/moor_ffi.dart';
import 'package:test/test.dart';
import '../data/tables/custom_tables.dart';
void main() {
test('fts5 integration test', () async {
final db = CustomTablesDb(VmDatabase.memory());
await db.into(db.email).insert(EmailCompanion.insert(
sender: 'foo@example.org', title: 'Hello world', body: 'Test email'));
await db.into(db.email).insert(EmailCompanion.insert(
sender: 'another@example.org', title: 'Good morning', body: 'hello'));
final results = await db.searchEmails('hello').get();
expect(results, hasLength(2));
});
}

View File

@ -44,5 +44,5 @@ void main() {
final resultRow = await query.getSingle();
expect(resultRow.read(arrayLengthExpr), 3);
});
}, tags: const ['integration']);
}

View File

@ -5,7 +5,8 @@ import '../data/tables/custom_tables.dart';
import '../data/utils/mocks.dart';
const _createNoIds =
'CREATE TABLE IF NOT EXISTS no_ids (payload BLOB NOT NULL) WITHOUT ROWID;';
'CREATE TABLE IF NOT EXISTS no_ids (payload BLOB NOT NULL PRIMARY KEY) '
'WITHOUT ROWID;';
const _createWithDefaults = 'CREATE TABLE IF NOT EXISTS with_defaults ('
"a VARCHAR DEFAULT 'something', b INTEGER UNIQUE);";
@ -47,7 +48,7 @@ void main() {
test('infers primary keys correctly', () async {
final db = CustomTablesDb(null);
expect(db.noIds.primaryKey, isEmpty);
expect(db.noIds.primaryKey, [db.noIds.payload]);
expect(db.withDefaults.primaryKey, isEmpty);
expect(db.config.primaryKey, [db.config.configKey]);
});