2021-01-11 17:58:56 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2021-09-30 22:42:40 +08:00
|
|
|
using System;
|
2021-01-11 17:58:56 +08:00
|
|
|
using Realms;
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
{
|
|
|
|
public static class RealmExtensions
|
|
|
|
{
|
2021-09-30 22:42:40 +08:00
|
|
|
public static void Write(this Realm realm, Action<Realm> function)
|
2021-01-11 17:58:56 +08:00
|
|
|
{
|
2021-09-30 22:42:40 +08:00
|
|
|
using var transaction = realm.BeginWrite();
|
|
|
|
function(realm);
|
|
|
|
transaction.Commit();
|
2021-01-11 18:46:51 +08:00
|
|
|
}
|
|
|
|
|
2021-09-30 22:42:40 +08:00
|
|
|
public static T Write<T>(this Realm realm, Func<Realm, T> function)
|
2021-01-11 17:58:56 +08:00
|
|
|
{
|
2021-09-30 22:42:40 +08:00
|
|
|
using var transaction = realm.BeginWrite();
|
|
|
|
var result = function(realm);
|
|
|
|
transaction.Commit();
|
|
|
|
return result;
|
2021-01-11 17:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|