@@ -16,41 +16,44 @@ public MySqlEffectsStore(string connectionString, string tablePrefix = "")
16
16
_tablePrefix = tablePrefix ;
17
17
}
18
18
19
+ private string ? _initializeSql ;
19
20
public async Task Initialize ( )
20
21
{
21
22
await using var conn = await CreateConnection ( ) ;
22
- var sql = @$ "
23
+ _initializeSql ?? = @$ "
23
24
CREATE TABLE IF NOT EXISTS { _tablePrefix } rfunction_effects (
24
25
id VARCHAR(450) PRIMARY KEY,
25
26
status INT NOT NULL,
26
27
result TEXT NULL,
27
28
exception TEXT NULL
28
29
);" ;
29
- var command = new MySqlCommand ( sql , conn ) ;
30
+ var command = new MySqlCommand ( _initializeSql , conn ) ;
30
31
await command . ExecuteNonQueryAsync ( ) ;
31
32
}
32
33
34
+ private string ? _truncateSql ;
33
35
public async Task Truncate ( )
34
36
{
35
37
await using var conn = await CreateConnection ( ) ;
36
- var sql = $ "TRUNCATE TABLE { _tablePrefix } rfunction_effects";
37
- var command = new MySqlCommand ( sql , conn ) ;
38
+ _truncateSql ?? = $ "TRUNCATE TABLE { _tablePrefix } rfunction_effects";
39
+ var command = new MySqlCommand ( _truncateSql , conn ) ;
38
40
await command . ExecuteNonQueryAsync ( ) ;
39
41
}
40
42
43
+ private string ? _setEffectResultSql ;
41
44
public async Task SetEffectResult ( FunctionId functionId , StoredEffect storedEffect )
42
45
{
43
46
var ( functionTypeId , functionInstanceId ) = functionId ;
44
47
await using var conn = await CreateConnection ( ) ;
45
- var sql = $@ "
48
+ _setEffectResultSql ?? = $@ "
46
49
INSERT INTO { _tablePrefix } rfunction_effects
47
50
(id, status, result, exception)
48
51
VALUES
49
52
(?, ?, ?, ?)
50
53
ON DUPLICATE KEY UPDATE
51
54
status = VALUES(status), result = VALUES(result), exception = VALUES(exception)" ;
52
55
53
- await using var command = new MySqlCommand ( sql , conn )
56
+ await using var command = new MySqlCommand ( _setEffectResultSql , conn )
54
57
{
55
58
Parameters =
56
59
{
@@ -64,14 +67,15 @@ ON DUPLICATE KEY UPDATE
64
67
await command . ExecuteNonQueryAsync ( ) ;
65
68
}
66
69
70
+ private string ? _getEffectResultsSql ;
67
71
public async Task < IEnumerable < StoredEffect > > GetEffectResults ( FunctionId functionId )
68
72
{
69
73
await using var conn = await CreateConnection ( ) ;
70
- var sql = @$ "
74
+ _getEffectResultsSql ?? = @$ "
71
75
SELECT id, status, result, exception
72
76
FROM { _tablePrefix } rfunction_effects
73
77
WHERE id LIKE ?" ;
74
- await using var command = new MySqlCommand ( sql , conn )
78
+ await using var command = new MySqlCommand ( _getEffectResultsSql , conn )
75
79
{
76
80
Parameters =
77
81
{
@@ -95,25 +99,27 @@ public async Task<IEnumerable<StoredEffect>> GetEffectResults(FunctionId functio
95
99
return functions ;
96
100
}
97
101
102
+ private string ? _deleteEffectResultSql ;
98
103
public async Task DeleteEffectResult ( FunctionId functionId , EffectId effectId )
99
104
{
100
105
await using var conn = await CreateConnection ( ) ;
101
- var sql = $ "DELETE FROM { _tablePrefix } rfunction_effects WHERE id = ?";
106
+ _deleteEffectResultSql ?? = $ "DELETE FROM { _tablePrefix } rfunction_effects WHERE id = ?";
102
107
var id = Escaper . Escape ( functionId . TypeId . Value , functionId . InstanceId . Value , effectId . Value ) ;
103
- await using var command = new MySqlCommand ( sql , conn )
108
+ await using var command = new MySqlCommand ( _deleteEffectResultSql , conn )
104
109
{
105
110
Parameters = { new ( ) { Value = id } }
106
111
} ;
107
112
108
113
await command . ExecuteNonQueryAsync ( ) ;
109
114
}
110
115
116
+ private string ? _removeSql ;
111
117
public async Task Remove ( FunctionId functionId )
112
118
{
113
119
await using var conn = await CreateConnection ( ) ;
114
- var sql = $ "DELETE FROM { _tablePrefix } rfunction_effects WHERE id LIKE ?";
120
+ _removeSql ?? = $ "DELETE FROM { _tablePrefix } rfunction_effects WHERE id LIKE ?";
115
121
var id = Escaper . Escape ( functionId . TypeId . Value , functionId . InstanceId . Value ) + $ "{ Escaper . Separator } %" ;
116
- await using var command = new MySqlCommand ( sql , conn )
122
+ await using var command = new MySqlCommand ( _removeSql , conn )
117
123
{
118
124
Parameters = { new ( ) { Value = id } }
119
125
} ;
0 commit comments