Skip to content

Commit eae3e0f

Browse files
AUTO: Sync ScalarDB docs in English to docs site repo (#648)
Co-authored-by: josh-wong <[email protected]>
1 parent 5ce3c21 commit eae3e0f

8 files changed

+171
-78
lines changed

docs/scalardb-cluster-dotnet-client-sdk/common-reference.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ options.HopLimit = 10;
102102
var factory = TransactionFactory.Create(options);
103103
```
104104

105-
If you use the SDK with ASP.NET Core, a lambda function of `AddScalarDbCluster` and/or `AddScalarDbContext` can be used as follows:
105+
If you use the SDK with ASP.NET Core, a lambda function of `AddScalarDb` and/or `AddScalarDbContext` can be used as follows:
106106

107107
```c#
108108
var builder = WebApplication.CreateBuilder(args);
109109

110110
//...
111111
112-
builder.Services.AddScalarDbCluster(options =>
112+
builder.Services.AddScalarDb(options =>
113113
{
114114
options.Address = "http://localhost:60053";
115115
options.HopLimit = 10;

docs/scalardb-cluster-dotnet-client-sdk/getting-started-with-admin-api.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ var namespaceExists = await admin.IsNamespacePresentAsync("ns");
7373
### Create a new table
7474

7575
```c#
76-
using Scalar.Db.Cluster.Rpc.V1;
7776
// ...
78-
using ScalarDB.Client.Builders;
77+
using ScalarDB.Client.Builders.Admin;
78+
using ScalarDB.Client.Core;
7979

8080
// ...
8181

docs/scalardb-cluster-dotnet-client-sdk/getting-started-with-aspnet-and-di.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For details about settings files and other ways to configure the client, see [Cl
3333

3434
## Set up the transaction managers
3535

36-
You can register the ScalarDB Cluster transaction managers as services in `IServiceCollection` as follows:
36+
You can register the ScalarDB transaction managers as services in `IServiceCollection` as follows:
3737

3838
```c#
3939
using ScalarDB.Client.Extensions;
@@ -44,7 +44,7 @@ var builder = WebApplication.CreateBuilder(args);
4444

4545
//...
4646
47-
builder.Services.AddScalarDbCluster();
47+
builder.Services.AddScalarDb();
4848
```
4949

5050
After registering the transaction managers, they can be injected into the controller's constructor as follows:

docs/scalardb-cluster-dotnet-client-sdk/getting-started-with-distributed-sql-transactions.mdx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ using var manager = factory.GetSqlTransactionManager();
5151

5252
## Execute SQL queries
5353

54-
To execute a SQL statement, you need a `SqlStatement` object, which can be created by using a builder as follows:
54+
To execute a SQL statement, you need an `ISqlStatement` object, which can be created by using a builder as follows:
5555

5656
```c#
57-
using ScalarDB.Client.Builders;
57+
using ScalarDB.Client.Builders.Sql;
5858

5959
// ...
6060
@@ -71,13 +71,9 @@ A single SQL statement can be executed directly by using the transaction manager
7171
var resultSet = await manager.ExecuteAsync(sqlStatement);
7272
```
7373

74-
The result from the `ExecuteAsync` method will contain records received from the cluster. The SDK has `GetValue`, `TryGetValue`, and `IsNull` extension methods to simplify using the records:
74+
The result from the `ExecuteAsync` method will contain records received from the cluster. The value of the specific column can be retrieved in the following manner:
7575

7676
```c#
77-
using ScalarDB.Client.Extensions;
78-
79-
// ...
80-
8177
foreach (var record in resultSet.Records)
8278
{
8379
// Getting an integer value from the "item_id" column.

docs/scalardb-cluster-dotnet-client-sdk/getting-started-with-distributed-transactions.mdx

Lines changed: 137 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ using var manager = factory.GetTransactionManager();
5252

5353
## Manage transactions
5454

55-
To execute CRUD operations, a transaction is needed. You can begin a transaction by using the transaction manager as follows:
55+
To execute multiple CRUD operations as part of a single transaction, first, you need to begin a transaction. You can begin a transaction by using the transaction manager as follows:
5656

5757
```c#
5858
var transaction = await manager.BeginAsync();
@@ -84,9 +84,15 @@ await transaction.RollbackAsync();
8484

8585
## Execute CRUD operations
8686

87-
A transaction has `GetAsync`, `ScanAsync`, `PutAsync`, `DeleteAsync`, and `MutateAsync` methods to execute CRUD commands against the cluster. As a parameter, these methods have a command object. A command object can be created by using the builders listed in this section.
87+
A transaction has `GetAsync`, `ScanAsync`, `InsertAsync`, `UpsertAsync`, `UpdateAsync`, `DeleteAsync`, and `MutateAsync` methods to execute CRUD operations against the cluster. As a parameter, these methods have an operation object. An operation object can be created by using the builders listed in this section.
8888

89-
To use these builders add the following namespace to the `using` section:
89+
:::note
90+
91+
CRUD operations can be executed in a one-shot transaction manner without needing to explicitly create a transaction. For that, a manager object has the same CRUD methods as a transaction object.
92+
93+
:::
94+
95+
To use builders, add the following namespace to the `using` section:
9096

9197
```c#
9298
using ScalarDB.Client.Builders;
@@ -100,16 +106,13 @@ The cluster does not support parallel execution of commands inside one transacti
100106

101107
### `GetAsync` method example
102108

103-
```c#
104-
using GetTypeEnum = Scalar.Db.Cluster.Rpc.V1.Get.Types.GetType;
105-
106-
// ...
109+
To retrieve a single record, you can use the `GetAsync` method as follows:
107110

111+
```c#
108112
var get =
109113
new GetBuilder()
110114
.SetNamespaceName("ns")
111115
.SetTableName("statements")
112-
.SetGetType(GetTypeEnum.Get)
113116
.AddPartitionKey("order_id", "1")
114117
.AddClusteringKey("item_id", 2)
115118
.SetProjections("item_id", "count")
@@ -118,15 +121,44 @@ var get =
118121
var getResult = await transaction.GetAsync(get);
119122
```
120123

121-
#### Handle `Result` objects
122-
123-
The `GetAsync` and `ScanAsync` methods return `Result` objects. The SDK has `GetValue`, `TryGetValue`, and `IsNull` extension methods to simplify using them:
124+
It is possible to retrieve a record by using an index instead of a partition key. To do that, you need to set the type of operation to `GetWithIndex` as follows:
124125

125126
```c#
126-
using ScalarDB.Client.Extensions;
127+
// ...
128+
using ScalarDB.Client.Core;
127129

128130
// ...
129131
132+
var get =
133+
new GetBuilder()
134+
// ...
135+
.SetGetType(GetOperationType.GetWithIndex)
136+
.AddPartitionKey("index_column", "1")
137+
.Build();
138+
```
139+
140+
You can also specify arbitrary conditions that a retrieved record must meet, or it won't be returned. The conditions can be set as conjunctions of conditions as follows:
141+
142+
```c#
143+
var get =
144+
new GetBuilder()
145+
// ...
146+
.AddConjunction(c => c.AddCondition("cost", 1000, Operator.LessThan))
147+
.AddConjunction(c =>
148+
{
149+
c.AddCondition("cost", 10000, Operator.LessThan);
150+
c.AddCondition("in_stock", true, Operator.Equal);
151+
})
152+
.Build();
153+
```
154+
155+
In the above example, a record will be returned only if its `cost` is less than `1000`, or if its `cost` is less than `10000` and `in_stock` is true.
156+
157+
#### Handle `IResult` objects
158+
159+
The `GetAsync` and `ScanAsync` methods return `IResult` objects. An `IResult` object contains columns of the retrieved record. The value of the specific column can be retrieved in the following manner:
160+
161+
```c#
130162
// Getting an integer value from the "item_id" column.
131163
// If it fails, an exception will be thrown.
132164
var itemId = result.GetValue<int>("item_id");
@@ -145,16 +177,13 @@ For details about which type should be used in `GetValue<T>` and `TryGetValue<T>
145177

146178
### `ScanAsync` method example
147179

148-
```c#
149-
using static Scalar.Db.Cluster.Rpc.V1.Scan.Types;
150-
151-
// ..
180+
To retrieve a range of records, you can use the `ScanAsync` method as follows:
152181

182+
```c#
153183
var scan =
154184
new ScanBuilder()
155185
.SetNamespaceName("ns")
156186
.SetTableName("statements")
157-
.SetScanType(ScanType.Scan)
158187
.AddPartitionKey("order_id", "1")
159188
.AddStartClusteringKey("item_id", 2)
160189
.SetStartInclusive(true)
@@ -166,58 +195,134 @@ var scan =
166195
var scanResult = await transaction.ScanAsync(scan);
167196
```
168197

169-
### `PutAsync` method example
198+
It is possible to retrieve a record by using an index instead of a partition key. To do that, you need to set the type of operation to `ScanWithIndex` as follows:
199+
200+
```c#
201+
// ...
202+
using ScalarDB.Client.Core;
203+
204+
// ...
205+
206+
var scan =
207+
new ScanBuilder()
208+
// ...
209+
.SetScanType(ScanOperationType.ScanWithIndex)
210+
.AddPartitionKey("index_column", "1")
211+
.Build();
212+
```
213+
214+
The arbitrary conditions that a retrieved record must meet can also be set for a scan operation in the same way as for a [get operation](getting-started-with-distributed-transactions.mdx#getasync-method-example).
215+
216+
### `InsertAsync` method example
217+
218+
To insert a new record, you can use the `InsertAsync` method as follows:
170219

171220
```c#
172-
var put =
173-
new PutBuilder()
221+
var insert =
222+
new InsertBuilder()
174223
.SetNamespaceName("ns")
175224
.SetTableName("statements")
176225
.AddPartitionKey("order_id", "1")
177226
.AddClusteringKey("item_id", 2)
178227
.AddColumn("count", 11)
179228
.Build();
180229

181-
await client.PutAsync(put);
230+
await transaction.InsertAsync(insert);
182231
```
183232

184-
### `DeleteAsync` method example
233+
### `UpsertAsync` method example
234+
235+
To upsert a record (update an existing record or insert a new one), you can use the `UpsertAsync` method as follows:
185236

186237
```c#
187-
var delete =
188-
new DeleteBuilder()
238+
var upsert =
239+
new UpsertBuilder()
189240
.SetNamespaceName("ns")
190241
.SetTableName("statements")
191242
.AddPartitionKey("order_id", "1")
192243
.AddClusteringKey("item_id", 2)
244+
.AddColumn("count", 11)
193245
.Build();
194246

195-
await client.DeleteAsync(delete);
247+
await transaction.UpsertAsync(upsert);
196248
```
197249

198-
### `MutateAsync` method example:
250+
### `UpdateAsync` method example
251+
252+
To update an existing record, you can use the `UpdateAsync` method as follows:
199253

200254
```c#
201-
using Scalar.Db.Cluster.Rpc.V1;
255+
// ...
256+
using ScalarDB.Client.Core;
202257

203258
// ...
204259
205-
var put =
206-
new PutBuilder()
260+
var update =
261+
new UpdateBuilder()
207262
.SetNamespaceName("ns")
208263
.SetTableName("statements")
209264
.AddPartitionKey("order_id", "1")
210265
.AddClusteringKey("item_id", 2)
211266
.AddColumn("count", 11)
267+
.AddCondition("processed", false, Operator.Equal)
268+
.Build();
269+
270+
await transaction.UpdateAsync(update);
271+
```
272+
273+
### `DeleteAsync` method example
274+
275+
To delete a record, you can use the `DeleteAsync` method as follows:
276+
277+
```c#
278+
// ...
279+
using ScalarDB.Client.Core;
280+
281+
// ...
282+
283+
var delete =
284+
new DeleteBuilder()
285+
.SetNamespaceName("ns")
286+
.SetTableName("statements")
287+
.AddPartitionKey("order_id", "1")
288+
.AddClusteringKey("item_id", 2)
289+
.AddCondition("processed", false, Operator.Equal)
212290
.Build();
213291

214-
var mutate = new Mutation { Put = put };
292+
await transaction.DeleteAsync(delete);
293+
```
294+
295+
### `MutateAsync` method example
296+
297+
The `MutateAsync` method allows you to execute more than one mutation operation in a single call to the cluster. You can do this in the following manner:
298+
299+
```c#
300+
// ...
301+
using ScalarDB.Client.Core;
302+
303+
// ...
215304
216-
await client.MutateAsync(new[] { mutate });
305+
var mutations = new IMutation[]
306+
{
307+
new InsertBuilder()
308+
// ...
309+
.Build(),
310+
new UpsertBuilder()
311+
// ...
312+
.Build(),
313+
new UpdateBuilder()
314+
// ...
315+
.Build(),
316+
new DeleteBuilder()
317+
// ...
318+
.Build()
319+
};
320+
321+
await transaction.MutateAsync(mutations);
217322
```
218323

219324
:::note
220325

221-
To modify data by using the `PutAsync`, `DeleteAsync`, or `MutateAsync` method, the data must be retrieved first by using the `GetAsync` or `ScanAsync` method.
326+
To modify data by using the `InsertAsync`, `UpsertAsync`, `UpdateAsync`, `DeleteAsync`, or `MutateAsync` method, the data must be retrieved first by using the `GetAsync` or `ScanAsync` method.
222327

223328
:::

0 commit comments

Comments
 (0)