public List <Hero> GetHeroes(Action <List <Hero> > heroesUpdated) { var heroes = new List <Hero>(); try { _heroesQuery = QueryBuilder .Select(SelectResult.All()) .From(DataSource.Database(DatabaseManager.Database)) .Where((Expression.Property("type").EqualTo(Expression.String("hero")))); if (heroesUpdated != null) { _heroesQueryToken = _heroesQuery.AddChangeListener((object sender, QueryChangedEventArgs e) => { if (e?.Results != null && e.Error == null) { heroes = e.Results.AllResults()?.ToObjects <Hero>() as List <Hero>; if (heroes != null) { heroesUpdated.Invoke(heroes); } } }); } } catch (Exception ex) { Console.WriteLine($"HeroRepository GetHeroesAsync Exception: {ex.Message}"); } return(heroes); }
public List <Commune> Gets(string critereVille, int limit) { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dataBaseGetter.Get())) .Where ( Expression.Property("table").EqualTo(Expression.String("commune")) .And(Function.Upper(Expression.Property("libelle")).Like(Expression.String($"{critereVille.ToUpper()}%"))) ) .OrderBy(Ordering.Property("libelle").Ascending()) .Limit(Expression.Int(limit)); var rows = query.Execute(); if (rows.Count() == 0) { List <Commune> communes = new List <Commune> { new Commune() { Num = 1, Libelle = LIBELLE_TEST, CodePostal = CP_TEST, PayCode = PAYCODE_TEST } }; return(communes); } rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToCommune()).ToList()); }
public List <Hero> Search(string searchText, bool sortAscending) { var heroes = new List <Hero>(); if (!string.IsNullOrEmpty(searchText)) { // Create a FTS expression for the previously created "AliasIndex" index. var whereClause = FullTextExpression.Index("AliasIndex").Match($"'{searchText}'"); using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(HeroesDatabase)) .Where(whereClause) .OrderBy(sortAscending ? Ordering.Property("Alias").Ascending() : Ordering.Property("Alias").Descending())) { heroes = ParseResults(query)?.ToList(); } } else { heroes = GetAll(sortAscending); } return(heroes); }
public ItemViewModel(Param param) { this.param = param; using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(this.param.App.database))) { var result = query.Execute(); var res = result.ToArray(); foreach (var i in res) { System.Diagnostics.Debug.WriteLine("Output " + Newtonsoft.Json.JsonConvert.SerializeObject(i)); System.Diagnostics.Debug.WriteLine("Output " + i.GetDictionary(0).GetString("ID")); this.items.Add(new Item() { Name = i.GetDictionary(0).GetString("name"), Value = i.GetDictionary(0).GetString("value"), ID = i.GetDictionary(0).GetString("ID") }); } result = query.Execute(); System.Diagnostics.Debug.WriteLine("Number " + result.Count()); } }
private static void DoPredictiveQuery() { using (var db = new Database("mydb")) { // tag::predictive-query[] var input = Expression.Dictionary(new Dictionary <string, object> { ["photo"] = Expression.Property("photo") }); //var prediction = PredictiveModel.predict("ImageClassifier", input); // <1> using (var q = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(db)) //.Where(prediction.Property("label").EqualTo(Expression.String("car")) //.And(prediction.Property("probability").GreaterThanOrEqualTo(Expression.Double(0.8)))) ) { var result = q.Execute(); Console.WriteLine($"Number of rows: {result.Count()}"); } // end::predictive-query[] } }
public List <Path> GetExternalPaths(Action <List <Path> > pathsUpdated) { List <Path> paths = new List <Path>(); try { _pathsQuery = QueryBuilder .Select(SelectResult.All()) .From(DataSource.Database(DatabaseManager.Database)) .Where((Expression.Property("type").EqualTo(Expression.String("path")) .And(Expression.Property("createdBy").NotEqualTo(Expression.String(AppInstance.AppId))))); if (pathsUpdated != null) { _pathsQueryToken = _pathsQuery.AddChangeListener((object sender, QueryChangedEventArgs e) => { if (e?.Results != null && e.Error == null) { paths = e.Results.AllResults()?.ToObjects <Path>(databaseName) as List <Path>; if (paths != null) { pathsUpdated.Invoke(paths); } } }); } } catch (Exception ex) { Console.WriteLine($"CanvasRepository GetExternalPaths Exception: {ex.Message}"); } return(paths); }
public List <SituationFamille> Gets() { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dataBaseGetter.Get())) .Where(Expression.Property("table").EqualTo(Expression.String("situationfamille"))); var rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToSituationFamille()).ToList()); }
public List <Lot> Gets(long?pgrNum) { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dataBaseGetter.Get())) .Where(Expression.Property("table").EqualTo(Expression.String("lot")).And(Expression.Property("pgrNum").EqualTo(Expression.Long(pgrNum ?? 0)))); var rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToLot()).OrderBy(l => l.Code).OrderBy(l => Regex.IsMatch(l.Code, @"^\d+$") ? Convert.ToInt32(l.Code):0).ToList()); }
public List <Option> Gets() { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dataBaseGetter.Get())) .Where(Expression.Property("table").EqualTo(Expression.String("option")) .And(Expression.Property("actif").EqualTo(Expression.Boolean(true)))); var rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToOption()).ToList()); }
public FuturAcquereur Get(string id) { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dataBaseGetter.Get())) .Where(Expression.Property("table").EqualTo(Expression.String("futuracquereur")) .And(Expression.Property("id").EqualTo(Expression.String(id)))); var rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToFuturAcquereur()).FirstOrDefault()); }
public bool ExistPeople() { bool exist = false; using (var query = QueryBuilder.Select(SelectResult.All()).From(DataSource.Database(database))) { exist = query.Execute().AllResults().Any(); } return(exist); }
private static void SelectAll() { var db = _Database; // # tag::query-select-all[] using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(db))) { // All user properties will be available here } // # end::query-select-all[] }
public List <SynchroEx> Gets() { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dbConfigurationGetter.Get())) .Where(Expression.Property("table").EqualTo(Expression.String("synchroex"))) .OrderBy(Ordering.Property("dateException").Descending()) .Limit(Expression.Int(150)); var rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToSynchroEx()).ToList()); }
public SeasonalItemsViewModel() { Title = "What's in Season?"; Items = new ObservableConcurrentDictionary <int, SeasonalItem>(); DocsChangeIndexes = new HashSet <int>(); LoadItemsCommand = new Command(() => ExecuteLoadItemsCommand()); SaveDocumentsCommand = new Command(async() => await ExecuteSaveDocumentsCommand()); //tag::LoadData[] var q = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_db)) .Where(Meta.ID.EqualTo(Expression.String(CoreApp.DocId))) .AddChangeListener((sender, args) => { var allResult = args.Results.AllResults(); var result = allResult[0]; var dict = result[CoreApp.DB.Name].Dictionary; var arr = dict.GetArray(CoreApp.ArrKey); if (arr.Count < Items.Count) { Items = new ObservableConcurrentDictionary <int, SeasonalItem>(); } Parallel.For(0, arr.Count, i => { var item = arr[i].Dictionary; var name = item.GetString("key"); var cnt = item.GetInt("value"); var image = item.GetBlob("image"); if (_items.ContainsKey(i)) { _items[i].Name = name; _items[i].Quantity = cnt; _items[i].ImageByteArray = image?.Content; } else { var seasonalItem = new SeasonalItem { Index = i, Name = name, Quantity = cnt, ImageByteArray = image?.Content }; _items.Add(i, seasonalItem); } }); }); //end::LoadData[] }
public void StartDBConnection() { Couchbase.Lite.Support.UWP.Activate(); // Get the database (and create it if it doesn't exist) this.database = new Database("einkaufsliste"); // Create replicator to push and pull changes to and from the cloud var targetEndpoint = new URLEndpoint(new Uri("ws://37.252.185.24:4984/db")); var replConfig = new ReplicatorConfiguration(this.database, targetEndpoint) { ReplicatorType = ReplicatorType.PushAndPull }; replConfig.Channels = new List <String>(); replConfig.Channels.Add("liste"); replConfig.Continuous = true; // Add authentication replConfig.Authenticator = new BasicAuthenticator("UserEin", "Einkaufsliste"); // Create replicator var replicator = new Replicator(replConfig); replicator.AddChangeListener((sender, args) => { if (args.Status.Error != null) { System.Diagnostics.Debug.WriteLine($"Error :: {args.Status.Error}"); } System.Diagnostics.Debug.WriteLine("Test sync"); using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(this.database))) { // Run the query var result = query.Execute(); var res = result.ToArray(); foreach (var i in res) { System.Diagnostics.Debug.WriteLine("Output " + Newtonsoft.Json.JsonConvert.SerializeObject(i)); System.Diagnostics.Debug.WriteLine("Output " + i.GetDictionary(0).GetString("name")); } result = query.Execute(); System.Diagnostics.Debug.WriteLine("Number " + result.Count()); } }); replicator.Start(); }
public IResultSet Travel(Database db) { if (db == null) { return(null); } var query = Query.Select(SelectResult.All()) .From(DataSource.Database(db)) .Where(Expression.Property("type").EqualTo("airline")) .OrderBy(Ordering.Property("id")); var rows = query.Run(); return(rows); }
public List <Hero> GetAll(bool sortAscending) { var heroes = new List <Hero>(); // Get all of the hero records, and sort accordingly using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(HeroesDatabase)) .OrderBy(sortAscending ? Ordering.Property("Alias").Ascending() : Ordering.Property("Alias").Descending())) { heroes = ParseResults(query)?.ToList(); } return(heroes); }
public void ShouldCreateBaselineTest() { // setup var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(SetUpAll.Database)) .Where(Expression.Property("$Type") .EqualTo(Expression.String(nameof(Person))) .And(Expression.Property("age").Is(Expression.Int(5)))); // execute var result = query.Execute(); // assert result.Count().Should().Be(1); }
public Server Get() { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dbConfigurationGetter.Get())) .Where(Expression.Property("table").EqualTo(Expression.String("server"))); var rows = query.Execute().ToList(); if (rows.Count() == 0) { return(null); } return(rows.Select(r => r.GetDictionary(0).ToMutable().ToServer()).FirstOrDefault()); }
public BingoBall GetBall(string ballId) { using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_database)) .Where(Expression.Property("Name").EqualTo(Expression.String(ballId)))) { var result = query.Execute().ToList().First()[0]; var ball = new BingoBall(); ball.Name = result["Name"].String; ball.IsPlayed = result["IsPlayed"].Boolean; ball.IsMatched = result["IsMatched"].Boolean; return(ball); } }
public List <FuturAcquereur> Gets(string critere, int limit) { IQuery query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_dataBaseGetter.Get())) .Where ( Expression.Property("table").EqualTo(Expression.String("futuracquereur")) .And(Function.Upper(Expression.Property("aquereurPrincipal.nom")).Like(Expression.String($"{critere.ToUpper()}%"))) ) .OrderBy(Ordering.Property("aquereurPrincipal.nom").Ascending()) .Limit(Expression.Int(limit)); var rows = query.Execute(); return(rows.Select(r => r.GetDictionary(0).ToMutable().ToFuturAcquereur()).ToList()); }
public void DeleteAllPaths() { try { var pathsQuery = QueryBuilder .Select(SelectResult.All()) .From(DataSource.Database(DatabaseManager.Database)); List <Path> paths = pathsQuery.Execute()?.AllResults()?.ToObjects <Path>()?.ToList(); DeletePaths(paths); } catch (Exception ex) { Console.WriteLine($"CanvasRepository GetInternalPaths Exception: {ex.Message}"); } }
private static void testQueryPagination() { // For Documentation var dbName = "travel-sample"; var this_Db = new Database(dbName); Dictionary <string, object> hotel = new Dictionary <string, object>(); List <Dictionary <string, object> > hotels = new List <Dictionary <string, object> >(); //tag::query-pagination[] var thisLimit = 20; var thisOffset = 0; var countQuery = QueryBuilder .Select(SelectResult.Expression(Function.Count(Expression.All())).As("mycount")) // <.> .From(DataSource.Database(this_Db)); var numberOfDocs = countQuery.Execute().AllResults().ElementAt(0).GetInt("mycount"); // <.> if (numberOfDocs < thisLimit) { thisLimit = numberOfDocs; } while (thisOffset < numberOfDocs) { var listQuery = QueryBuilder .Select(SelectResult.All()) .From(DataSource.Database(this_Db)) .Limit(Expression.Int(thisLimit), Expression.Int(thisOffset)); // <.> foreach (var result in listQuery.Execute().AllResults()) { // Display and or process query results batch } thisOffset = thisOffset + thisLimit; } // end while //end::query-pagination[] } // testQueryPagination
private static void SelectWhere() { Console.WriteLine("Where"); var db = _Database; // # tag::query-where[] using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(db)) .Where(Expression.Property("type").EqualTo(Expression.String("hotel"))) .Limit(Expression.Int(10))) { foreach (var result in query.Execute()) { var dict = result.GetDictionary(db.Name); Console.WriteLine($"Document Name :: {dict?.GetString("name")}"); } } // # end::query-where[] }
public IEnumerable <BingoBall> GetBingoBalls() { var list = new List <BingoBall>(); using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_database))) { var result = query.Execute(); foreach (var item in result) { var ball = new BingoBall((DictionaryObject)item[0].Value); list.Add(ball); } } return(list); }
public IEnumerable <BingoBall> GetMatchedBingoBalls() { var list = new List <BingoBall>(); using (var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(_database)) .Where(Expression.Property("IsMatched").EqualTo(Expression.Boolean(true)))) { var result = query.Execute(); foreach (var item in result) { var ball = new BingoBall((DictionaryObject)item[0].Value); list.Add(ball); } } return(list); }
public void ShouldConnectToDatabase() { // setup var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Database(SetUpAll.Database)) .Where(Expression.Property("$Type") .EqualTo(Expression.String(nameof(Person))) .And(Expression.Property("age").Is(Expression.Int(5)))); // execute var resultSet = ObservableResultSet.Create(query) .ToProperty(this, "") .DisposeWith(_disposable); var allResults = resultSet.Value.AllResults(); var connectionCount = ObservableResultSet.ConnectionCount.ToProperty(this, "").DisposeWith(_disposable); // assert allResults.Count.Should().Be(1); connectionCount.Value.Should().Be(1); }
public List <People> GetPeople() { List <People> people = new List <People>(); using (var query = QueryBuilder.Select(SelectResult.All()).From(DataSource.Database(database))) { foreach (Result item in query.Execute()) { var dict = item.GetDictionary(database.Name); string value = dict?.GetString(ConstantPerson); if (!string.IsNullOrEmpty(value)) { people.Add(JsonConvert.DeserializeObject <People>(value)); } } } return(people); }
public List <Item> GetItems(Action <List <Item> > userProfileUpdated) { List <Item> items = new List <Item>(); try { var database = DatabaseManager.Database; if (database != null) { _userQuery = QueryBuilder .Select(SelectResult.All()) .From(DataSource.Database(database)) .Where((Expression.Property("type").EqualTo(Expression.String("item")))); //.And(Expression.String("tenant_2").In(Expression.Property("channels")))); if (userProfileUpdated != null) { _userQueryToken = _userQuery.AddChangeListener((object sender, QueryChangedEventArgs e) => { if (e?.Results != null && e.Error == null) { items = e.Results.AllResults()?.ToObjects <Item>("test") as List <Item>; if (items != null) { userProfileUpdated.Invoke(items); } } }); } } } catch (Exception ex) { Console.WriteLine($"TestRepository Exception: {ex.Message}"); } return(items); }
public List <Message> GetMessages(Action <List <Message> > messagesUpdated) { List <Message> messages = new List <Message>(); try { var database = DatabaseManager.Database; if (database != null) { _messagesQuery = QueryBuilder .Select(SelectResult.All()) .From(DataSource.Database(database)) .Where((Expression.Property("type").EqualTo(Expression.String("message"))) .And((Expression.Property("channel").EqualTo(Expression.String(AppInstance.Channel))))); if (messagesUpdated != null) { _messagesQueryToken = _messagesQuery.AddChangeListener((object sender, QueryChangedEventArgs e) => { if (e?.Results != null && e.Error == null) { messages = e.Results.AllResults()?.ToObjects <Message>("chatbase") as List <Message>; if (messages != null) { messagesUpdated.Invoke(messages); } } }); } } } catch (Exception ex) { Console.WriteLine($"ChatRepository Exception: {ex.Message}"); } return(messages); }