Migrate benchmarks to sqlite3/ package

This commit is contained in:
Simon Binder 2020-07-10 17:30:10 +02:00
parent e4fa5fb936
commit 22391a9c54
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 65 additions and 38 deletions

View File

@ -1,7 +1,7 @@
import 'dart:io';
import 'package:moor/ffi.dart';
import 'package:moor/moor.dart';
import 'package:moor_ffi/moor_ffi.dart';
import 'package:path/path.dart' as p;
import 'package:uuid/uuid.dart';

View File

@ -21,6 +21,26 @@ class KeyValue extends DataClass implements Insertable<KeyValue> {
stringType.mapFromDatabaseResponse(data['${effectivePrefix}value']),
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (!nullToAbsent || key != null) {
map['key'] = Variable<String>(key);
}
if (!nullToAbsent || value != null) {
map['value'] = Variable<String>(value);
}
return map;
}
KeyValuesCompanion toCompanion(bool nullToAbsent) {
return KeyValuesCompanion(
key: key == null && nullToAbsent ? const Value.absent() : Value(key),
value:
value == null && nullToAbsent ? const Value.absent() : Value(value),
);
}
factory KeyValue.fromJson(Map<String, dynamic> json,
{ValueSerializer serializer}) {
serializer ??= moorRuntimeOptions.defaultSerializer;
@ -38,15 +58,6 @@ class KeyValue extends DataClass implements Insertable<KeyValue> {
};
}
@override
KeyValuesCompanion createCompanion(bool nullToAbsent) {
return KeyValuesCompanion(
key: key == null && nullToAbsent ? const Value.absent() : Value(key),
value:
value == null && nullToAbsent ? const Value.absent() : Value(value),
);
}
KeyValue copyWith({String key, String value}) => KeyValue(
key: key ?? this.key,
value: value ?? this.value,
@ -80,12 +91,43 @@ class KeyValuesCompanion extends UpdateCompanion<KeyValue> {
@required String value,
}) : key = Value(key),
value = Value(value);
static Insertable<KeyValue> custom({
Expression<String> key,
Expression<String> value,
}) {
return RawValuesInsertable({
if (key != null) 'key': key,
if (value != null) 'value': value,
});
}
KeyValuesCompanion copyWith({Value<String> key, Value<String> value}) {
return KeyValuesCompanion(
key: key ?? this.key,
value: value ?? this.value,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (key.present) {
map['key'] = Variable<String>(key.value);
}
if (value.present) {
map['value'] = Variable<String>(value.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('KeyValuesCompanion(')
..write('key: $key, ')
..write('value: $value')
..write(')'))
.toString();
}
}
class $KeyValuesTable extends KeyValues
@ -126,17 +168,19 @@ class $KeyValuesTable extends KeyValues
@override
final String actualTableName = 'key_values';
@override
VerificationContext validateIntegrity(KeyValuesCompanion d,
VerificationContext validateIntegrity(Insertable<KeyValue> instance,
{bool isInserting = false}) {
final context = VerificationContext();
if (d.key.present) {
context.handle(_keyMeta, key.isAcceptableValue(d.key.value, _keyMeta));
final data = instance.toColumns(true);
if (data.containsKey('key')) {
context.handle(
_keyMeta, key.isAcceptableOrUnknown(data['key'], _keyMeta));
} else if (isInserting) {
context.missing(_keyMeta);
}
if (d.value.present) {
if (data.containsKey('value')) {
context.handle(
_valueMeta, value.isAcceptableValue(d.value.value, _valueMeta));
_valueMeta, value.isAcceptableOrUnknown(data['value'], _valueMeta));
} else if (isInserting) {
context.missing(_valueMeta);
}
@ -151,18 +195,6 @@ class $KeyValuesTable extends KeyValues
return KeyValue.fromData(data, _db, prefix: effectivePrefix);
}
@override
Map<String, Variable> entityToSql(KeyValuesCompanion d) {
final map = <String, Variable>{};
if (d.key.present) {
map['key'] = Variable<String>(d.key.value);
}
if (d.value.present) {
map['value'] = Variable<String>(d.value.value);
}
return map;
}
@override
$KeyValuesTable createAlias(String alias) {
return $KeyValuesTable(_db, alias);

View File

@ -1,5 +1,5 @@
import 'package:benchmarks/benchmarks.dart';
import 'package:moor_ffi/database.dart';
import 'package:sqlite3/sqlite3.dart';
class SelectStringBenchmark extends BenchmarkBase {
SelectStringBenchmark(ScoreEmitter emitter)
@ -10,7 +10,7 @@ class SelectStringBenchmark extends BenchmarkBase {
@override
void setup() {
database = Database.memory();
database = sqlite3.openInMemory();
statement = database.prepare('SELECT ?;');
}
@ -29,7 +29,7 @@ class SelectStringBenchmark extends BenchmarkBase {
@override
void teardown() {
statement.close();
database.close();
statement.dispose();
database.dispose();
}
}

View File

@ -3,7 +3,7 @@ description: Runs simple and complex benchmarks to measure performance of moor a
dependencies:
moor:
moor_ffi:
sqlite3: ^0.1.3
benchmark_harness: ^1.0.5
intl: ^0.16.0
uuid: ^2.0.0
@ -16,8 +16,6 @@ dev_dependencies:
dependency_overrides:
moor:
path: ../../moor
moor_ffi:
path: ../../moor_ffi
moor_generator:
path: ../../moor_generator
sqlparser:

View File

@ -14,10 +14,7 @@ dependencies:
collection: ^1.0.0
synchronized: ^2.1.0
pedantic: ^1.0.0
sqlite3:
git:
url: https://github.com/simolus3/sqlite3.dart.git
path: sqlite3
sqlite3: ^0.1.3
dev_dependencies:
moor_generator: ^3.2.0