Skip to content

Commit 2ace6ff

Browse files
Create AppendDBMethod.cs
1 parent b71b0b9 commit 2ace6ff

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.Exceptions;
4+
using SER.MethodSystem.BaseMethods;
5+
using SER.MethodSystem.MethodDescriptors;
6+
7+
namespace SER.MethodSystem.Methods.DatabaseMethods;
8+
9+
public class AppendDBMethod : SynchronousMethod, ICanError
10+
{
11+
public override string Description => "Adds a key-value pair to the database.";
12+
13+
public string[] ErrorReasons =>
14+
[
15+
"Provided value cannot be stored in databases"
16+
];
17+
18+
public override Argument[] ExpectedArguments =>
19+
[
20+
new DatabaseArgument("database"),
21+
new TextArgument("key"),
22+
new AnyValueArgument("value")
23+
];
24+
25+
public override void Execute()
26+
{
27+
if (Args.GetDatabase("database").Set(
28+
Args.GetText("key"),
29+
Args.GetAnyValue("value")
30+
).HasErrored(out var error))
31+
throw new ScriptRuntimeError(error);
32+
}
33+
}

0 commit comments

Comments
 (0)