Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ linter:
constant_identifier_names: false
prefer_final_locals: true
prefer_final_in_for_each: true
require_trailing_commas: true
# require_trailing_commas: true // causes issues with dart 3.7
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

Expand Down
87 changes: 87 additions & 0 deletions lib/db/drift/database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2025 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2025-05-06
*
*/

import 'dart:async';

import 'package:drift/drift.dart';
import 'package:drift_flutter/drift_flutter.dart';
import 'package:path/path.dart' as path;

import '../../utilities/stack_file_system.dart';

part 'database.g.dart';

abstract final class Drift {
static bool _didInit = false;

static final Map<String, WalletDatabase> _map = {};

static WalletDatabase get(String walletId) {
if (!_didInit) {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
_didInit = true;
}

return _map[walletId] ??= WalletDatabase._(walletId);
}
}

class SparkNames extends Table {
TextColumn get name =>
text().customConstraint("UNIQUE NOT NULL COLLATE NOCASE")();
TextColumn get address => text()();
IntColumn get validUntil => integer()();
TextColumn get additionalInfo => text().nullable()();

@override
Set<Column> get primaryKey => {name};
}

@DriftDatabase(tables: [SparkNames])
final class WalletDatabase extends _$WalletDatabase {
WalletDatabase._(String walletId, [QueryExecutor? executor])
: super(executor ?? _openConnection(walletId));

@override
int get schemaVersion => 1;

static QueryExecutor _openConnection(String walletId) {
return driftDatabase(
name: walletId,
native: DriftNativeOptions(
shareAcrossIsolates: true,
databasePath: () async {
final dir = await StackFileSystem.applicationDriftDirectory();
return path.join(dir.path, "wallets", walletId, "$walletId.db");
},
),
);
}

Future<void> upsertSparkNames(
List<
({String name, String address, int validUntil, String? additionalInfo})
>
names,
) async {
await transaction(() async {
for (final name in names) {
await into(sparkNames).insertOnConflictUpdate(
SparkNamesCompanion(
name: Value(name.name),
address: Value(name.address),
validUntil: Value(name.validUntil),
additionalInfo: Value(name.additionalInfo),
),
);
}
});
}
}
Loading
Loading