Esempio n. 1
0
        public void KitchenSinkExample()
        {
            var actual = RollsQuery.Execute(Db, @"
                SELECT {
                    -- select a JsonPath value
                      $.name

                    -- call a function with a JsonPath and return the result with a custom name
                    , isManager: any($.roles[?(@.title == 'manager')])

                    -- an alternate way to rename a field
                    , $.name AS 'the dudes name'

                    -- selecting and filtering an array
                    , $.roles[?(@.title == 'employee' || @.title == 'manager')]

                    -- ignoring commented lines
                    --, $.age

                    -- calling other functions
                    , utc()
                }
                FROM people
                KEYS 1, 2, 3
                WHERE starts($.name, 'Fred') OR starts($.name, 'Tim') OR starts($.name, 'Steve') AND 1=1
                ORDER BY $.name DESC
                LIMIT 2")
                         .ToArray();

            actual.Iterate(Util.Dump).Evaluate();

            Assert.Equal(2, actual.Length);
        }
Esempio n. 2
0
        public void MonthFunctionPositiveTest(int expected, string expression)
        {
            var actual =
                RollsQuery.Execute(Db, $@"
                    SELECT MONTH({expression}) as 'X' ")
                .Select(j => j["X"].Value <int>())
                .Single();

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void TrimFunctionPositiveTest(string expected, string expression)
        {
            var actual =
                RollsQuery.Execute(Db, $@"
                    SELECT TRIM({expression}) as 'X' ")
                .Select(j => j["X"].Value <string>())
                .Single();

            Assert.Equal(expected, actual);
        }
Esempio n. 4
0
        public void AggregatePositiveTest(int expected, string expression)
        {
            var result = RollsQuery.Execute(Db, $@"
                SELECT {expression} as 'X' FROM people")
                         .Single();

            var actual = result["X"].Value <int>();

            Assert.Equal(expected, actual);
        }
Esempio n. 5
0
        public void LimitPositiveTest(int expected, string expression)
        {
            var actual = RollsQuery.Execute(Db, $@"
                SELECT $
                FROM people
                LIMIT {expression}")
                         .Count();

            Assert.Equal(expected, actual);
        }
Esempio n. 6
0
        public void WherePositiveTest(string expected, string expression)
        {
            var actual = String.Join(",",
                                     RollsQuery.Execute(Db, $@"
                    SELECT $.id
                    FROM people
                    WHERE {expression}")
                                     .Select(j => j["id"].Value <int>()));

            Assert.Equal(expected, actual);
        }
Esempio n. 7
0
        public void SelectPositiveTest(string name, string expected, string expression)
        {
            var actual = RollsQuery.Execute(Db, $@"
                SELECT {{ {expression} }}
                FROM people
                KEYS 1")
                         .Select(j => j[name].Value <string>())
                         .Single();

            Assert.Equal(expected, actual);
        }
Esempio n. 8
0
        public void FirstFunctionPositiveTest(string expected, string expression)
        {
            var actual =
                RollsQuery.Execute(Db, $@"
                    SELECT FIRST(SPLIT({expression})) as 'X'
                    FROM people
                    KEYS 1")
                .Select(j => j["X"].Value <string>())
                .Single();

            Assert.Equal(expected, actual);
        }
Esempio n. 9
0
        public void MultiOrderPositiveTest(string expected, string expression)
        {
            var actual = String.Join(",",
                                     RollsQuery.Execute(Db, $@"
                    SELECT $.id
                    FROM people
                    ORDER BY {expression}")
                                     .Select(j => j["id"].Value <int>())
                                     .ToArray());

            Assert.Equal(expected, actual);
        }