mirror of https://github.com/AMT-Cheif/drift.git
Integration test for fts5 queries
This commit is contained in:
parent
10b41bafe4
commit
9dbd737087
|
@ -0,0 +1,2 @@
|
||||||
|
tags:
|
||||||
|
integration:
|
|
@ -87,7 +87,7 @@ class NoIds extends Table with TableInfo<NoIds, NoId> {
|
||||||
GeneratedBlobColumn get payload => _payload ??= _constructPayload();
|
GeneratedBlobColumn get payload => _payload ??= _constructPayload();
|
||||||
GeneratedBlobColumn _constructPayload() {
|
GeneratedBlobColumn _constructPayload() {
|
||||||
return GeneratedBlobColumn('payload', $tableName, false,
|
return GeneratedBlobColumn('payload', $tableName, false,
|
||||||
$customConstraints: 'NOT NULL');
|
$customConstraints: 'NOT NULL PRIMARY KEY');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -112,7 +112,7 @@ class NoIds extends Table with TableInfo<NoIds, NoId> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Set<GeneratedColumn> get $primaryKey => <GeneratedColumn>{};
|
Set<GeneratedColumn> get $primaryKey => {payload};
|
||||||
@override
|
@override
|
||||||
NoId map(Map<String, dynamic> data, {String tablePrefix}) {
|
NoId map(Map<String, dynamic> data, {String tablePrefix}) {
|
||||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null;
|
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : null;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
CREATE TABLE no_ids (
|
CREATE TABLE no_ids (
|
||||||
payload BLOB NOT NULL
|
payload BLOB NOT NULL PRIMARY KEY
|
||||||
) WITHOUT ROWID;
|
) WITHOUT ROWID;
|
||||||
|
|
||||||
CREATE TABLE with_defaults (
|
CREATE TABLE with_defaults (
|
||||||
|
|
|
@ -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));
|
||||||
|
});
|
||||||
|
}
|
|
@ -44,5 +44,5 @@ void main() {
|
||||||
|
|
||||||
final resultRow = await query.getSingle();
|
final resultRow = await query.getSingle();
|
||||||
expect(resultRow.read(arrayLengthExpr), 3);
|
expect(resultRow.read(arrayLengthExpr), 3);
|
||||||
});
|
}, tags: const ['integration']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import '../data/tables/custom_tables.dart';
|
||||||
import '../data/utils/mocks.dart';
|
import '../data/utils/mocks.dart';
|
||||||
|
|
||||||
const _createNoIds =
|
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 ('
|
const _createWithDefaults = 'CREATE TABLE IF NOT EXISTS with_defaults ('
|
||||||
"a VARCHAR DEFAULT 'something', b INTEGER UNIQUE);";
|
"a VARCHAR DEFAULT 'something', b INTEGER UNIQUE);";
|
||||||
|
@ -47,7 +48,7 @@ void main() {
|
||||||
test('infers primary keys correctly', () async {
|
test('infers primary keys correctly', () async {
|
||||||
final db = CustomTablesDb(null);
|
final db = CustomTablesDb(null);
|
||||||
|
|
||||||
expect(db.noIds.primaryKey, isEmpty);
|
expect(db.noIds.primaryKey, [db.noIds.payload]);
|
||||||
expect(db.withDefaults.primaryKey, isEmpty);
|
expect(db.withDefaults.primaryKey, isEmpty);
|
||||||
expect(db.config.primaryKey, [db.config.configKey]);
|
expect(db.config.primaryKey, [db.config.configKey]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue