intermediate
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/extensions/database_table_size.dart';
|
||||
import 'package:lensai/features/user/data/database/database.dart';
|
||||
|
||||
part 'cache.g.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class CacheDao extends DatabaseAccessor<UserDatabase> with _$CacheDaoMixin {
|
||||
CacheDao(super.attachedDatabase);
|
||||
|
||||
SingleSelectable<double> iconCacheSize() {
|
||||
return db.tableSize(db.iconCache);
|
||||
}
|
||||
|
||||
Future<int> clearIconCache() {
|
||||
return db.iconCache.deleteAll();
|
||||
}
|
||||
|
||||
SingleOrNullSelectable<Uint8List?> getCachedIcon(String origin) {
|
||||
final query = selectOnly(db.iconCache)
|
||||
..addColumns([db.iconCache.iconData])
|
||||
..where(db.iconCache.origin.equals(origin));
|
||||
|
||||
return query.map((row) => row.read(db.iconCache.iconData));
|
||||
}
|
||||
|
||||
Future<int> cacheIcon(String origin, Uint8List bytes) {
|
||||
return db.iconCache.insertOne(
|
||||
IconCacheCompanion.insert(
|
||||
origin: origin,
|
||||
iconData: bytes,
|
||||
fetchDate: DateTime.now(),
|
||||
),
|
||||
onConflict: DoUpdate(
|
||||
(old) => IconCacheCompanion.custom(
|
||||
iconData: Variable(bytes),
|
||||
fetchDate: Variable(DateTime.now()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'cache.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$CacheDaoMixin on DatabaseAccessor<UserDatabase> {}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/user/data/database/database.dart';
|
||||
|
||||
part 'setting.g.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class SettingDao extends DatabaseAccessor<UserDatabase> with _$SettingDaoMixin {
|
||||
SettingDao(super.attachedDatabase);
|
||||
|
||||
Future<int> updateSetting(String key, Object? value) {
|
||||
final driftvalue = (value != null) ? DriftAny(value) : null;
|
||||
|
||||
return db.setting.insertOne(
|
||||
SettingCompanion.insert(
|
||||
key: key,
|
||||
value: Value(driftvalue),
|
||||
),
|
||||
onConflict: DoUpdate(
|
||||
(old) => SettingCompanion.custom(value: Variable(driftvalue)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<MapEntry<String, DriftAny?>> allSettings() {
|
||||
return db.setting.select().map((row) => MapEntry(row.key, row.value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'setting.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$SettingDaoMixin on DatabaseAccessor<UserDatabase> {}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/features/user/data/database/daos/cache.dart';
|
||||
import 'package:lensai/features/user/data/database/daos/setting.dart';
|
||||
|
||||
part 'database.g.dart';
|
||||
|
||||
@DriftDatabase(include: {
|
||||
'database.drift'
|
||||
}, daos: [
|
||||
SettingDao,
|
||||
CacheDao,
|
||||
])
|
||||
class UserDatabase extends _$UserDatabase {
|
||||
@override
|
||||
final int schemaVersion = 1;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
beforeOpen: (details) async {
|
||||
await customStatement('PRAGMA foreign_keys = ON;');
|
||||
},
|
||||
);
|
||||
|
||||
UserDatabase(super.e);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
CREATE TABLE setting (
|
||||
"key" TEXT PRIMARY KEY NOT NULL,
|
||||
"value" ANY
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE icon_cache (
|
||||
origin TEXT PRIMARY KEY NOT NULL,
|
||||
icon_data BLOB NOT NULL,
|
||||
fetch_date DATETIME NOT NULL
|
||||
);
|
||||
|
||||
evictCacheEntries:
|
||||
DELETE FROM icon_cache
|
||||
WHERE rowid IN (
|
||||
SELECT rowid
|
||||
FROM icon_cache
|
||||
ORDER BY fetch_date DESC
|
||||
LIMIT -1 OFFSET :limit
|
||||
);
|
||||
@@ -0,0 +1,653 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'database.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
class Setting extends Table with TableInfo<Setting, SettingData> {
|
||||
@override
|
||||
final GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
Setting(this.attachedDatabase, [this._alias]);
|
||||
late final GeneratedColumn<String> key = GeneratedColumn<String>(
|
||||
'key', aliasedName, false,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'PRIMARY KEY NOT NULL');
|
||||
late final GeneratedColumn<DriftAny> value = GeneratedColumn<DriftAny>(
|
||||
'value', aliasedName, true,
|
||||
type: DriftSqlType.any,
|
||||
requiredDuringInsert: false,
|
||||
$customConstraints: '');
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [key, value];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
String get actualTableName => $name;
|
||||
static const String $name = 'setting';
|
||||
@override
|
||||
Set<GeneratedColumn> get $primaryKey => {key};
|
||||
@override
|
||||
SettingData map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return SettingData(
|
||||
key: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}key'])!,
|
||||
value: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.any, data['${effectivePrefix}value']),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Setting createAlias(String alias) {
|
||||
return Setting(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isStrict => true;
|
||||
@override
|
||||
bool get dontWriteConstraints => true;
|
||||
}
|
||||
|
||||
class SettingData extends DataClass implements Insertable<SettingData> {
|
||||
final String key;
|
||||
final DriftAny? value;
|
||||
const SettingData({required this.key, this.value});
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
map['key'] = Variable<String>(key);
|
||||
if (!nullToAbsent || value != null) {
|
||||
map['value'] = Variable<DriftAny>(value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
factory SettingData.fromJson(Map<String, dynamic> json,
|
||||
{ValueSerializer? serializer}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return SettingData(
|
||||
key: serializer.fromJson<String>(json['key']),
|
||||
value: serializer.fromJson<DriftAny?>(json['value']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'key': serializer.toJson<String>(key),
|
||||
'value': serializer.toJson<DriftAny?>(value),
|
||||
};
|
||||
}
|
||||
|
||||
SettingData copyWith(
|
||||
{String? key, Value<DriftAny?> value = const Value.absent()}) =>
|
||||
SettingData(
|
||||
key: key ?? this.key,
|
||||
value: value.present ? value.value : this.value,
|
||||
);
|
||||
SettingData copyWithCompanion(SettingCompanion data) {
|
||||
return SettingData(
|
||||
key: data.key.present ? data.key.value : this.key,
|
||||
value: data.value.present ? data.value.value : this.value,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('SettingData(')
|
||||
..write('key: $key, ')
|
||||
..write('value: $value')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(key, value);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is SettingData &&
|
||||
other.key == this.key &&
|
||||
other.value == this.value);
|
||||
}
|
||||
|
||||
class SettingCompanion extends UpdateCompanion<SettingData> {
|
||||
final Value<String> key;
|
||||
final Value<DriftAny?> value;
|
||||
final Value<int> rowid;
|
||||
const SettingCompanion({
|
||||
this.key = const Value.absent(),
|
||||
this.value = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
});
|
||||
SettingCompanion.insert({
|
||||
required String key,
|
||||
this.value = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : key = Value(key);
|
||||
static Insertable<SettingData> custom({
|
||||
Expression<String>? key,
|
||||
Expression<DriftAny>? value,
|
||||
Expression<int>? rowid,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (key != null) 'key': key,
|
||||
if (value != null) 'value': value,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
});
|
||||
}
|
||||
|
||||
SettingCompanion copyWith(
|
||||
{Value<String>? key, Value<DriftAny?>? value, Value<int>? rowid}) {
|
||||
return SettingCompanion(
|
||||
key: key ?? this.key,
|
||||
value: value ?? this.value,
|
||||
rowid: rowid ?? this.rowid,
|
||||
);
|
||||
}
|
||||
|
||||
@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<DriftAny>(value.value);
|
||||
}
|
||||
if (rowid.present) {
|
||||
map['rowid'] = Variable<int>(rowid.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('SettingCompanion(')
|
||||
..write('key: $key, ')
|
||||
..write('value: $value, ')
|
||||
..write('rowid: $rowid')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class IconCache extends Table with TableInfo<IconCache, IconCacheData> {
|
||||
@override
|
||||
final GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
IconCache(this.attachedDatabase, [this._alias]);
|
||||
late final GeneratedColumn<String> origin = GeneratedColumn<String>(
|
||||
'origin', aliasedName, false,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'PRIMARY KEY NOT NULL');
|
||||
late final GeneratedColumn<Uint8List> iconData = GeneratedColumn<Uint8List>(
|
||||
'icon_data', aliasedName, false,
|
||||
type: DriftSqlType.blob,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL');
|
||||
late final GeneratedColumn<DateTime> fetchDate = GeneratedColumn<DateTime>(
|
||||
'fetch_date', aliasedName, false,
|
||||
type: DriftSqlType.dateTime,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL');
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [origin, iconData, fetchDate];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
String get actualTableName => $name;
|
||||
static const String $name = 'icon_cache';
|
||||
@override
|
||||
Set<GeneratedColumn> get $primaryKey => {origin};
|
||||
@override
|
||||
IconCacheData map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return IconCacheData(
|
||||
origin: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}origin'])!,
|
||||
iconData: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.blob, data['${effectivePrefix}icon_data'])!,
|
||||
fetchDate: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.dateTime, data['${effectivePrefix}fetch_date'])!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
IconCache createAlias(String alias) {
|
||||
return IconCache(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get dontWriteConstraints => true;
|
||||
}
|
||||
|
||||
class IconCacheData extends DataClass implements Insertable<IconCacheData> {
|
||||
final String origin;
|
||||
final Uint8List iconData;
|
||||
final DateTime fetchDate;
|
||||
const IconCacheData(
|
||||
{required this.origin, required this.iconData, required this.fetchDate});
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
map['origin'] = Variable<String>(origin);
|
||||
map['icon_data'] = Variable<Uint8List>(iconData);
|
||||
map['fetch_date'] = Variable<DateTime>(fetchDate);
|
||||
return map;
|
||||
}
|
||||
|
||||
factory IconCacheData.fromJson(Map<String, dynamic> json,
|
||||
{ValueSerializer? serializer}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return IconCacheData(
|
||||
origin: serializer.fromJson<String>(json['origin']),
|
||||
iconData: serializer.fromJson<Uint8List>(json['icon_data']),
|
||||
fetchDate: serializer.fromJson<DateTime>(json['fetch_date']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'origin': serializer.toJson<String>(origin),
|
||||
'icon_data': serializer.toJson<Uint8List>(iconData),
|
||||
'fetch_date': serializer.toJson<DateTime>(fetchDate),
|
||||
};
|
||||
}
|
||||
|
||||
IconCacheData copyWith(
|
||||
{String? origin, Uint8List? iconData, DateTime? fetchDate}) =>
|
||||
IconCacheData(
|
||||
origin: origin ?? this.origin,
|
||||
iconData: iconData ?? this.iconData,
|
||||
fetchDate: fetchDate ?? this.fetchDate,
|
||||
);
|
||||
IconCacheData copyWithCompanion(IconCacheCompanion data) {
|
||||
return IconCacheData(
|
||||
origin: data.origin.present ? data.origin.value : this.origin,
|
||||
iconData: data.iconData.present ? data.iconData.value : this.iconData,
|
||||
fetchDate: data.fetchDate.present ? data.fetchDate.value : this.fetchDate,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('IconCacheData(')
|
||||
..write('origin: $origin, ')
|
||||
..write('iconData: $iconData, ')
|
||||
..write('fetchDate: $fetchDate')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(origin, $driftBlobEquality.hash(iconData), fetchDate);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is IconCacheData &&
|
||||
other.origin == this.origin &&
|
||||
$driftBlobEquality.equals(other.iconData, this.iconData) &&
|
||||
other.fetchDate == this.fetchDate);
|
||||
}
|
||||
|
||||
class IconCacheCompanion extends UpdateCompanion<IconCacheData> {
|
||||
final Value<String> origin;
|
||||
final Value<Uint8List> iconData;
|
||||
final Value<DateTime> fetchDate;
|
||||
final Value<int> rowid;
|
||||
const IconCacheCompanion({
|
||||
this.origin = const Value.absent(),
|
||||
this.iconData = const Value.absent(),
|
||||
this.fetchDate = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
});
|
||||
IconCacheCompanion.insert({
|
||||
required String origin,
|
||||
required Uint8List iconData,
|
||||
required DateTime fetchDate,
|
||||
this.rowid = const Value.absent(),
|
||||
}) : origin = Value(origin),
|
||||
iconData = Value(iconData),
|
||||
fetchDate = Value(fetchDate);
|
||||
static Insertable<IconCacheData> custom({
|
||||
Expression<String>? origin,
|
||||
Expression<Uint8List>? iconData,
|
||||
Expression<DateTime>? fetchDate,
|
||||
Expression<int>? rowid,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (origin != null) 'origin': origin,
|
||||
if (iconData != null) 'icon_data': iconData,
|
||||
if (fetchDate != null) 'fetch_date': fetchDate,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
});
|
||||
}
|
||||
|
||||
IconCacheCompanion copyWith(
|
||||
{Value<String>? origin,
|
||||
Value<Uint8List>? iconData,
|
||||
Value<DateTime>? fetchDate,
|
||||
Value<int>? rowid}) {
|
||||
return IconCacheCompanion(
|
||||
origin: origin ?? this.origin,
|
||||
iconData: iconData ?? this.iconData,
|
||||
fetchDate: fetchDate ?? this.fetchDate,
|
||||
rowid: rowid ?? this.rowid,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
if (origin.present) {
|
||||
map['origin'] = Variable<String>(origin.value);
|
||||
}
|
||||
if (iconData.present) {
|
||||
map['icon_data'] = Variable<Uint8List>(iconData.value);
|
||||
}
|
||||
if (fetchDate.present) {
|
||||
map['fetch_date'] = Variable<DateTime>(fetchDate.value);
|
||||
}
|
||||
if (rowid.present) {
|
||||
map['rowid'] = Variable<int>(rowid.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('IconCacheCompanion(')
|
||||
..write('origin: $origin, ')
|
||||
..write('iconData: $iconData, ')
|
||||
..write('fetchDate: $fetchDate, ')
|
||||
..write('rowid: $rowid')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _$UserDatabase extends GeneratedDatabase {
|
||||
_$UserDatabase(QueryExecutor e) : super(e);
|
||||
$UserDatabaseManager get managers => $UserDatabaseManager(this);
|
||||
late final Setting setting = Setting(this);
|
||||
late final IconCache iconCache = IconCache(this);
|
||||
late final SettingDao settingDao = SettingDao(this as UserDatabase);
|
||||
late final CacheDao cacheDao = CacheDao(this as UserDatabase);
|
||||
Future<int> evictCacheEntries({required int limit}) {
|
||||
return customUpdate(
|
||||
'DELETE FROM icon_cache WHERE "rowid" IN (SELECT "rowid" FROM icon_cache ORDER BY fetch_date DESC LIMIT -1 OFFSET ?1)',
|
||||
variables: [Variable<int>(limit)],
|
||||
updates: {iconCache},
|
||||
updateKind: UpdateKind.delete,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Iterable<TableInfo<Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
|
||||
@override
|
||||
List<DatabaseSchemaEntity> get allSchemaEntities => [setting, iconCache];
|
||||
}
|
||||
|
||||
typedef $SettingCreateCompanionBuilder = SettingCompanion Function({
|
||||
required String key,
|
||||
Value<DriftAny?> value,
|
||||
Value<int> rowid,
|
||||
});
|
||||
typedef $SettingUpdateCompanionBuilder = SettingCompanion Function({
|
||||
Value<String> key,
|
||||
Value<DriftAny?> value,
|
||||
Value<int> rowid,
|
||||
});
|
||||
|
||||
class $SettingFilterComposer extends Composer<_$UserDatabase, Setting> {
|
||||
$SettingFilterComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
ColumnFilters<String> get key => $composableBuilder(
|
||||
column: $table.key, builder: (column) => ColumnFilters(column));
|
||||
|
||||
ColumnFilters<DriftAny> get value => $composableBuilder(
|
||||
column: $table.value, builder: (column) => ColumnFilters(column));
|
||||
}
|
||||
|
||||
class $SettingOrderingComposer extends Composer<_$UserDatabase, Setting> {
|
||||
$SettingOrderingComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
ColumnOrderings<String> get key => $composableBuilder(
|
||||
column: $table.key, builder: (column) => ColumnOrderings(column));
|
||||
|
||||
ColumnOrderings<DriftAny> get value => $composableBuilder(
|
||||
column: $table.value, builder: (column) => ColumnOrderings(column));
|
||||
}
|
||||
|
||||
class $SettingAnnotationComposer extends Composer<_$UserDatabase, Setting> {
|
||||
$SettingAnnotationComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
GeneratedColumn<String> get key =>
|
||||
$composableBuilder(column: $table.key, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<DriftAny> get value =>
|
||||
$composableBuilder(column: $table.value, builder: (column) => column);
|
||||
}
|
||||
|
||||
class $SettingTableManager extends RootTableManager<
|
||||
_$UserDatabase,
|
||||
Setting,
|
||||
SettingData,
|
||||
$SettingFilterComposer,
|
||||
$SettingOrderingComposer,
|
||||
$SettingAnnotationComposer,
|
||||
$SettingCreateCompanionBuilder,
|
||||
$SettingUpdateCompanionBuilder,
|
||||
(SettingData, BaseReferences<_$UserDatabase, Setting, SettingData>),
|
||||
SettingData,
|
||||
PrefetchHooks Function()> {
|
||||
$SettingTableManager(_$UserDatabase db, Setting table)
|
||||
: super(TableManagerState(
|
||||
db: db,
|
||||
table: table,
|
||||
createFilteringComposer: () =>
|
||||
$SettingFilterComposer($db: db, $table: table),
|
||||
createOrderingComposer: () =>
|
||||
$SettingOrderingComposer($db: db, $table: table),
|
||||
createComputedFieldComposer: () =>
|
||||
$SettingAnnotationComposer($db: db, $table: table),
|
||||
updateCompanionCallback: ({
|
||||
Value<String> key = const Value.absent(),
|
||||
Value<DriftAny?> value = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) =>
|
||||
SettingCompanion(
|
||||
key: key,
|
||||
value: value,
|
||||
rowid: rowid,
|
||||
),
|
||||
createCompanionCallback: ({
|
||||
required String key,
|
||||
Value<DriftAny?> value = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) =>
|
||||
SettingCompanion.insert(
|
||||
key: key,
|
||||
value: value,
|
||||
rowid: rowid,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
.map((e) => (e.readTable(table), BaseReferences(db, table, e)))
|
||||
.toList(),
|
||||
prefetchHooksCallback: null,
|
||||
));
|
||||
}
|
||||
|
||||
typedef $SettingProcessedTableManager = ProcessedTableManager<
|
||||
_$UserDatabase,
|
||||
Setting,
|
||||
SettingData,
|
||||
$SettingFilterComposer,
|
||||
$SettingOrderingComposer,
|
||||
$SettingAnnotationComposer,
|
||||
$SettingCreateCompanionBuilder,
|
||||
$SettingUpdateCompanionBuilder,
|
||||
(SettingData, BaseReferences<_$UserDatabase, Setting, SettingData>),
|
||||
SettingData,
|
||||
PrefetchHooks Function()>;
|
||||
typedef $IconCacheCreateCompanionBuilder = IconCacheCompanion Function({
|
||||
required String origin,
|
||||
required Uint8List iconData,
|
||||
required DateTime fetchDate,
|
||||
Value<int> rowid,
|
||||
});
|
||||
typedef $IconCacheUpdateCompanionBuilder = IconCacheCompanion Function({
|
||||
Value<String> origin,
|
||||
Value<Uint8List> iconData,
|
||||
Value<DateTime> fetchDate,
|
||||
Value<int> rowid,
|
||||
});
|
||||
|
||||
class $IconCacheFilterComposer extends Composer<_$UserDatabase, IconCache> {
|
||||
$IconCacheFilterComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
ColumnFilters<String> get origin => $composableBuilder(
|
||||
column: $table.origin, builder: (column) => ColumnFilters(column));
|
||||
|
||||
ColumnFilters<Uint8List> get iconData => $composableBuilder(
|
||||
column: $table.iconData, builder: (column) => ColumnFilters(column));
|
||||
|
||||
ColumnFilters<DateTime> get fetchDate => $composableBuilder(
|
||||
column: $table.fetchDate, builder: (column) => ColumnFilters(column));
|
||||
}
|
||||
|
||||
class $IconCacheOrderingComposer extends Composer<_$UserDatabase, IconCache> {
|
||||
$IconCacheOrderingComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
ColumnOrderings<String> get origin => $composableBuilder(
|
||||
column: $table.origin, builder: (column) => ColumnOrderings(column));
|
||||
|
||||
ColumnOrderings<Uint8List> get iconData => $composableBuilder(
|
||||
column: $table.iconData, builder: (column) => ColumnOrderings(column));
|
||||
|
||||
ColumnOrderings<DateTime> get fetchDate => $composableBuilder(
|
||||
column: $table.fetchDate, builder: (column) => ColumnOrderings(column));
|
||||
}
|
||||
|
||||
class $IconCacheAnnotationComposer extends Composer<_$UserDatabase, IconCache> {
|
||||
$IconCacheAnnotationComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
GeneratedColumn<String> get origin =>
|
||||
$composableBuilder(column: $table.origin, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<Uint8List> get iconData =>
|
||||
$composableBuilder(column: $table.iconData, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<DateTime> get fetchDate =>
|
||||
$composableBuilder(column: $table.fetchDate, builder: (column) => column);
|
||||
}
|
||||
|
||||
class $IconCacheTableManager extends RootTableManager<
|
||||
_$UserDatabase,
|
||||
IconCache,
|
||||
IconCacheData,
|
||||
$IconCacheFilterComposer,
|
||||
$IconCacheOrderingComposer,
|
||||
$IconCacheAnnotationComposer,
|
||||
$IconCacheCreateCompanionBuilder,
|
||||
$IconCacheUpdateCompanionBuilder,
|
||||
(IconCacheData, BaseReferences<_$UserDatabase, IconCache, IconCacheData>),
|
||||
IconCacheData,
|
||||
PrefetchHooks Function()> {
|
||||
$IconCacheTableManager(_$UserDatabase db, IconCache table)
|
||||
: super(TableManagerState(
|
||||
db: db,
|
||||
table: table,
|
||||
createFilteringComposer: () =>
|
||||
$IconCacheFilterComposer($db: db, $table: table),
|
||||
createOrderingComposer: () =>
|
||||
$IconCacheOrderingComposer($db: db, $table: table),
|
||||
createComputedFieldComposer: () =>
|
||||
$IconCacheAnnotationComposer($db: db, $table: table),
|
||||
updateCompanionCallback: ({
|
||||
Value<String> origin = const Value.absent(),
|
||||
Value<Uint8List> iconData = const Value.absent(),
|
||||
Value<DateTime> fetchDate = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) =>
|
||||
IconCacheCompanion(
|
||||
origin: origin,
|
||||
iconData: iconData,
|
||||
fetchDate: fetchDate,
|
||||
rowid: rowid,
|
||||
),
|
||||
createCompanionCallback: ({
|
||||
required String origin,
|
||||
required Uint8List iconData,
|
||||
required DateTime fetchDate,
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) =>
|
||||
IconCacheCompanion.insert(
|
||||
origin: origin,
|
||||
iconData: iconData,
|
||||
fetchDate: fetchDate,
|
||||
rowid: rowid,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
.map((e) => (e.readTable(table), BaseReferences(db, table, e)))
|
||||
.toList(),
|
||||
prefetchHooksCallback: null,
|
||||
));
|
||||
}
|
||||
|
||||
typedef $IconCacheProcessedTableManager = ProcessedTableManager<
|
||||
_$UserDatabase,
|
||||
IconCache,
|
||||
IconCacheData,
|
||||
$IconCacheFilterComposer,
|
||||
$IconCacheOrderingComposer,
|
||||
$IconCacheAnnotationComposer,
|
||||
$IconCacheCreateCompanionBuilder,
|
||||
$IconCacheUpdateCompanionBuilder,
|
||||
(IconCacheData, BaseReferences<_$UserDatabase, IconCache, IconCacheData>),
|
||||
IconCacheData,
|
||||
PrefetchHooks Function()>;
|
||||
|
||||
class $UserDatabaseManager {
|
||||
final _$UserDatabase _db;
|
||||
$UserDatabaseManager(this._db);
|
||||
$SettingTableManager get setting => $SettingTableManager(_db, _db.setting);
|
||||
$IconCacheTableManager get iconCache =>
|
||||
$IconCacheTableManager(_db, _db.iconCache);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'settings.g.dart';
|
||||
|
||||
@CopyWith()
|
||||
@JsonSerializable(includeIfNull: true, constructor: 'withDefaults')
|
||||
class Settings with FastEquatable {
|
||||
final bool incognitoMode;
|
||||
final bool enableJavascript;
|
||||
final bool blockHttpProtocol;
|
||||
final ThemeMode themeMode;
|
||||
final bool enableReadability;
|
||||
|
||||
Settings({
|
||||
required this.incognitoMode,
|
||||
required this.enableJavascript,
|
||||
required this.blockHttpProtocol,
|
||||
required this.themeMode,
|
||||
required this.enableReadability,
|
||||
});
|
||||
|
||||
Settings.withDefaults({
|
||||
bool? incognitoMode,
|
||||
bool? enableJavascript,
|
||||
bool? blockHttpProtocol,
|
||||
ThemeMode? themeMode,
|
||||
bool? enableReadability,
|
||||
}) : incognitoMode = incognitoMode ?? true,
|
||||
enableJavascript = enableJavascript ?? true,
|
||||
blockHttpProtocol = blockHttpProtocol ?? false,
|
||||
themeMode = themeMode ?? ThemeMode.dark,
|
||||
enableReadability = enableReadability ?? true;
|
||||
|
||||
factory Settings.fromJson(Map<String, dynamic> json) =>
|
||||
_$SettingsFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SettingsToJson(this);
|
||||
|
||||
@override
|
||||
bool get cacheHash => true;
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
incognitoMode,
|
||||
enableJavascript,
|
||||
blockHttpProtocol,
|
||||
themeMode,
|
||||
enableReadability,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$SettingsCWProxy {
|
||||
Settings incognitoMode(bool incognitoMode);
|
||||
|
||||
Settings enableJavascript(bool enableJavascript);
|
||||
|
||||
Settings blockHttpProtocol(bool blockHttpProtocol);
|
||||
|
||||
Settings themeMode(ThemeMode themeMode);
|
||||
|
||||
Settings enableReadability(bool enableReadability);
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// Settings(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
Settings call({
|
||||
bool incognitoMode,
|
||||
bool enableJavascript,
|
||||
bool blockHttpProtocol,
|
||||
ThemeMode themeMode,
|
||||
bool enableReadability,
|
||||
});
|
||||
}
|
||||
|
||||
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSettings.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSettings.copyWith.fieldName(...)`
|
||||
class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
||||
const _$SettingsCWProxyImpl(this._value);
|
||||
|
||||
final Settings _value;
|
||||
|
||||
@override
|
||||
Settings incognitoMode(bool incognitoMode) =>
|
||||
this(incognitoMode: incognitoMode);
|
||||
|
||||
@override
|
||||
Settings enableJavascript(bool enableJavascript) =>
|
||||
this(enableJavascript: enableJavascript);
|
||||
|
||||
@override
|
||||
Settings blockHttpProtocol(bool blockHttpProtocol) =>
|
||||
this(blockHttpProtocol: blockHttpProtocol);
|
||||
|
||||
@override
|
||||
Settings themeMode(ThemeMode themeMode) => this(themeMode: themeMode);
|
||||
|
||||
@override
|
||||
Settings enableReadability(bool enableReadability) =>
|
||||
this(enableReadability: enableReadability);
|
||||
|
||||
@override
|
||||
|
||||
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Settings(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||
///
|
||||
/// Usage
|
||||
/// ```dart
|
||||
/// Settings(...).copyWith(id: 12, name: "My name")
|
||||
/// ````
|
||||
Settings call({
|
||||
Object? incognitoMode = const $CopyWithPlaceholder(),
|
||||
Object? enableJavascript = const $CopyWithPlaceholder(),
|
||||
Object? blockHttpProtocol = const $CopyWithPlaceholder(),
|
||||
Object? themeMode = const $CopyWithPlaceholder(),
|
||||
Object? enableReadability = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return Settings(
|
||||
incognitoMode: incognitoMode == const $CopyWithPlaceholder()
|
||||
? _value.incognitoMode
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: incognitoMode as bool,
|
||||
enableJavascript: enableJavascript == const $CopyWithPlaceholder()
|
||||
? _value.enableJavascript
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: enableJavascript as bool,
|
||||
blockHttpProtocol: blockHttpProtocol == const $CopyWithPlaceholder()
|
||||
? _value.blockHttpProtocol
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: blockHttpProtocol as bool,
|
||||
themeMode: themeMode == const $CopyWithPlaceholder()
|
||||
? _value.themeMode
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: themeMode as ThemeMode,
|
||||
enableReadability: enableReadability == const $CopyWithPlaceholder()
|
||||
? _value.enableReadability
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: enableReadability as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $SettingsCopyWith on Settings {
|
||||
/// Returns a callable class that can be used as follows: `instanceOfSettings.copyWith(...)` or like so:`instanceOfSettings.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$SettingsCWProxy get copyWith => _$SettingsCWProxyImpl(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Settings _$SettingsFromJson(Map<String, dynamic> json) => Settings.withDefaults(
|
||||
incognitoMode: json['incognitoMode'] as bool?,
|
||||
enableJavascript: json['enableJavascript'] as bool?,
|
||||
blockHttpProtocol: json['blockHttpProtocol'] as bool?,
|
||||
themeMode: $enumDecodeNullable(_$ThemeModeEnumMap, json['themeMode']),
|
||||
enableReadability: json['enableReadability'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
|
||||
'incognitoMode': instance.incognitoMode,
|
||||
'enableJavascript': instance.enableJavascript,
|
||||
'blockHttpProtocol': instance.blockHttpProtocol,
|
||||
'themeMode': _$ThemeModeEnumMap[instance.themeMode]!,
|
||||
'enableReadability': instance.enableReadability,
|
||||
};
|
||||
|
||||
const _$ThemeModeEnumMap = {
|
||||
ThemeMode.system: 'system',
|
||||
ThemeMode.light: 'light',
|
||||
ThemeMode.dark: 'dark',
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:lensai/features/user/data/database/database.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:riverpod/riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
UserDatabase userDatabase(Ref ref) {
|
||||
return UserDatabase(
|
||||
LazyDatabase(() async {
|
||||
// put the database file, called db.sqlite here, into the documents folder
|
||||
// for your app.
|
||||
final dbFolder = await path_provider.getApplicationDocumentsDirectory();
|
||||
final file = File(p.join(dbFolder.path, 'user.db'));
|
||||
|
||||
// Also work around limitations on old Android versions
|
||||
if (Platform.isAndroid) {
|
||||
await applyWorkaroundToOpenSqlite3OnOldAndroidVersions();
|
||||
}
|
||||
|
||||
// Make sqlite3 pick a more suitable location for temporary files - the
|
||||
// one from the system may be inaccessible due to sandboxing.
|
||||
final cachebase = (await path_provider.getTemporaryDirectory()).path;
|
||||
// We can't access /tmp on Android, which sqlite3 would try by default.
|
||||
// Explicitly tell it about the correct temporary directory.
|
||||
sqlite3.tempDirectory = cachebase;
|
||||
|
||||
return NativeDatabase.createInBackground(file);
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$userDatabaseHash() => r'a84f951e1673e34b6857e1618cd7d80497c6f3a1';
|
||||
|
||||
/// See also [userDatabase].
|
||||
@ProviderFor(userDatabase)
|
||||
final userDatabaseProvider = Provider<UserDatabase>.internal(
|
||||
userDatabase,
|
||||
name: r'userDatabaseProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$userDatabaseHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef UserDatabaseRef = ProviderRef<UserDatabase>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
Reference in New Issue
Block a user