-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/3.4' into dispose-things
- Loading branch information
Showing
17 changed files
with
1,560 additions
and
2,895 deletions.
There are no files selected for viewing
This file contains 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
93 changes: 93 additions & 0 deletions
93
modules/howtos/examples/Couchbase.Examples.KV/RangeScan/RangeScan/Program.cs
This file contains 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,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); |
19 changes: 19 additions & 0 deletions
19
modules/howtos/examples/Couchbase.Examples.KV/RangeScan/RangeScan/RangeScan.csproj
This file contains 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,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> |
71 changes: 71 additions & 0 deletions
71
modules/howtos/examples/Couchbase.Examples.KV/SubDocument/Program.cs
This file contains 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,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[] | ||
} |
14 changes: 14 additions & 0 deletions
14
modules/howtos/examples/Couchbase.Examples.KV/SubDocument/SubDocument.csproj
This file contains 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 @@ | ||
<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> |
Oops, something went wrong.