mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Upgrade drift
This commit is contained in:
parent
24f1281478
commit
18f5a49db0
18 changed files with 1829 additions and 1645 deletions
|
@ -1,13 +1,6 @@
|
|||
targets:
|
||||
$default:
|
||||
builders:
|
||||
drift_dev:
|
||||
options:
|
||||
apply_converters_on_variables: true
|
||||
generate_values_in_copy_with: true
|
||||
new_sql_code_generation: true
|
||||
scoped_dart_components: true
|
||||
generate_connect_constructor: true
|
||||
to_string_build:
|
||||
options:
|
||||
formatStringNameMapping:
|
||||
|
|
|
@ -216,7 +216,7 @@ class AlbumSqliteDbDataSource2 implements AlbumDataSource2 {
|
|||
await db.into(db.albums).insertReturning(insert.album);
|
||||
rowId = insertedAlbum.rowId;
|
||||
} else {
|
||||
await (db.delete(db.albumShares)..where((t) => t.album.equals(rowId)))
|
||||
await (db.delete(db.albumShares)..where((t) => t.album.equals(rowId!)))
|
||||
.go();
|
||||
}
|
||||
if (insert.albumShares.isNotEmpty) {
|
||||
|
|
|
@ -416,7 +416,7 @@ class FileSqliteDbDataSource implements FileDataSource {
|
|||
}
|
||||
return q.build();
|
||||
});
|
||||
final dateTime = db.accountFiles.bestDateTime.secondsSinceEpoch;
|
||||
final dateTime = db.accountFiles.bestDateTime.unixepoch;
|
||||
query
|
||||
..where(dateTime.isBetweenValues(
|
||||
fromEpochMs ~/ 1000, (toEpochMs ~/ 1000) - 1))
|
||||
|
|
|
@ -133,7 +133,7 @@ class FileSqliteCacheUpdater {
|
|||
}
|
||||
|
||||
final dirFileQuery = db.select(db.dirFiles)
|
||||
..where((t) => t.dir.equals(_dirRowId))
|
||||
..where((t) => t.dir.equals(_dirRowId!))
|
||||
..orderBy([(t) => sql.OrderingTerm.asc(t.rowId)]);
|
||||
final dirFiles = await dirFileQuery.get();
|
||||
final diff = list_util.diff(dirFiles.map((e) => e.child),
|
||||
|
@ -151,7 +151,7 @@ class FileSqliteCacheUpdater {
|
|||
final deleteQuery = db.delete(db.dirFiles)
|
||||
..where((t) => t.child.isIn(sublist))
|
||||
..where((t) =>
|
||||
t.dir.equals(_dirRowId) | t.dir.equalsExp(db.dirFiles.child));
|
||||
t.dir.equals(_dirRowId!) | t.dir.equalsExp(db.dirFiles.child));
|
||||
await deleteQuery.go();
|
||||
}, sql.maxByFileIdsSize);
|
||||
|
||||
|
|
|
@ -46,8 +46,6 @@ class SqliteDb extends _$SqliteDb {
|
|||
QueryExecutor? executor,
|
||||
}) : super(executor ?? platform.openSqliteConnection());
|
||||
|
||||
SqliteDb.connect(DatabaseConnection connection) : super.connect(connection);
|
||||
|
||||
@override
|
||||
get schemaVersion => 5;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -618,7 +618,7 @@ extension SqliteDbExtension on SqliteDb {
|
|||
query
|
||||
..where(files.fileId.isIn(sublist))
|
||||
..where(whereFileIsSupportedImageMime());
|
||||
return [await query.map((r) => r.read(count)).getSingle()];
|
||||
return [await query.map((r) => r.read(count)!).getSingle()];
|
||||
}, maxByFileIdsSize);
|
||||
return counts.reduce((value, element) => value + element);
|
||||
}
|
||||
|
@ -645,15 +645,15 @@ extension SqliteDbExtension on SqliteDb {
|
|||
await customStatement("UPDATE sqlite_sequence SET seq=0;");
|
||||
}
|
||||
|
||||
Expression<bool?> whereFileIsSupportedMime() {
|
||||
Expression<bool> whereFileIsSupportedMime() {
|
||||
return file_util.supportedFormatMimes
|
||||
.map<Expression<bool?>>((m) => files.contentType.equals(m))
|
||||
.map<Expression<bool>>((m) => files.contentType.equals(m))
|
||||
.reduce((value, element) => value | element);
|
||||
}
|
||||
|
||||
Expression<bool?> whereFileIsSupportedImageMime() {
|
||||
Expression<bool> whereFileIsSupportedImageMime() {
|
||||
return file_util.supportedImageFormatMimes
|
||||
.map<Expression<bool?>>((m) => files.contentType.equals(m))
|
||||
.map<Expression<bool>>((m) => files.contentType.equals(m))
|
||||
.reduce((value, element) => value | element);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ enum FilesQueryMode {
|
|||
expression,
|
||||
}
|
||||
|
||||
typedef FilesQueryRelativePathBuilder = Expression<bool?> Function(
|
||||
GeneratedColumn<String?> relativePath);
|
||||
typedef FilesQueryRelativePathBuilder = Expression<bool> Function(
|
||||
GeneratedColumn<String> relativePath);
|
||||
|
||||
/// Build a Files table query
|
||||
///
|
||||
|
@ -136,28 +136,28 @@ class FilesQueryBuilder {
|
|||
}
|
||||
|
||||
if (_byRowId != null) {
|
||||
query.where(db.files.rowId.equals(_byRowId));
|
||||
query.where(db.files.rowId.equals(_byRowId!));
|
||||
}
|
||||
if (_byFileId != null) {
|
||||
query.where(db.files.fileId.equals(_byFileId));
|
||||
query.where(db.files.fileId.equals(_byFileId!));
|
||||
}
|
||||
if (_byFileIds != null) {
|
||||
query.where(db.files.fileId.isIn(_byFileIds!));
|
||||
}
|
||||
if (_byRelativePath != null) {
|
||||
query.where(db.accountFiles.relativePath.equals(_byRelativePath));
|
||||
query.where(db.accountFiles.relativePath.equals(_byRelativePath!));
|
||||
}
|
||||
if (_byOrRelativePathBuilders?.isNotEmpty == true) {
|
||||
final expression = _byOrRelativePathBuilders!
|
||||
.sublist(1)
|
||||
.fold<Expression<bool?>>(
|
||||
.fold<Expression<bool>>(
|
||||
_byOrRelativePathBuilders![0](db.accountFiles.relativePath),
|
||||
(previousValue, builder) =>
|
||||
previousValue | builder(db.accountFiles.relativePath));
|
||||
query.where(expression);
|
||||
}
|
||||
if (_byMimePatterns?.isNotEmpty == true) {
|
||||
final expression = _byMimePatterns!.sublist(1).fold<Expression<bool?>>(
|
||||
final expression = _byMimePatterns!.sublist(1).fold<Expression<bool>>(
|
||||
db.files.contentType.like(_byMimePatterns![0]),
|
||||
(previousValue, element) =>
|
||||
previousValue | db.files.contentType.like(element));
|
||||
|
@ -172,10 +172,10 @@ class FilesQueryBuilder {
|
|||
}
|
||||
}
|
||||
if (_byDirRowId != null) {
|
||||
query.where(db.dirFiles.dir.equals(_byDirRowId));
|
||||
query.where(db.dirFiles.dir.equals(_byDirRowId!));
|
||||
}
|
||||
if (_byServerRowId != null) {
|
||||
query.where(db.files.server.equals(_byServerRowId));
|
||||
query.where(db.files.server.equals(_byServerRowId!));
|
||||
}
|
||||
if (_byLocation != null) {
|
||||
var clause = db.imageLocations.name.like(_byLocation!) |
|
||||
|
|
|
@ -21,7 +21,7 @@ Future<SqliteDb> createDb() async {
|
|||
// see: https://drift.simonbinder.eu/docs/advanced-features/isolates/
|
||||
final driftIsolate = await _createDriftIsolate();
|
||||
final connection = await driftIsolate.connect();
|
||||
return SqliteDb.connect(connection);
|
||||
return SqliteDb(executor: connection);
|
||||
}
|
||||
|
||||
Future<U> computeWithDb<T, U>(
|
||||
|
@ -65,6 +65,7 @@ Future<DriftIsolate> _createDriftIsolate() async {
|
|||
return await receivePort.first as DriftIsolate;
|
||||
}
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
void _startBackground(_IsolateStartRequest request) {
|
||||
app_init.initDrift();
|
||||
|
||||
|
@ -75,7 +76,7 @@ void _startBackground(_IsolateStartRequest request) {
|
|||
// background isolate. If we used DriftIsolate.spawn, a third isolate would be
|
||||
// started which is not what we want!
|
||||
final driftIsolate = DriftIsolate.inCurrent(
|
||||
() => DatabaseConnection.fromExecutor(executor),
|
||||
() => DatabaseConnection(executor),
|
||||
// this breaks background service!
|
||||
serialize: false,
|
||||
);
|
||||
|
|
|
@ -237,8 +237,8 @@ class SqliteDateTimeConverter extends TypeConverter<DateTime, DateTime> {
|
|||
const SqliteDateTimeConverter();
|
||||
|
||||
@override
|
||||
DateTime? mapToDart(DateTime? fromDb) => fromDb?.toUtc();
|
||||
DateTime fromSql(DateTime fromDb) => fromDb.toUtc();
|
||||
|
||||
@override
|
||||
DateTime? mapToSql(DateTime? value) => value?.toUtc();
|
||||
DateTime toSql(DateTime value) => value.toUtc();
|
||||
}
|
||||
|
|
3
app/lib/map_extension.dart
Normal file
3
app/lib/map_extension.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
extension MapEntryListExtension<T, U> on Iterable<MapEntry<T, U>> {
|
||||
Map<T, U> toMap() => Map.fromEntries(this);
|
||||
}
|
|
@ -62,7 +62,7 @@ class CacheFavorite {
|
|||
}
|
||||
if (removedFildIds.isNotEmpty) {
|
||||
final counts =
|
||||
await removedFildIds.map((id) => cacheMap[id]).withPartition(
|
||||
await removedFildIds.map((id) => cacheMap[id]!).withPartition(
|
||||
(sublist) async {
|
||||
return [
|
||||
await (db.update(db.accountFiles)
|
||||
|
|
|
@ -18,7 +18,7 @@ class CompatV55 {
|
|||
return db.use((db) async {
|
||||
final countExp = db.accountFiles.rowId.count();
|
||||
final countQ = db.selectOnly(db.accountFiles)..addColumns([countExp]);
|
||||
final count = await countQ.map((r) => r.read<int>(countExp)).getSingle();
|
||||
final count = await countQ.map((r) => r.read(countExp)!).getSingle();
|
||||
onProgress?.call(0, count);
|
||||
|
||||
final dateTimeUpdates = <Tuple2<int, DateTime>>[];
|
||||
|
|
|
@ -85,9 +85,9 @@ class ListLocationGroup {
|
|||
return LocationGroup(
|
||||
r.read(db.imageLocations.name)!,
|
||||
r.read(db.imageLocations.countryCode)!,
|
||||
r.read(count),
|
||||
r.read(count)!,
|
||||
r.read(db.files.fileId)!,
|
||||
r.read(latest).toUtc(),
|
||||
r.read(latest)!.toUtc(),
|
||||
);
|
||||
}).get(),
|
||||
);
|
||||
|
@ -104,9 +104,9 @@ class ListLocationGroup {
|
|||
.map((r) => LocationGroup(
|
||||
r.read(db.imageLocations.admin1)!,
|
||||
r.read(db.imageLocations.countryCode)!,
|
||||
r.read(count),
|
||||
r.read(count)!,
|
||||
r.read(db.files.fileId)!,
|
||||
r.read(latest).toUtc(),
|
||||
r.read(latest)!.toUtc(),
|
||||
))
|
||||
.get(),
|
||||
);
|
||||
|
@ -123,9 +123,9 @@ class ListLocationGroup {
|
|||
.map((r) => LocationGroup(
|
||||
r.read(db.imageLocations.admin2)!,
|
||||
r.read(db.imageLocations.countryCode)!,
|
||||
r.read(count),
|
||||
r.read(count)!,
|
||||
r.read(db.files.fileId)!,
|
||||
r.read(latest).toUtc(),
|
||||
r.read(latest)!.toUtc(),
|
||||
))
|
||||
.get(),
|
||||
);
|
||||
|
@ -143,9 +143,9 @@ class ListLocationGroup {
|
|||
return LocationGroup(
|
||||
location_util.alpha2CodeToName(cc) ?? cc,
|
||||
cc,
|
||||
r.read(count),
|
||||
r.read(count)!,
|
||||
r.read(db.files.fileId)!,
|
||||
r.read(latest).toUtc(),
|
||||
r.read(latest)!.toUtc(),
|
||||
);
|
||||
}).get(),
|
||||
);
|
||||
|
@ -168,7 +168,7 @@ class ListLocationGroup {
|
|||
String dir,
|
||||
sql.Expression<DateTime> latest,
|
||||
sql.Expression<int> count,
|
||||
sql.GeneratedColumn<String?> groupColumn,
|
||||
sql.GeneratedColumn<String> groupColumn,
|
||||
) {
|
||||
final query = db.selectOnly(db.imageLocations).join([
|
||||
sql.innerJoin(db.accountFiles,
|
||||
|
|
|
@ -5,26 +5,26 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: _fe_analyzer_shared
|
||||
sha256: "4897882604d919befd350648c7f91926a9d5de99e67b455bf0917cc2362f4bb8"
|
||||
sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "47.0.0"
|
||||
version: "61.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
sha256: "690e335554a8385bc9d787117d9eb52c0c03ee207a607e593de3c9d71b1cfe80"
|
||||
sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.7.0"
|
||||
version: "5.13.0"
|
||||
analyzer_plugin:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer_plugin
|
||||
sha256: "02b0046b8b9a4c97a238c66f70acd22eec4263dfc8d9205f9dab5cc8630c5a6f"
|
||||
sha256: c1d5f167683de03d5ab6c3b53fc9aeefc5d59476e7810ba7bbddff50c6f4392d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.11.1"
|
||||
version: "0.11.2"
|
||||
android_intent_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -328,10 +328,18 @@ packages:
|
|||
dependency: "direct dev"
|
||||
description:
|
||||
name: dart_code_metrics
|
||||
sha256: dbb719c64661e8d279dc113bc1dc9484e159b805a0d779074cd92ea3856ffa0b
|
||||
sha256: "1dc1fa763b73ed52147bd91b015d81903edc3f227b77b1672fcddba43390ed18"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.18.0"
|
||||
version: "5.7.5"
|
||||
dart_code_metrics_presets:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dart_code_metrics_presets
|
||||
sha256: b71eadf02a3787ebd5c887623f83f6fdc204d45c75a081bd636c4104b3fd8b73
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
dart_style:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -393,18 +401,18 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: drift
|
||||
sha256: "43ae515270f38ffe47702dc920c04d415894bcc6ebdf3e2b6a292cb207ed8cb7"
|
||||
sha256: "21abd7b1c1a637a264f58f9f05c7b910d29c204aab1cbfcb4d9fada1e98a9303"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.7.1"
|
||||
version: "2.8.0"
|
||||
drift_dev:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: drift_dev
|
||||
sha256: "7d51538da971823a158236823cfb299731f720cd55078c6a478bfa4effb69275"
|
||||
sha256: ac1454f20b4b721bfbde7bd3b05123150bae2196ef992c405c07a63f5976a397
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.7.1"
|
||||
version: "2.8.0"
|
||||
equatable:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -1137,6 +1145,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
pub_updater:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pub_updater
|
||||
sha256: "05ae70703e06f7fdeb05f7f02dd680b8aad810e87c756a618f33e1794635115c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
pubspec_parse:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1394,10 +1410,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: sqlparser
|
||||
sha256: "9ed8f4a24a2a243e23ad267bb50378cb75c7de0b200b5336229b2d6096e6a5df"
|
||||
sha256: b5b24c2804d39cbd619b424d8c9b1321cc5e813fd0e7b95a2707f596f82d5cd3
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.22.0"
|
||||
version: "0.29.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -52,7 +52,7 @@ dependencies:
|
|||
git:
|
||||
url: https://gitlab.com/nc-photos/flutter-draggable-scrollbar
|
||||
ref: v0.1.0-nc-photos-6
|
||||
drift: ^1.7.1
|
||||
drift: 2.8.0
|
||||
equatable: ^2.0.5
|
||||
event_bus: ^2.0.0
|
||||
exifdart:
|
||||
|
@ -145,7 +145,7 @@ dev_dependencies:
|
|||
path: copy_with_build
|
||||
ref: copy_with_build-1.6.0
|
||||
dart_code_metrics: any
|
||||
drift_dev: ^1.7.0
|
||||
drift_dev: 2.8.0
|
||||
flutter_lints: any
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
|
|
@ -39,7 +39,7 @@ Future<void> _insertAccountFirst() async {
|
|||
expect(
|
||||
await util.listSqliteDbServerAccounts(c.sqliteDb),
|
||||
{
|
||||
util.SqlAccountWithServer(
|
||||
const util.SqlAccountWithServer(
|
||||
sql.Server(rowId: 1, address: "http://example.com"),
|
||||
sql.Account(rowId: 1, server: 1, userId: "admin"),
|
||||
),
|
||||
|
@ -67,11 +67,11 @@ Future<void> _insertAccountSameServer() async {
|
|||
expect(
|
||||
await util.listSqliteDbServerAccounts(c.sqliteDb),
|
||||
{
|
||||
util.SqlAccountWithServer(
|
||||
const util.SqlAccountWithServer(
|
||||
sql.Server(rowId: 1, address: "http://example.com"),
|
||||
sql.Account(rowId: 1, server: 1, userId: "admin"),
|
||||
),
|
||||
util.SqlAccountWithServer(
|
||||
const util.SqlAccountWithServer(
|
||||
sql.Server(rowId: 1, address: "http://example.com"),
|
||||
sql.Account(rowId: 2, server: 1, userId: "user1"),
|
||||
),
|
||||
|
@ -99,7 +99,7 @@ Future<void> _insertAccountSameAccount() async {
|
|||
expect(
|
||||
await util.listSqliteDbServerAccounts(c.sqliteDb),
|
||||
{
|
||||
util.SqlAccountWithServer(
|
||||
const util.SqlAccountWithServer(
|
||||
sql.Server(rowId: 1, address: "http://example.com"),
|
||||
sql.Account(rowId: 1, server: 1, userId: "admin"),
|
||||
),
|
||||
|
@ -177,7 +177,7 @@ Future<void> _deleteAccountSameServer() async {
|
|||
expect(
|
||||
await util.listSqliteDbServerAccounts(c.sqliteDb),
|
||||
{
|
||||
util.SqlAccountWithServer(
|
||||
const util.SqlAccountWithServer(
|
||||
sql.Server(rowId: 1, address: "http://example.com"),
|
||||
sql.Account(rowId: 2, server: 1, userId: "user1"),
|
||||
),
|
||||
|
@ -228,7 +228,7 @@ Future<void> _deleteAccountSameServerSharedFile() async {
|
|||
expect(
|
||||
await util.listSqliteDbServerAccounts(c.sqliteDb),
|
||||
{
|
||||
util.SqlAccountWithServer(
|
||||
const util.SqlAccountWithServer(
|
||||
sql.Server(rowId: 1, address: "http://example.com"),
|
||||
sql.Account(rowId: 2, server: 1, userId: "user1"),
|
||||
),
|
||||
|
|
|
@ -601,7 +601,7 @@ Future<Set<Album>> listSqliteDbAlbums(sql.SqliteDb db) async {
|
|||
),
|
||||
);
|
||||
return Tuple2(
|
||||
r.read(db.albums.rowId),
|
||||
r.read(db.albums.rowId)!,
|
||||
SqliteAlbumConverter.fromSql(r.readTable(db.albums), albumFile, []),
|
||||
);
|
||||
}).get();
|
||||
|
|
Loading…
Reference in a new issue