Created
March 17, 2021 07:27
-
-
Save Jacknq/9a70984d2e43441848658215e73dc354 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Text.Json.Serialization; | |
using Couchbase; | |
using Couchbase.Linq; | |
using Newtonsoft.Json; | |
using couch; | |
using Couchbase.Linq.QueryGeneration; | |
using Couchbase.Linq.QueryGeneration.MemberNameResolvers; | |
using Couchbase.Linq.Utils; | |
using Couchbase.Linq.Versioning; | |
//using Couchbase..Query; | |
using System.Linq; | |
using Microsoft.Extensions.Logging; | |
using Newtonsoft.Json; | |
namespace couch | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
runCouch(); | |
} | |
static void runCouch() | |
{ | |
var options = new ClusterOptions() | |
.WithConnectionString("http://localhost") | |
.WithCredentials(username: "Administrator", | |
password: "password") | |
.AddLinq() | |
.WithLogging(LoggerFactory.Create(builder => | |
{ | |
builder.AddFilter("Couchbase", LogLevel.Debug); | |
})); | |
// var cluster =await Cluster | |
// .ConnectAsync("couchbase://localhost:11210",options); | |
var cluster = Cluster.ConnectAsync(options) | |
.GetAwaiter() | |
.GetResult(); | |
// var b = cluster.Buckets.GetAllBucketsAsync().GetAwaiter().GetResult(); | |
// Console.WriteLine("b count {0}",b.Count); | |
// cluster.Start(); | |
// Wait until the cluster is bootstrapped | |
// await cluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10)); | |
Console.WriteLine("connect done"); | |
var context = new BucketContext( | |
cluster.BucketAsync("travel-sample") | |
.GetAwaiter().GetResult()); | |
var query = (from a in context.Query<Airline>() | |
where a.Country == "United Kingdom" | |
select a) | |
.Take(10); | |
foreach (var airline in query.ToList()) | |
{ | |
Console.WriteLine(airline.Name); | |
} | |
} | |
} | |
public class Airline | |
{ | |
[Newtonsoft.Json.JsonIgnore] | |
public string Id { get; set; } | |
[JsonProperty("type")] | |
public string Type { get; set; } | |
[JsonProperty("name")] | |
public string Name { get; set; } | |
[JsonProperty("iata")] | |
public string Iata { get; set; } | |
[JsonProperty("icao")] | |
public string Icao { get; set; } | |
[JsonProperty("callsign")] | |
public string Callsign { get; set; } | |
[JsonProperty("country")] | |
public string Country { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment