491fae10f5
BREAKING CHANGE: DNS and NTP override toggles are removed; picked keys apply to every profile Changelog: Per-key DNS, NTP, sniffer and TUN settings
87 lines
2.3 KiB
Dart
87 lines
2.3 KiB
Dart
part of 'database.dart';
|
|
|
|
@DataClassName('RawCustomProxy')
|
|
class CustomProxies extends Table {
|
|
@override
|
|
String get tableName => 'custom_proxies';
|
|
|
|
IntColumn get id => integer()();
|
|
|
|
TextColumn get definition => text().map(const JsonMapConverter())();
|
|
|
|
TextColumn get order => text().nullable()();
|
|
|
|
TextColumn get emptyOptions =>
|
|
text().map(const StringSetConverter()).nullable()();
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {id};
|
|
}
|
|
|
|
@DriftAccessor(tables: [CustomProxies])
|
|
class CustomProxiesDao extends DatabaseAccessor<Database>
|
|
with _$CustomProxiesDaoMixin {
|
|
CustomProxiesDao(super.attachedDatabase);
|
|
|
|
Selectable<CustomProxy> query() {
|
|
return customProxies.readable(
|
|
(row) => row.toCustomProxy(),
|
|
orderBy: [
|
|
(t) => OrderingTerm(expression: t.order, nulls: NullsOrder.last),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<int> order({required CustomProxy proxy, required String order}) {
|
|
return customProxies.insertOnConflictUpdate(proxy.toCompanion(order));
|
|
}
|
|
|
|
void setAllWithBatch(Batch batch, Iterable<CustomProxy> items) {
|
|
final keys = indexing.generateNKeys(items.length);
|
|
customProxies.setAll(
|
|
batch,
|
|
items.mapIndexed((index, item) => item.toCompanion(keys[index])),
|
|
deleteFilter: (_) => const Constant(true),
|
|
preDelete: true,
|
|
);
|
|
}
|
|
|
|
Future<void> delAll(Iterable<int> ids) {
|
|
return batch((b) {
|
|
customProxies.deleteInChunks(b, ids, (t, chunk) => t.id.isIn(chunk));
|
|
});
|
|
}
|
|
|
|
void putAllWithBatch(Batch batch, Iterable<CustomProxy> items) {
|
|
batch.insertAllOnConflictUpdate(
|
|
customProxies,
|
|
items.map((item) => item.toCompanion()),
|
|
);
|
|
}
|
|
}
|
|
|
|
extension RawCustomProxyExt on RawCustomProxy {
|
|
CustomProxy toCustomProxy() {
|
|
final fields = ProxyField.values.asNameMap();
|
|
return CustomProxy(
|
|
id: id,
|
|
definition: definition,
|
|
order: order,
|
|
emptyOptions: {
|
|
for (final name in emptyOptions ?? const {}) ?fields[name],
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
extension CustomProxiesCompanionExt on CustomProxy {
|
|
CustomProxiesCompanion toCompanion([String? order]) {
|
|
return CustomProxiesCompanion.insert(
|
|
id: Value(id),
|
|
definition: definition,
|
|
order: Value(order ?? this.order),
|
|
emptyOptions: Value({for (final field in emptyOptions) field.name}),
|
|
);
|
|
}
|
|
}
|