-
Notifications
You must be signed in to change notification settings - Fork 7
Add sample application for ScalarDB Cluster .NET Client SDK (SQL) #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/GetCustomerInfoCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System.CommandLine; | ||
|
|
||
| namespace ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| public static class GetCustomerInfoCommand | ||
| { | ||
| private const string Name = "GetCustomerInfo"; | ||
| private const string Description = "Get customer information"; | ||
|
|
||
| private const string ArgName = "id"; | ||
| private const string ArgDescription = "customer ID"; | ||
|
|
||
| public static Command Create() | ||
| { | ||
| var customerIdArg = new Argument<int>(ArgName, ArgDescription); | ||
| var getCustomerInfoCommand = new Command(Name, Description) | ||
| { | ||
| customerIdArg | ||
| }; | ||
|
|
||
| getCustomerInfoCommand.SetHandler(async customerId => | ||
| { | ||
| using var sample = new Sample(); | ||
| var customerInfo = await sample.GetCustomerInfo(customerId); | ||
|
|
||
| Console.WriteLine(customerInfo); | ||
| }, customerIdArg); | ||
|
|
||
| return getCustomerInfoCommand; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/GetOrderCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System.CommandLine; | ||
|
|
||
| namespace ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| public static class GetOrderCommand | ||
| { | ||
| private const string Name = "GetOrder"; | ||
| private const string Description = "Get order information by order ID"; | ||
|
|
||
| private const string ArgName = "id"; | ||
| private const string ArgDescription = "order ID"; | ||
|
|
||
| public static Command Create() | ||
| { | ||
| var orderIdArg = new Argument<string>(ArgName, ArgDescription); | ||
| var getOrderCommand = new Command(Name, Description) | ||
| { | ||
| orderIdArg | ||
| }; | ||
|
|
||
| getOrderCommand.SetHandler(async orderId => | ||
| { | ||
| using var sample = new Sample(); | ||
| var order = await sample.GetOrderByOrderId(orderId); | ||
|
|
||
| Console.WriteLine(order); | ||
| }, orderIdArg); | ||
|
|
||
| return getOrderCommand; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/GetOrdersCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System.CommandLine; | ||
|
|
||
| namespace ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| public static class GetOrdersCommand | ||
| { | ||
| private const string Name = "GetOrders"; | ||
| private const string Description = "Get information about orders by customer ID"; | ||
|
|
||
| private const string ArgName = "customer_id"; | ||
| private const string ArgDescription = "customer ID"; | ||
|
|
||
| public static Command Create() | ||
| { | ||
| var customerIdArg = new Argument<int>(ArgName, ArgDescription); | ||
| var getOrdersCommand = new Command(Name, Description) | ||
| { | ||
| customerIdArg | ||
| }; | ||
|
|
||
| getOrdersCommand.SetHandler(async customerId => | ||
| { | ||
| using var sample = new Sample(); | ||
| var orders = await sample.GetOrdersByCustomerId(customerId); | ||
|
|
||
| Console.WriteLine(orders); | ||
| }, customerIdArg); | ||
|
|
||
| return getOrdersCommand; | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/LoadInitialDataCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using System.CommandLine; | ||
| using ScalarDB.Client.Exceptions; | ||
|
|
||
| namespace ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| public static class LoadInitialDataCommand | ||
| { | ||
| private const string Name = "LoadInitialData"; | ||
| private const string Description = "Load initial data"; | ||
|
|
||
| public static Command Create() | ||
| { | ||
| var loadInitialDataCommand = new Command(Name, Description); | ||
| loadInitialDataCommand.SetHandler(async () => | ||
| { | ||
| using var sample = new Sample(); | ||
| await sample.CreateTables(); | ||
|
|
||
| var attempts = 10; | ||
| while (attempts-- > 0) | ||
| { | ||
| try | ||
| { | ||
| await sample.LoadInitialData(); | ||
| return; | ||
| } | ||
| catch (IllegalArgumentException) | ||
| { | ||
| // there's can be a lag until ScalarDB Cluster recognize namespaces and tables created | ||
| // in some databases like Cassandra, so if this command was called for the first time | ||
| // the first attempts can fail with 'The namespace does not exist' error | ||
|
|
||
| await Task.Delay(TimeSpan.FromSeconds(1)); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return loadInitialDataCommand; | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/PlaceOrderCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System.CommandLine; | ||
|
|
||
| namespace ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| public static class PlaceOrderCommand | ||
| { | ||
| private const string Name = "PlaceOrder"; | ||
| private const string Description = "Place an order"; | ||
|
|
||
| private const string ArgName1 = "customer_id"; | ||
| private const string ArgDescription1 = "customer ID"; | ||
| private const string ArgName2 = "orders"; | ||
| private const string ArgDescription2 = "orders. The format is \"<Item ID>:<Count>,<Item ID>:<Count>,...\""; | ||
|
|
||
| public static Command Create() | ||
| { | ||
| var customerIdArg = new Argument<int>(ArgName1, ArgDescription1); | ||
| var ordersArg = new Argument<Dictionary<int, int>>( | ||
| name: ArgName2, | ||
| parse: arg => | ||
| { | ||
| var argStr = arg.Tokens.First().Value; | ||
| var orders = argStr | ||
| .Split(',') | ||
| .Select(s => s.Split(':')) | ||
| .ToDictionary( | ||
| s => Int32.Parse(s[0]), | ||
| s => Int32.Parse(s[1]) | ||
| ); | ||
|
|
||
| return orders; | ||
| }, | ||
| description: ArgDescription2) | ||
| { | ||
| Arity = ArgumentArity.ExactlyOne | ||
| }; | ||
|
|
||
| var placeOrderCommand = new Command(Name, Description) | ||
| { | ||
| customerIdArg, | ||
| ordersArg | ||
| }; | ||
|
|
||
| placeOrderCommand.SetHandler(async (customerId, orders) => | ||
| { | ||
| using var sample = new Sample(); | ||
| var order = await sample.PlaceOrder(customerId, orders); | ||
|
|
||
| Console.WriteLine(order); | ||
| }, customerIdArg, ordersArg); | ||
|
|
||
| return placeOrderCommand; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Commands/RepaymentCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System.CommandLine; | ||
|
|
||
| namespace ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| public static class RepaymentCommand | ||
| { | ||
| private const string Name = "Repayment"; | ||
| private const string Description = "Repayment"; | ||
|
|
||
| private const string ArgName1 = "customer_id"; | ||
| private const string ArgDescription1 = "customer ID"; | ||
| private const string ArgName2 = "amount"; | ||
| private const string ArgDescription2 = "amount of the money for repayment"; | ||
|
|
||
| public static Command Create() | ||
| { | ||
| var customerIdArg = new Argument<int>(ArgName1, ArgDescription1); | ||
| var amountArg = new Argument<int>(ArgName2, ArgDescription2); | ||
| var repaymentCommand = new Command(Name, Description) | ||
| { | ||
| customerIdArg, | ||
| amountArg | ||
| }; | ||
|
|
||
| repaymentCommand.SetHandler(async (customerId, amount) => | ||
| { | ||
| using var sample = new Sample(); | ||
| await sample.Repayment(customerId, amount); | ||
| }, customerIdArg, amountArg); | ||
|
|
||
| return repaymentCommand; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
scalardb-dotnet-samples/scalardb-cluster-sql-sample/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.CommandLine; | ||
| using ScalarDbClusterSqlSample.Commands; | ||
|
|
||
| var rootCommand = new RootCommand("Sample application for ScalarDB Cluster .NET Client SDK") | ||
| { | ||
| LoadInitialDataCommand.Create(), | ||
| GetCustomerInfoCommand.Create(), | ||
| GetOrderCommand.Create(), | ||
| GetOrdersCommand.Create(), | ||
| PlaceOrderCommand.Create(), | ||
| RepaymentCommand.Create() | ||
| }; | ||
|
|
||
| await rootCommand.InvokeAsync(args); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an error handling for retry-over is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@komamitsu what kind of error handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception should be thrown when the retry is over. Without any exception, users won't know what is happening when facing failures in the following commands.