fix(import): add AddAccount to tx
This commit is contained in:
parent
655d0d6c44
commit
2e89310129
@ -186,6 +186,16 @@ namespace PluralKit.Core
|
|||||||
return await conn.ExecuteAsync(query.Sql + $" {extraSql}", query.NamedBindings);
|
return await conn.ExecuteAsync(query.Sql + $" {extraSql}", query.NamedBindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> ExecuteQuery(IPKConnection? conn, Query q, string extraSql = "", [CallerMemberName] string queryName = "")
|
||||||
|
{
|
||||||
|
if (conn == null)
|
||||||
|
return await ExecuteQuery(q, extraSql, queryName);
|
||||||
|
|
||||||
|
var query = _compiler.Compile(q);
|
||||||
|
using (_metrics.Measure.Timer.Time(CoreMetrics.DatabaseQuery, new MetricTags("Query", queryName)))
|
||||||
|
return await conn.ExecuteAsync(query.Sql + $" {extraSql}", query.NamedBindings);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "")
|
public async Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "")
|
||||||
{
|
{
|
||||||
var query = _compiler.Compile(q);
|
var query = _compiler.Compile(q);
|
||||||
|
@ -15,6 +15,7 @@ namespace PluralKit.Core
|
|||||||
Task<T> Execute<T>(Func<IPKConnection, Task<T>> func);
|
Task<T> Execute<T>(Func<IPKConnection, Task<T>> func);
|
||||||
IAsyncEnumerable<T> Execute<T>(Func<IPKConnection, IAsyncEnumerable<T>> func);
|
IAsyncEnumerable<T> Execute<T>(Func<IPKConnection, IAsyncEnumerable<T>> func);
|
||||||
Task<int> ExecuteQuery(Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
Task<int> ExecuteQuery(Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
||||||
|
Task<int> ExecuteQuery(IPKConnection? conn, Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
||||||
Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
Task<T> QueryFirst<T>(Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
||||||
Task<T> QueryFirst<T>(IPKConnection? conn, Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
Task<T> QueryFirst<T>(IPKConnection? conn, Query q, string extraSql = "", [CallerMemberName] string queryName = "");
|
||||||
Task<IEnumerable<T>> Query<T>(Query q, [CallerMemberName] string queryName = "");
|
Task<IEnumerable<T>> Query<T>(Query q, [CallerMemberName] string queryName = "");
|
||||||
|
@ -88,7 +88,7 @@ namespace PluralKit.Core
|
|||||||
return _db.QueryFirst<PKSystem>(conn, query, extraSql: "returning *");
|
return _db.QueryFirst<PKSystem>(conn, query, extraSql: "returning *");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task AddAccount(SystemId system, ulong accountId)
|
public Task AddAccount(SystemId system, ulong accountId, IPKConnection? conn = null)
|
||||||
{
|
{
|
||||||
// We have "on conflict do nothing" since linking an account when it's already linked to the same system is idempotent
|
// We have "on conflict do nothing" since linking an account when it's already linked to the same system is idempotent
|
||||||
// This is used in import/export, although the pk;link command checks for this case beforehand
|
// This is used in import/export, although the pk;link command checks for this case beforehand
|
||||||
@ -100,7 +100,7 @@ namespace PluralKit.Core
|
|||||||
});
|
});
|
||||||
|
|
||||||
_logger.Information("Linked account {UserId} to {SystemId}", accountId, system);
|
_logger.Information("Linked account {UserId} to {SystemId}", accountId, system);
|
||||||
return _db.ExecuteQuery(query, extraSql: "on conflict do nothing");
|
return _db.ExecuteQuery(conn, query, extraSql: "on conflict do nothing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveAccount(SystemId system, ulong accountId)
|
public async Task RemoveAccount(SystemId system, ulong accountId)
|
||||||
|
@ -49,7 +49,7 @@ namespace PluralKit.Core
|
|||||||
if (system == null)
|
if (system == null)
|
||||||
{
|
{
|
||||||
system = await repo.CreateSystem(null, importer._conn);
|
system = await repo.CreateSystem(null, importer._conn);
|
||||||
await repo.AddAccount(system.Id, userId);
|
await repo.AddAccount(system.Id, userId, importer._conn);
|
||||||
importer._result.CreatedSystem = system.Hid;
|
importer._result.CreatedSystem = system.Hid;
|
||||||
importer._system = system;
|
importer._system = system;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user