private ReqlExpr BuildFilter(ReqlExpr doc, JArray conditions)
        {
            var statement = r.And();

            foreach (JToken cond in conditions)
            {
                string column = (string)cond["column"];
                string op     = (string)cond["operator"];
                object value  = (object)cond["value"];

                switch (op)
                {
                case "eq": statement = statement.And(doc[column].Eq(value)); break;

                case "lt": statement = statement.And(doc[column].Lt(value)); break;

                case "gt": statement = statement.And(doc[column].Gt(value)); break;

                case "lte": statement = statement.And(doc[column].Le(value)); break;

                case "gte": statement = statement.And(doc[column].Ge(value)); break;

                case "like": statement = statement.And(doc[column].Match(value)); break;

                case "not-like": statement = statement.And(doc[column].Match(value).Not()); break;

                case "in": {
                    var      st     = r.Or();
                    string[] values = ((string)value).Split(new char[] { ',', ';' });
                    foreach (string val in values)
                    {
                        st = st.Or(doc[column].Eq(val));
                    }
                    statement = statement.And(st);
                    break;
                }

                case "not-in": {
                    var      st     = r.And();
                    string[] values = ((string)value).Split(new char[] { ',', ';' });
                    foreach (string val in values)
                    {
                        st = st.And(doc[column].Eq(val).Not());
                    }
                    statement = statement.And(st);
                    break;
                }
                }
            }

            return(statement);
        }
Exemplo n.º 2
0
        private ReqlExpr BuildDynamicFilter(ReqlExpr expr, Dictionary <string, object> parameters)
        {
            var statement = rethinkDB.And();

            if (parameters != null && parameters.Keys.Count > 0)
            {
                foreach (var key in parameters.Keys)
                {
                    statement = statement.And(expr[key].Eq(parameters[key]));
                }
            }
            return(statement);
        }