本文整理汇总了C#中Couchbase.N1QL.QueryRequest类的典型用法代码示例。如果您正苦于以下问题:C# QueryRequest类的具体用法?C# QueryRequest怎么用?C# QueryRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryRequest类属于Couchbase.N1QL命名空间,在下文中一共展示了QueryRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindAll
public object FindAll(string search, string token)
{
if (search.Length == 3)
{
// LAX
var query =
new QueryRequest("SELECT airportname FROM `" + CouchbaseConfigHelper.Instance.Bucket + "` WHERE faa=$1")
.AddPositionalParameter(search.ToUpper());
return CouchbaseStorageHelper.Instance.ExecuteQuery(query).Rows;
}
else if (search.Length == 4)
{
// KLAX
var query =
new QueryRequest("SELECT airportname FROM `" + CouchbaseConfigHelper.Instance.Bucket + "` WHERE icao = '$1'")
.AddPositionalParameter(search.ToUpper());
return CouchbaseStorageHelper.Instance.ExecuteQuery(query).Rows;
}
else
{
// Los Angeles
var query =
new QueryRequest("SELECT airportname FROM `" + CouchbaseConfigHelper.Instance.Bucket + "` WHERE airportname LIKE $1")
.AddPositionalParameter("%" + search + "%");
return CouchbaseStorageHelper.Instance.ExecuteQuery(query).Rows;
}
}
示例2: ReplayMessagesAsync
public override Task ReplayMessagesAsync(string persistenceId, long fromSequenceNr, long toSequenceNr, long max, Action<IPersistentRepresentation> replayCallback)
{
// Limit(0) doesn't work...
if (max == 0)
return Task.Run(() => {});
// Limit allows only integer
var maxValue = max >= int.MaxValue ? int.MaxValue : (int)max;
var sender = Context.Sender;
String N1QLQueryString = "SELECT `" + _CBBucket.Name + "`.* FROM `" + _CBBucket.Name + "` WHERE PersistenceId = $PersistenceId AND SequenceNr >= $FromSequenceNr AND SequenceNr <= $ToSequenceNr ORDER BY SequenceNr ASC LIMIT $Maximum";
IQueryRequest N1QLQueryRequest = new QueryRequest()
.Statement(N1QLQueryString)
.AddNamedParameter("PersistenceId", persistenceId)
.AddNamedParameter("FromSequenceNr", fromSequenceNr)
.AddNamedParameter("ToSequenceNr", toSequenceNr)
.AddNamedParameter("Maximum", maxValue)
.AdHoc(false);
Couchbase.N1QL.IQueryResult<JournalEntry> result = _CBBucket.Query<JournalEntry>(N1QLQueryRequest);
return result.Rows.ForEachAsync<JournalEntry>(je => replayCallback(ToPersistanceRepresentation(je, sender)));
}
示例3: LoadAsync
protected override Task<SelectedSnapshot> LoadAsync(string persistenceId, SnapshotSelectionCriteria criteria)
{
// Create a Query with dynamic parameters
string N1QLQueryString = "select `" + _CBBucket.Name + "`.* from `" + _CBBucket.Name + "` where DocumentType = 'SnapshotEntry' AND PersistenceId = $PersistenceId ";
IQueryRequest N1QLQueryRequest = new QueryRequest()
.AddNamedParameter("PersistenceId", persistenceId);
string N1QLQueryOrderByClauseString = "ORDER BY SequenceNr DESC";
if (criteria.MaxSequenceNr > 0 && criteria.MaxSequenceNr < long.MaxValue)
{
N1QLQueryString += "AND SequenceNr <= $limit ";
N1QLQueryOrderByClauseString = "ORDER BY SequenceNr DESC,";
N1QLQueryRequest.AddNamedParameter("limit",criteria.MaxSequenceNr);
}
if (criteria.MaxTimeStamp != DateTime.MinValue && criteria.MaxTimeStamp != DateTime.MaxValue)
{
N1QLQueryString += " AND Timestamp <= $timelimit ";
N1QLQueryOrderByClauseString = "ORDER BY Timestamp DESC,";
N1QLQueryRequest.AddNamedParameter("timelimit", criteria.MaxTimeStamp.Ticks.ToString());
}
N1QLQueryString += N1QLQueryOrderByClauseString.TrimEnd(',') + " LIMIT 1";
N1QLQueryRequest.Statement(N1QLQueryString).AdHoc(false);
return taskLoadAsync(N1QLQueryRequest);
}
示例4: Test_Statement
public void Test_Statement()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default");
var values = query.GetFormValues();
Assert.AreEqual("SELECT * FROM default", values["statement"]);
}
示例5: Test_Query_HelloWorld
public void Test_Query_HelloWorld()
{
var client = GetQueryClient();
var uri = new Uri(string.Format("http://{0}:8093/query", _server));
var query = new QueryRequest("SELECT 'Hello World' AS Greeting").BaseUri(uri);
var result = client.Query<dynamic>(query);
Assert.IsNotNull(result);
Assert.AreEqual("Hello World", result.Rows.First().Greeting.ToString());
}
示例6: Test_Statement
public void Test_Statement()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default");
var uri = query.GetRequestUri();
Assert.IsTrue(uri.ToString().Contains(":8093/query?statement=SELECT * FROM default"));
Console.WriteLine(uri);
}
示例7: Test_Positional_Parameters
public void Test_Positional_Parameters()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default WHERE type=$1").
AddPositionalParameter("dog");
var values = query.GetFormValues();
Assert.AreEqual("SELECT * FROM default WHERE type=$1", values["statement"]);
Assert.AreEqual(new[] {"dog"}, values["args"]);
}
示例8: Test_Statement_ClientContextId_Pretty
public void Test_Statement_ClientContextId_Pretty()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default").
ClientContextId("somecontextlessthanorequalto64chars").
Pretty(true);
var values = query.GetFormValues();
Assert.AreEqual(true, values["pretty"]);
}
示例9: Test_Statement_ClientContextId
public void Test_Statement_ClientContextId()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default").
ClientContextId("somecontextlessthanorequalto64chars");
var values = query.GetFormValues();
string contextid = values["client_context_id"].ToString().Split(new String[] {"::"}, System.StringSplitOptions.None)[0];
Assert.AreEqual("somecontextlessthanorequalto64chars", contextid);
}
示例10: Test_Query_HelloWorld
public void Test_Query_HelloWorld()
{
var config = new ClientConfiguration();
var client = new QueryClient(new HttpClient(), new JsonDataMapper(config), new BucketConfig(), config);
var uri = new Uri(string.Format("http://{0}:8093/query", _server));
var query = new QueryRequest("SELECT 'Hello World' AS Greeting").BaseUri(uri);
var result = client.Query<dynamic>(query);
Assert.IsNotNull(result);
Assert.AreEqual("Hello World", result.Rows.First().Greeting.ToString());
}
示例11: Test_Statement
public void Test_Statement()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default");
var json = query.GetFormValuesAsJson();
var expected = "{\"statement\":\"SELECT * FROM default\",\"timeout\":\"75000ms\"}";
Console.WriteLine(json);
Assert.AreEqual(expected, json);
}
示例12: Test_N1QL_Query
public void Test_N1QL_Query()
{
using (var bucket = _cluster.OpenBucket())
{
var query = new QueryRequest("SELECT * FROM `beer-sample` LIMIT 10");
var result = bucket.Query<dynamic>(query);
Assert.IsTrue(result.Success);
Assert.AreEqual(10, result.Rows.Count);
}
}
示例13: Test_Statement_ClientContextId
public void Test_Statement_ClientContextId()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default").
ClientContextId("somecontextlessthanorequalto64chars");
var uri = query.GetRequestUri();
Console.WriteLine(uri);
Assert.IsTrue(uri.ToString().Contains(":8093/query?statement=SELECT * FROM default&client_context_id=somecontextlessthanorequalto64chars"));
}
示例14: Test_Positional_Parameters
public void Test_Positional_Parameters()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default WHERE type=$1").
AddPositionalParameter("dog");
var uri = query.GetRequestUri();
Console.WriteLine(uri);
Assert.IsTrue(uri.ToString().Contains(":8093/query?statement=SELECT * FROM default WHERE type=$1&args=[\"dog\"]"));
}
示例15: Test_Positional_Parameters
public void Test_Positional_Parameters()
{
var query = new QueryRequest().
BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))).
Statement("SELECT * FROM default WHERE type=$1").
AddPositionalParameter("dog");
var json = query.GetFormValuesAsJson();
var expected = "{\"statement\":\"SELECT * FROM default WHERE type=$1\",\"timeout\":\"75000ms\",\"args\":[\"dog\"]}";
Console.WriteLine(json);
Assert.AreEqual(expected, json);
}