private static And UserIsGroupCreator(Guid userId, ReqlExpr eventExpr) { return(R.And( eventExpr["Type"].Eq(EventType.GroupCreated), UserIsAuthor(userId, eventExpr) )); }
public override ReqlExpr Parse(ReqlExpr expression, QueryModel queryModel, Expression predicate) { var binaryExpression = (BinaryExpression)predicate; var value = GetValue(binaryExpression); return(((Table)expression).Get(value)); }
private static And UserMembersInChannelNotChanged(ReqlExpr eventExpr) { return(R.And( eventExpr["Type"].Ne(EventType.UserAddedToChannel), eventExpr["Type"].Ne(EventType.UserRemovedFromChannel) )); }
private static And UserNotRemovedFromGroup(Guid userId, ReqlExpr eventExpr) { return(R.And( UserAttached(userId, eventExpr), eventExpr["Type"].Ne(EventType.UserRemovedFromGroup) )); }
private static ReqlExpr GetWhereReqlAst(ReqlExpr reqlExpr, Expression predicate, QueryModel queryModel) { var visitor = new ExpressionVisitor(reqlExpr, GetResultType(queryModel)); visitor.Visit(predicate); return(visitor.Current); }
public void Configuration(IAppBuilder app) { var mongo = new MongoConnection(); var rethink = new RethinkConnection(); // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseCors(CorsOptions.AllowAll); app.MapSignalR(); app.UseWebApi(config); ReqlExpr dbTable = RethinkDB.R.Db("baseball").Table("batterStat"); var feed = dbTable.Changes() .RunChanges <Batter>(RethinkConnection.Connection); var observe = feed.ToObservable(); observe.SubscribeOn(NewThreadScheduler.Default) .Subscribe((Change <Batter> b) => { BatterInstance.Instance.UpdateBatterStat(b.NewValue); }); }
static void Main(string[] args) { var mongo = new MongoConnection(); var rethink = new RethinkConnection(); var eventStore = new EventConnection(); var system = ActorSystem.Create("baseballStats"); var topLevel = system.ActorOf(GameEventCoordinator.Create(), "gameCoordinator"); var handler = new PlayHandler(topLevel); ReqlExpr dbTable = RethinkDB.R.Db("baseball").Table("plays"); var feed = dbTable.Changes() .RunChanges <Play>(RethinkConnection.Connection /*, new { include_initial = true }*/); var observe = feed.ToObservable(); observe.SubscribeOn(CurrentThreadScheduler.Instance) .Subscribe((Change <Play> p) => { handler.Handle(p.NewValue); }); Console.WriteLine("Hit enter to exit..."); Console.ReadLine(); }
public override ReqlExpr Parse(ReqlExpr expression, QueryModel queryModel, Expression predicate) { var binaryExpression = (BinaryExpression)predicate; var value = GetValue(binaryExpression); return(((Table)expression).GetAll(value).OptArg("index", GetIndexName(binaryExpression))); }
public override NexusExtDBBaseService Where(JArray conditions) { Where(); query = query.Filter(doc => BuildFilter(doc, conditions)); return(this); }
static void Main(string[] args) { var handler = new PlayHandler(); var conn = RethinkDB.R .Connection() .Hostname("localhost") .Port(RethinkDBConstants.DefaultPort) .Timeout(30) .Connect(); ReqlExpr dbTable = RethinkDB.R.Db("baseball").Table("plays"); var feed = dbTable.Changes() .RunChanges <Play>(conn, new { include_initial = true }); var observe = feed.ToObservable(); observe.SubscribeOn(CurrentThreadScheduler.Instance) .Subscribe((Change <Play> p) => { handler.Handle(p.NewValue); }); Console.WriteLine("Hit enter to exit..."); Console.ReadLine(); }
public static ReqlExpr filter <T>(this ReqlExpr _this, Expression <Func <T, object> > expr) { var arguments = new Arguments(_this); arguments.CoerceAndAdd(expr); return(new Filter(arguments)); }
private static ReqlExpr GetWhereReqlAst(ReqlExpr reqlExpr, Expression predicate) { var visitor = new ExpressionVisitor(reqlExpr, typeof(bool)); visitor.Visit(predicate); return(visitor.Current); }
private And UserIdRelatedCriteria(Guid userId, ReqlExpr eventExpr) { return(R.And( R.Or( R.And( R.Or( GroupNotCreated(eventExpr), UserNotRemovedFromGroup(userId, eventExpr) ), UserIsInsideGroup(userId, eventExpr) ), UserIsGroupCreator(userId, eventExpr), UserRemovedFromGroup(userId, eventExpr) ), R.Or( ChatNotAffected(eventExpr), UserRemovedFromChat(userId, eventExpr), UserIsInsideAffectedChat(userId, eventExpr) ), R.Or( ChannelNotAffected(eventExpr), UserRemovedFromChannel(userId, eventExpr), UserMembersInChannelNotChanged(eventExpr), UserIsInsideAffectedChannel(userId, eventExpr) ) )); }
private static And UserRemovedFromChannel(Guid userId, ReqlExpr eventExpr) { return(R.And( UserAttached(userId, eventExpr), eventExpr["Type"].Eq(EventType.UserRemovedFromChannel) )); }
public static async Task <T[]> RunArrayAsync <T>(this ReqlExpr expr, IConnection conn) { var huh = await expr.RunResultAsync(conn); var cursor = await expr.RunCursorAsync <T>(conn); return(cursor.ToArray()); }
public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel) { var fromExpression = queryModel.MainFromClause.FromExpression as MemberExpression; var memberNameResolver = new MemberNameResolver(fromExpression); reqlExpr = memberNameResolver.Resolve(reqlExpr); reqlExpr = reqlExpr.Filter(expr => GetWhereReqlAst(expr, ((AllResultOperator)queryModel.ResultOperators[0]).Predicate, queryModel).Not()); return(reqlExpr.Count().Eq(0)); }
private ReqlExpr BuildDynamicFilter(ReqlExpr expr, string[] colorSearch) { var statement = R.Or(); foreach (var color in colorSearch) { statement = statement.Or(expr[nameof(Product.ColorCode)].Eq(color)); } return(statement); }
public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel) { var fromExpression = queryModel.MainFromClause.FromExpression as ConstantExpression; var array = RethinkDB.R.Expr(fromExpression.Value as IEnumerable <object>); var resultOperator = queryModel.ResultOperators[0] as ContainsResultOperator; var memberNameResolver = new MemberNameResolver((MemberExpression)resultOperator.Item); return(array.Contains(memberNameResolver.Resolve(reqlExpr))); }
public static ReqlExpr TranslateUnary(ExpressionType type, ReqlExpr term) { switch (type) { case ExpressionType.Not: return(term.Not()); default: throw new NotSupportedException("Unary term not supported."); } }
private static ReqlExpr GetWhereReqlAst(ReqlExpr reqlExpr, Expression predicate) { var subQueryExpression = predicate as SubQueryExpression; var where = subQueryExpression.QueryModel.BodyClauses[0] as WhereClause; var visitor = new ExpressionVisitor(reqlExpr, subQueryExpression.QueryModel.MainFromClause.ItemType); visitor.Visit(where.Predicate); return(visitor.Current); }
protected override ReqlExpr BuildReql(ReqlExpr reqlExpr, QueryModel queryModel) { reqlExpr = reqlExpr.Nth(queryModel.ResultOperators[0] is FirstResultOperator ? 0 : -1); var resultOperator = (ChoiceResultOperatorBase)queryModel.ResultOperators[0]; if (resultOperator.ReturnDefaultWhenEmpty) { reqlExpr = reqlExpr.Default_((object)null); } return(reqlExpr); }
private JObject GetFromDbFull <T>(Id id) { var importTree = GetFullImportTree(typeof(T), null); var table = GetTable(typeof(T)); ReqlExpr get = table .Get(id.ToString()); get = Merge(get, importTree); var result = get.Run(_connection) as JObject; return(result); }
private static ReqlExpr ResolveMemberExpression(ReqlExpr reqlExpr, MemberExpression expression) { if (expression.Expression.NodeType == ExpressionType.MemberAccess) { reqlExpr = ResolveMemberExpression(reqlExpr, (MemberExpression)expression.Expression); } if (expression.Expression.NodeType == ExpressionType.Extension && expression.Expression is SubQueryExpression) { reqlExpr = ResolveExtensionExpression(reqlExpr, (SubQueryExpression)expression.Expression); } return(reqlExpr[QueryHelper.GetJsonMemberName(expression.Member)]); }
private Gt UserIsInsideGroup(Guid userId, ReqlExpr eventExpr) { return(_groupUserTable .Filter( groupUser => R.And( groupUser["GroupId"].Eq(eventExpr["GroupId"]), groupUser["UserId"].Eq(userId) ) ) .Count() .Gt(0)); }
public override ReqlExpr Visit(ReqlExpr reqlExpr, QueryModel queryModel) { var fromExpression = queryModel.MainFromClause.FromExpression as MemberExpression; var memberNameResolver = new MemberNameResolver(fromExpression); reqlExpr = memberNameResolver.Resolve(reqlExpr); if (queryModel.BodyClauses.Any()) { reqlExpr = reqlExpr.Filter(expr => GetWhereReqlAst(expr, ((WhereClause)queryModel.BodyClauses[0]).Predicate, queryModel)); } return(BuildReql(reqlExpr, queryModel)); }
private Gt UserIsInsideAffectedChannel(Guid userId, ReqlExpr eventExpr) { return(_channelUserTable .Filter( channelUser => R.And( channelUser["ChannelId"].Eq(eventExpr["ChannelId"]), channelUser["UserId"].Eq(userId) ) ) .Count() .Gt(0)); }
public static ReqlExpr TranslateBinary(ExpressionType type, ReqlExpr left, ReqlExpr right) { switch (type) { case ExpressionType.Equal: return(left.Eq(right)); case ExpressionType.NotEqual: return(left.Eq(right).Not()); case ExpressionType.LessThan: return(left.Lt(right)); case ExpressionType.LessThanOrEqual: return(left.Le(right)); case ExpressionType.GreaterThan: return(left.Gt(right)); case ExpressionType.GreaterThanOrEqual: return(left.Ge(right)); case ExpressionType.And: case ExpressionType.AndAlso: return(left.And(right)); case ExpressionType.Or: case ExpressionType.OrElse: return(left.Or(right)); case ExpressionType.Not: throw new InvalidOperationException("ExpresionType:Not cannot be called on a binary translation."); case ExpressionType.Add: return(left.Add(right)); case ExpressionType.Subtract: return(left.Sub(right)); case ExpressionType.Multiply: return(left.Mul(right)); case ExpressionType.Divide: return(left.Div(right)); case ExpressionType.Modulo: return(left.Mod(right)); default: throw new NotSupportedException("Binary expression not supported."); } }
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); }
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); }
//private JArray GetFromDb<T>(Id[] ids, MapObject hashMap) //{ // var importTree = GetImportTree(typeof(T), hashMap, null); // var idStrings = ids.Select(d => d.ToString()).ToArray(); // var table = GetTable(typeof(T)); // ReqlExpr get = table.GetAll(R.Args(idStrings)); // get = get.Map(item => Merge(item, importTree)); // get = get.Map(item => item.Pluck(hashMap)); // var result = get.CoerceTo("ARRAY").Run(_connection) as JArray; // return result; //} private JObject GetFromDb <T>(Id id, MapObject hashMap) { var importTree = GetImportTree(typeof(T), hashMap, null); var table = GetTable(typeof(T)); ReqlExpr get = table .Get(id.ToString()); get = Merge(get, importTree); get = get.Pluck(hashMap); var result = get.Run(_connection) as JObject; return(result); }