Skip to content

Commit

Permalink
Merge branch 'release/3.4' into dispose-things
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardSmedley authored Jun 3, 2024
2 parents bcb0f03 + ca2dbe4 commit 0fff633
Show file tree
Hide file tree
Showing 17 changed files with 1,560 additions and 2,895 deletions.
437 changes: 437 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@ title: ".NET SDK"
start_page: hello-world:overview.adoc
nav:
- modules/ROOT/nav.adoc
server_version: '7.1'
asciidoc:
attributes:
server_version: '7.2'
sdk_current_version: '3.4.14'
sdk_dot_minor: 3.4
sdk_dot_major: 3.x
version-server: '7.2'
version-common: '7.2'
name_platform: '.NET'
name-sdk: '.NET SDK'
sdk_api: '3.4'
sdk-api-link: https://docs.couchbase.com/sdk-api/couchbase-net-client/
sdk-gh-link: https://github.com/couchbase/couchbase-net-client/

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Couchbase;
using Couchbase.KeyValue;
using Couchbase.KeyValue.RangeScan;
using Serilog;
using Serilog.Extensions.Logging;

Serilog.Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Information()
.WriteTo.Console()
.CreateLogger();

var clusterOptions = new ClusterOptions()
{
ConnectionString = "couchbase://localhost",
UserName = "Administrator",
Password = "password",
EnableDnsSrvResolution = false,
};

clusterOptions = clusterOptions.WithLogging(new SerilogLoggerFactory());

var exampleCluster = await Cluster.ConnectAsync(clusterOptions);
await exampleCluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10));
var travelSample = await exampleCluster.BucketAsync("travel-sample");
var inventoryScope = travelSample.Scope("inventory");
await Task.Delay(1000);

await RangeScanAllDocuments(inventoryScope);
await RangeScanPrefixScan(inventoryScope);

async Task RangeScanAllDocuments(IScope scope)
{
var collection = scope.Collection("hotel");
// tag::rangeScanAllDocuments[]
IAsyncEnumerable<IScanResult> results = collection.ScanAsync(new RangeScan());

await foreach (var scanResult in results)
{
Log.Information(scanResult.Id);
Log.Information(scanResult.ContentAs<Hotel>().ToString());
}

// alternate declaration
var scan2 = new RangeScan(from: ScanTerm.Inclusive("id001"), to: ScanTerm.Inclusive("id999"));
// end::rangeScanAllDocuments[]
}

async Task RangeScanPrefixScan(IScope scope)
{
var collection = scope.Collection("hotel");
// tag::rangeScanPrefix[]
IAsyncEnumerable<IScanResult> results = collection.ScanAsync(
new PrefixScan("alice::")
);

await foreach (var scanResult in results)
{
Log.Information(scanResult.Id);
}
// end::rangeScanPrefix[]
}

async Task RangeScanSamplingScan(IScope scope)
{
var collection = scope.Collection("hotel");
// tag::rangeScanSample[]
IAsyncEnumerable<IScanResult> results = collection.ScanAsync(
new SamplingScan(limit: 100)
);

await foreach (var scanResult in results)
{
Log.Information(scanResult.Id);
}
// end::rangeScanSample[]
}
async Task RangeScanAllDocumentIds(IScope scope)
{
var collection = scope.Collection("hotel");
// tag::rangeScanAllDocumentIds[]
IAsyncEnumerable<IScanResult> results = collection.ScanAsync(
new RangeScan(),
new ScanOptions().IdsOnly(true));

await foreach (var scanResult in results)
{
Log.Information(scanResult.Id);
}
// end::rangeScanAllDocumentIds[]
}

record Hotel(string name, string title, string address);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\..\couchbase-net-client\src\Couchbase\Couchbase.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Couchbase;
using Couchbase.Core.Exceptions.KeyValue;
using Couchbase.KeyValue;

var clusterOptions = new ClusterOptions()
{
ConnectionString = "couchbase://localhost",
UserName = "Administrator",
Password = "password",
EnableDnsSrvResolution = false,
};

var exampleCluster = await Cluster.ConnectAsync(clusterOptions);
await exampleCluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10));
var travelSample = await exampleCluster.BucketAsync("travel-sample");
var inventoryScope = travelSample.Scope("inventory");
await Task.Delay(1000);

await LookupInAnyReplica(travelSample.DefaultCollection());
await LookupInAllReplicas(travelSample.DefaultCollection());

async Task LookupInAnyReplica(ICouchbaseCollection collection)
{
// tag::lookup-in-any-replica[]
try
{
var result = await collection.LookupInAnyReplicaAsync(
"hotel_10138",
specs => specs.Get("geo.lat")
);

var geoLat = result.ContentAs<string>(0);
Console.Out.WriteLine($"getFunc: Latitude={geoLat}");
}
catch (PathNotFoundException)
{
Console.Error.WriteLine("The version of the document" +
" on the server node that responded quickest" +
" did not have the requested field.");
}
catch (DocumentUnretrievableException)
{
Console.Error.WriteLine("Document was not present" +
" on any server node");
}
// end::lookup-in-any-replica[]
}

async Task LookupInAllReplicas(ICouchbaseCollection collection)
{
// tag::lookup-in-all-replicas[]
IAsyncEnumerable<ILookupInResult> result = collection.LookupInAllReplicasAsync(
"hotel_10138",
specs => specs.Get("geo.lat"));

await foreach (var replicaResult in result)
{
try
{
var geoLat = replicaResult.ContentAs<string>(0);
Console.Out.WriteLine($"getFunc: Latitude={geoLat}");
}
catch (PathNotFoundException)
{
Console.Error.WriteLine("The version of the document" +
" on the server node that responded quickest" +
" did not have the requested field.");
}
}
// end::lookup-in-all-replicas[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\couchbase-net-client\src\Couchbase\Couchbase.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 0fff633

Please sign in to comment.