Skip to content

Commit ae6e18f

Browse files
authored
Merge pull request #45 MakeTablePath, CopyTable, CopyTables, DescribeTable methods for TableClient
2 parents 037f303 + 54a5d69 commit ae6e18f

File tree

8 files changed

+834
-0
lines changed

8 files changed

+834
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Added MakeTablePath, CopyTable, CopyTables, DescribeTable methods for TableClient
12
- Add logging for transactions
23

34
## v0.1.5

src/Ydb.Sdk/src/Driver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class Driver : IDisposable, IAsyncDisposable
1919
private readonly ChannelsCache _channels;
2020
private bool _disposed;
2121

22+
internal string Database => _config.Database;
23+
2224
public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null)
2325
{
2426
LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using Ydb.Sdk.Client;
2+
using Ydb.Table;
3+
using Ydb.Table.V1;
4+
5+
namespace Ydb.Sdk.Services.Table;
6+
7+
public class CopyTableItem
8+
{
9+
public string SourcePath { get; }
10+
public string DestinationPath { get; }
11+
public bool OmitIndexes { get; }
12+
13+
public CopyTableItem(string sourcePath, string destinationPath, bool omitIndexes)
14+
{
15+
SourcePath = sourcePath;
16+
DestinationPath = destinationPath;
17+
OmitIndexes = omitIndexes;
18+
}
19+
20+
public Ydb.Table.CopyTableItem GetProto(TableClient tableClient)
21+
{
22+
return new Ydb.Table.CopyTableItem
23+
{
24+
SourcePath = tableClient.MakeTablePath(SourcePath),
25+
DestinationPath = tableClient.MakeTablePath(DestinationPath),
26+
OmitIndexes = OmitIndexes
27+
};
28+
}
29+
}
30+
31+
public class CopyTableSettings : OperationRequestSettings
32+
{
33+
}
34+
35+
public class CopyTablesSettings : OperationRequestSettings
36+
{
37+
}
38+
39+
public class CopyTableResponse : ResponseBase
40+
{
41+
internal CopyTableResponse(Status status) : base(status)
42+
{
43+
}
44+
}
45+
46+
public class CopyTablesResponse : ResponseBase
47+
{
48+
internal CopyTablesResponse(Status status) : base(status)
49+
{
50+
}
51+
}
52+
53+
public partial class TableClient
54+
{
55+
public async Task<CopyTableResponse> CopyTable(string sourcePath, string destinationPath,
56+
CopyTableSettings? settings = null)
57+
{
58+
settings ??= new CopyTableSettings();
59+
var request = new CopyTableRequest
60+
{
61+
OperationParams = MakeOperationParams(settings),
62+
SourcePath = MakeTablePath(sourcePath),
63+
DestinationPath = MakeTablePath(destinationPath)
64+
};
65+
66+
try
67+
{
68+
var response = await Driver.UnaryCall(
69+
method: TableService.CopyTableMethod,
70+
request: request,
71+
settings: settings);
72+
73+
var status = UnpackOperation(response.Data.Operation);
74+
return new CopyTableResponse(status);
75+
}
76+
catch (Driver.TransportException e)
77+
{
78+
return new CopyTableResponse(e.Status);
79+
}
80+
}
81+
82+
public async Task<CopyTablesResponse> CopyTables(List<CopyTableItem> tableItems,
83+
CopyTablesSettings? settings = null)
84+
{
85+
settings ??= new CopyTablesSettings();
86+
var request = new CopyTablesRequest
87+
{
88+
OperationParams = MakeOperationParams(settings)
89+
};
90+
request.Tables.AddRange(tableItems.Select(item => item.GetProto(this)));
91+
92+
try
93+
{
94+
var response = await Driver.UnaryCall(
95+
method: TableService.CopyTablesMethod,
96+
request: request,
97+
settings: settings);
98+
99+
var status = UnpackOperation(response.Data.Operation);
100+
return new CopyTablesResponse(status);
101+
}
102+
catch (Driver.TransportException e)
103+
{
104+
return new CopyTablesResponse(e.Status);
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)