Skip to content

Commit 38621e5

Browse files
Create GetFromDBMethod.cs
1 parent d916f2a commit 38621e5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 GetFromDBMethod : ReturningMethod, ICanError
10+
{
11+
public override string Description => "Returns the value of a given key in the database.";
12+
13+
public override Type[]? ReturnTypes => null;
14+
15+
public string[] ErrorReasons =>
16+
[
17+
"Provided key does not exist in the database."
18+
];
19+
20+
public override Argument[] ExpectedArguments =>
21+
[
22+
new DatabaseArgument("database"),
23+
new TextArgument("key")
24+
];
25+
26+
public override void Execute()
27+
{
28+
if (Args.GetDatabase("database").Get(Args.GetText("key")).HasErrored(out var err, out var value))
29+
{
30+
throw new ScriptRuntimeError(err);
31+
}
32+
33+
ReturnValue = value;
34+
}
35+
}

0 commit comments

Comments
 (0)