@@ -11,20 +11,20 @@ namespace GitTrends
11
11
{
12
12
public abstract class BaseDatabase
13
13
{
14
+ readonly SQLiteAsyncConnection _databaseConnection ;
15
+
14
16
protected BaseDatabase ( IFileSystem fileSystem , IAnalyticsService analyticsService , TimeSpan expiresAt )
15
17
{
16
18
ExpiresAt = expiresAt ;
17
19
AnalyticsService = analyticsService ;
18
20
19
21
var databasePath = Path . Combine ( fileSystem . AppDataDirectory , $ "{ nameof ( GitTrends ) } .db3") ;
20
- DatabaseConnection = new SQLiteAsyncConnection ( databasePath , SQLiteOpenFlags . ReadWrite | SQLiteOpenFlags . Create | SQLiteOpenFlags . SharedCache ) ;
22
+ _databaseConnection = new SQLiteAsyncConnection ( databasePath , SQLiteOpenFlags . ReadWrite | SQLiteOpenFlags . Create | SQLiteOpenFlags . SharedCache ) ;
21
23
}
22
24
23
25
public TimeSpan ExpiresAt { get ; }
24
26
protected IAnalyticsService AnalyticsService { get ; }
25
27
26
- SQLiteAsyncConnection DatabaseConnection { get ; }
27
-
28
28
public abstract Task < int > DeleteAllData ( ) ;
29
29
30
30
protected static Task < T > AttemptAndRetry < T > ( Func < Task < T > > action , int numRetries = 12 )
@@ -38,22 +38,22 @@ protected static Task<T> AttemptAndRetry<T>(Func<Task<T>> action, int numRetries
38
38
39
39
protected async ValueTask < SQLiteAsyncConnection > GetDatabaseConnection < T > ( )
40
40
{
41
- if ( ! DatabaseConnection . TableMappings . Any ( x => x . MappedType == typeof ( T ) ) )
41
+ if ( ! _databaseConnection . TableMappings . Any ( x => x . MappedType == typeof ( T ) ) )
42
42
{
43
- await DatabaseConnection . EnableWriteAheadLoggingAsync ( ) . ConfigureAwait ( false ) ;
43
+ await _databaseConnection . EnableWriteAheadLoggingAsync ( ) . ConfigureAwait ( false ) ;
44
44
45
45
try
46
46
{
47
- await DatabaseConnection . CreateTablesAsync ( CreateFlags . None , typeof ( T ) ) . ConfigureAwait ( false ) ;
47
+ await _databaseConnection . CreateTablesAsync ( CreateFlags . None , typeof ( T ) ) . ConfigureAwait ( false ) ;
48
48
}
49
49
catch ( SQLiteException e ) when ( e . Message . Contains ( "PRIMARY KEY" , StringComparison . OrdinalIgnoreCase ) )
50
50
{
51
- await DatabaseConnection . DropTableAsync ( DatabaseConnection . TableMappings . First ( x => x . MappedType == typeof ( T ) ) ) ;
52
- await DatabaseConnection . CreateTablesAsync ( CreateFlags . None , typeof ( T ) ) . ConfigureAwait ( false ) ;
51
+ await _databaseConnection . DropTableAsync ( _databaseConnection . TableMappings . First ( x => x . MappedType == typeof ( T ) ) ) ;
52
+ await _databaseConnection . CreateTablesAsync ( CreateFlags . None , typeof ( T ) ) . ConfigureAwait ( false ) ;
53
53
}
54
54
}
55
55
56
- return DatabaseConnection ;
56
+ return _databaseConnection ;
57
57
}
58
58
}
59
59
}
0 commit comments