Ejemplo n.º 1
0
 public IObservable <ICollection <Bike> > ObserveBikesFromStation(Station station)
 => ObservableBikes(Bikes(station.CommunityId)
                    .WhereEqualsTo(FieldPath.GetMappingName <Bike>(nameof(Bike.StationId)), station.Id),
                    station.CommunityId);
Ejemplo n.º 2
0
 public Task Update(T model, string field, object?value) =>
 GetDocument(model).UpdateAsync(FieldPath.GetMappingName <T>(field), value ?? FieldValue.Delete);
Ejemplo n.º 3
0
 public AnalyzedField(FieldPath fieldPath, int offset)
 {
     this.fieldPath = fieldPath;
     this.offset = offset;
     this.name = this.FieldPath.DotPath;
 }
Ejemplo n.º 4
0
 private static FieldPath[] SplitPaths(params string[] paths) =>
 paths.Select(p => FieldPath.FromDotSeparatedString(p)).ToArray();
Ejemplo n.º 5
0
        public void FromDotSeparatedString(string expectedEncodedPath, string input)
        {
            FieldPath path = FieldPath.FromDotSeparatedString(input);

            Assert.Equal(expectedEncodedPath, path.EncodedPath);
        }
Ejemplo n.º 6
0
 public void FromDotSeparatedString_Invalid(string value)
 {
     Assert.Throws <ArgumentException>(() => FieldPath.FromDotSeparatedString(value));
 }
Ejemplo n.º 7
0
 public IQuery WhereArrayContainsAny(FieldPath path, object[] values)
 {
     return(_wrapped.WhereArrayContainsAny(path.ToNative(), values).ToAbstract());
 }
Ejemplo n.º 8
0
 public AnalyzedField(FieldPath fieldPath, int offset)
 {
     this.fieldPath = fieldPath;
     this.offset    = offset;
     this.name      = this.FieldPath.DotPath;
 }
Ejemplo n.º 9
0
 public IQuery WhereGreaterThan(FieldPath path, object value)
 {
     return(_wrapped.WhereGreaterThan(path.ToNative(), value).ToAbstract());
 }
Ejemplo n.º 10
0
 public IQuery WhereLessThanOrEqualsTo(FieldPath path, object value)
 {
     return(_wrapped.WhereLessThanOrEqualsTo(path.ToNative(), value).ToAbstract());
 }
Ejemplo n.º 11
0
 public IQuery OrderBy(FieldPath path, bool @descending = false)
 {
     return(_wrapped.OrderedBy(path.ToNative(), descending).ToAbstract());
 }
 static FieldPathAssemblerStub()
 {
     Source = new FieldPath();
     DTO    = new FieldPathDTO();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Execute all SQL statements and ensure the given configuration is valid.
        /// </summary>
        /// <param name="config"></param>
        public virtual void Validate(bool onlyErrors = false)
        {
            _conn.Open();
            var broken = new List <ISubject>();

            // ensure all the source data from the subjects can be executed as SQL
            foreach (ISqlSubject subject in _configuration)
            {
                // check subject and all non-related fields first
                var fields = subject.FindAll <IField>(f => !(f is IRelationField))
                             .ToList <IField>()
                             .ConvertAll <IFieldPath>(f => FieldPath.FromDefault(f));

                var generator = new SqlGenerator(_configuration);
                generator
                .ForTarget(subject)
                .Column(fields);

                try
                {
                    int rows = Execute(generator);
                    if (!onlyErrors)
                    {
                        Console.WriteLine("Subject '" + subject.DisplayName + "' succeeded (" + rows + " rows affected)");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Subject '" + subject.DisplayName + "' failed when executing with all non-RelationFields: " + ex.Message + "\n\t"); // + generator.GenerateSql());
                    broken.Add(subject);
                    continue;
                }


                // now check all RelationFields individually for validity
                foreach (var rf in subject.FindAll <IField>(f => f is IRelationField))
                {
                    var path = FieldPath.FromDefault(rf);

                    var bf = path.Find(f2 => broken.Contains(f2.Subject));
                    if (bf != null)
                    {
                        Console.WriteLine("Cannot check relation field for " + path.Description + " as " + bf.Subject + " SQL is invalid.");
                        continue;
                    }

                    var generator2 = new SqlGenerator(_configuration);
                    generator2
                    .ForTarget(subject)
                    .Column(path);

                    try
                    {
                        int rows = Execute(generator2);
                        if (!onlyErrors)
                        {
                            Console.WriteLine("RelationField '" + rf.DisplayName + "' succeeded.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("RelationField '" + rf.DisplayName + "' failed. " + ex.Message + "\n\t"); // + generator2.GenerateSql());
                    }
                }

                // for all fields, ensure list data can be retrieved
                foreach (var f in subject)
                {
                    var path = FieldPath.FromDefault(f);
                    if (path.Last.List != null && !String.IsNullOrEmpty(path.Last.List.Source))
                    {
                        var bf = path.Find(f2 => broken.Contains(f2.Subject));
                        if (bf != null)
                        {
                            Console.WriteLine("Cannot check list data for " + path.Description + " as " + bf.Subject + " SQL is invalid.");
                            continue;
                        }

                        var gen = new SqlListGenerator(_configuration).WithPath(path);
                        if (Regex.IsMatch(path.Last.List.Source, @"^select.*[`'\[\s]id", RegexOptions.IgnoreCase))
                        {
                            gen.IdColumnName("ID")
                            .ValueColumnName("Value");
                        }

                        try
                        {
                            int rows = Execute(gen);
                            if (!onlyErrors)
                            {
                                Console.WriteLine("List data for " + path.Description + " succeeded (" + rows + " rows affected).");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("List data for " + path.Description + " failed. " + ex.Message + "\n\t");
                        }
                    }
                }
            }


            // ensure all path SQL statements execute successfully
            foreach (ISqlSubject from in _configuration)
            {
                foreach (ISqlSubject to in _configuration)
                {
                    if (broken.Contains(from))
                    {
                        Console.WriteLine("Cannot check matrix query [" + from.DisplayName + " to " + to.DisplayName + "] because " + from.DisplayName + " SQL is invalid.");
                        continue;
                    }

                    if (broken.Contains(to))
                    {
                        Console.WriteLine("Cannot check matrix query [" + from.DisplayName + " to " + to.DisplayName + "] because " + to.DisplayName + " SQL is invalid.");
                        continue;
                    }

                    var matrix = _configuration[from, to];

                    if (String.IsNullOrWhiteSpace(matrix.Query))
                    {
                        if (!onlyErrors)
                        {
                            Console.WriteLine("No relationship between " + from.DisplayName + " to " + to.DisplayName + ".");
                        }
                        continue;
                    }

                    // try the vanilla SQL first
                    try
                    {
                        int rows = Execute(matrix.Query);
                        if (!onlyErrors)
                        {
                            Console.WriteLine("Matrix query for [" + from.DisplayName + " to " + to.DisplayName + "] succeeded (" + rows + " rows affected).");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Matrix query for [" + from.DisplayName + " to " + to.DisplayName + "] failed. " + ex.Message + "\n\t" + matrix.Query);
                        continue;
                    }


                    // now try a full query traversing the two subjects
                    // TODO: is this correct?  are we asking for Target=from?  somethings not right here...
                    var generator = new SqlGenerator(_configuration);
                    generator
                    .ForTarget(from)
                    .Column(FieldPath.FromDefault(to.IdField));

                    try
                    {
                        int rows = Execute(generator);
                        if (!onlyErrors)
                        {
                            Console.WriteLine("Generated SQL for " + from.DisplayName + " to " + to.DisplayName + " succeeded (" + rows + " rows affected).");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Generated SQL for " + from.DisplayName + " to " + to.DisplayName + " failed. " + ex.Message + "\n\t"); // + generator.GenerateSql());
                    }
                }
            }
        }
Ejemplo n.º 14
0
 public void Update(T model, string field, object?value, ITransaction transaction)
 {
     transaction.Update(GetDocument(model), FieldPath.GetMappingName <T>(field), value ?? FieldValue.Delete);
 }
Ejemplo n.º 15
0
 public IQuery WhereFieldIn(FieldPath path, object[] values)
 {
     return(_wrapped.WhereFieldIn(path.ToNative(), values).ToAbstract());
 }
Ejemplo n.º 16
0
 private static Firestore.FieldPath ConvertFieldPath(FieldPath testFieldPath) =>
 new Firestore.FieldPath(testFieldPath.Field.ToArray());
Ejemplo n.º 17
0
        public void ShouldGetOriginPathWhenJoinPathWithNormalizePath(string normalizePath)
        {
            var paths = FieldPath.ParsePaths(normalizePath);

            FieldPath.JoinPaths(paths).Should().Be(normalizePath);
        }