public Term GenerateTerm(IQueryConverter queryConverter) { var getAllTerm = new Term() { type = Term.TermType.GET_ALL, }; getAllTerm.args.Add(tableTerm.GenerateTerm(queryConverter)); foreach (var key in keys) { getAllTerm.args.Add(new Term() { type = Term.TermType.DATUM, datum = queryConverter.Get <TKey>().ConvertObject(key) }); } if (!String.IsNullOrEmpty(indexName)) { getAllTerm.optargs.Add(new Term.AssocPair() { key = "index", val = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = indexName }, } }); } return(getAllTerm); }
public async Task <T> RunAsync <T>(IQueryConverter queryConverter, IScalarQuery <T> queryObject, CancellationToken cancellationToken) { var query = new Spec.Query(); query.token = GetNextToken(); query.type = Spec.Query.QueryType.START; query.query = queryObject.GenerateTerm(queryConverter); var response = await InternalRunQuery(query, cancellationToken); switch (response.type) { case Response.ResponseType.SUCCESS_SEQUENCE: case Response.ResponseType.SUCCESS_ATOM: if (response.response.Count != 1) { throw new RethinkDbRuntimeException(String.Format("Expected 1 object, received {0}", response.response.Count)); } return(queryConverter.Get <T>().ConvertDatum(response.response[0])); case Response.ResponseType.CLIENT_ERROR: case Response.ResponseType.COMPILE_ERROR: throw new RethinkDbInternalErrorException("Client error: " + response.response[0].r_str); case Response.ResponseType.RUNTIME_ERROR: throw new RethinkDbRuntimeException("Runtime error: " + response.response[0].r_str); default: throw new RethinkDbInternalErrorException("Unhandled response type: " + response.type); } }
public Term GenerateTerm(IQueryConverter queryConverter) { var replaceTerm = new Term() { type = Term.TermType.REPLACE, }; replaceTerm.args.Add(getTerm.GenerateTerm(queryConverter)); replaceTerm.args.Add(new Term() { type = Term.TermType.DATUM, datum = queryConverter.Get <T>().ConvertObject(newObject) }); AddOptionalArguments(replaceTerm); if (nonAtomic) { replaceTerm.optargs.Add(new Term.AssocPair() { key = "non_atomic", val = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_BOOL, r_bool = nonAtomic } } }); } return(replaceTerm); }
public QueryEnumerator(Connection connection, IQueryConverter queryConverter, ISequenceQuery <T> queryObject) { this.connection = connection; this.queryConverter = queryConverter; this.datumConverter = queryConverter.Get <T>(); this.queryObject = queryObject; this.stackTrace = new StackTrace(true); }
public Term GenerateTerm(IQueryConverter queryConverter) { if (objectExpr != null) { return(ExpressionUtils.CreateValueTerm <T>(queryConverter, objectExpr)); } else { var datumTerm = new Term() { type = Term.TermType.DATUM, datum = queryConverter.Get <T>().ConvertObject(@object) }; return(datumTerm); } }
private IEnumerable <Term> GetMembers(IQueryConverter queryConverter) { var datumConverter = queryConverter.Get <T>(); var fieldConverter = datumConverter as IObjectDatumConverter; if (fieldConverter == null) { throw new NotSupportedException("Cannot map member access into ReQL without implementing IObjectDatumConverter"); } foreach (var memberReferenceExpression in fields) { if (memberReferenceExpression.NodeType != ExpressionType.Lambda) { throw new NotSupportedException("Unsupported expression type " + memberReferenceExpression.Type + "; expected Lambda"); } var body = memberReferenceExpression.Body; MemberExpression memberExpr; if (body.NodeType == ExpressionType.MemberAccess) { memberExpr = (MemberExpression)body; } else { throw new NotSupportedException("Unsupported expression type " + body.NodeType + "; expected MemberAccess or Call"); } if (memberExpr.Expression.NodeType != ExpressionType.Parameter) { throw new NotSupportedException("Unrecognized member access pattern"); } var fieldReference = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = fieldConverter.GetDatumFieldName(memberExpr.Member) } }; yield return(fieldReference); } }
public Term GenerateTerm(IQueryConverter queryConverter) { var sequenceTerm = new Term() { type = Term.TermType.MAKE_ARRAY, }; foreach (var obj in enumerable) { var datumTerm = new Term() { type = Term.TermType.DATUM, datum = queryConverter.Get <T>().ConvertObject(obj) }; sequenceTerm.args.Add(datumTerm); } return(sequenceTerm); }
public Term GenerateTerm(IQueryConverter queryConverter) { var insertTerm = new Term() { type = Term.TermType.INSERT, }; insertTerm.args.Add(tableTerm.GenerateTerm(queryConverter)); var objectArray = new Datum() { type = Datum.DatumType.R_ARRAY, }; var converter = queryConverter.Get <T>(); foreach (var obj in objects) { objectArray.r_array.Add(converter.ConvertObject(obj)); } insertTerm.args.Add(new Term() { type = Term.TermType.DATUM, datum = objectArray, }); insertTerm.optargs.Add(new Term.AssocPair() { key = "conflict", val = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = conflict.ToString().ToLower(), } } }); return(insertTerm); }
public Term GenerateTerm(IQueryConverter queryConverter) { var datumConverter = queryConverter.Get <TKey>(); var betweenTerm = new Term() { type = Term.TermType.BETWEEN, }; betweenTerm.args.Add(tableTerm.GenerateTerm(queryConverter)); betweenTerm.args.Add(new Term() { type = Term.TermType.DATUM, datum = datumConverter.ConvertObject(leftKey) }); betweenTerm.args.Add(new Term() { type = Term.TermType.DATUM, datum = datumConverter.ConvertObject(rightKey) }); if (!String.IsNullOrEmpty(indexName)) { betweenTerm.optargs.Add(new Term.AssocPair() { key = "index", val = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = indexName }, } }); } if (leftBound != Bound.Closed) { betweenTerm.optargs.Add(new Term.AssocPair() { key = "left_bound", val = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = "open" }, } }); } if (rightBound != Bound.Open) { betweenTerm.optargs.Add(new Term.AssocPair() { key = "right_bound", val = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = "closed" }, } }); } return(betweenTerm); }
private IEnumerable <Term> GetMembers(IQueryConverter queryConverter, out Term indexOrderBy) { var datumConverter = queryConverter.Get <T>(); var fieldConverter = datumConverter as IObjectDatumConverter; if (fieldConverter == null) { throw new NotSupportedException("Cannot map member access into ReQL without implementing IObjectDatumConverter"); } indexOrderBy = null; List <Term> retval = new List <Term>(orderByMembers.Length); foreach (var orderByMember in orderByMembers) { var memberReferenceExpression = orderByMember.Expression; var direction = orderByMember.Direction; if (!String.IsNullOrEmpty(orderByMember.IndexName)) { if (indexOrderBy != null) { throw new InvalidOperationException("Sorting by multiple indexes is not supported"); } var indexReference = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = orderByMember.IndexName } }; if (direction == OrderByDirection.Ascending) { var newFieldRef = new Term() { type = Term.TermType.ASC, }; newFieldRef.args.Add(indexReference); indexOrderBy = newFieldRef; } else if (direction == OrderByDirection.Descending) { var newFieldRef = new Term() { type = Term.TermType.DESC, }; newFieldRef.args.Add(indexReference); indexOrderBy = newFieldRef; } else { throw new NotSupportedException(); } } else { if (memberReferenceExpression.NodeType != ExpressionType.Lambda) { throw new NotSupportedException("Unsupported expression type " + memberReferenceExpression.Type + "; expected Lambda"); } var body = memberReferenceExpression.Body; MemberExpression memberExpr; if (body.NodeType == ExpressionType.Convert) { // If we're order-bying a primitive, the expr will be a cast to object for the Asc/Desc method call if (body.Type == typeof(object)) { body = ((UnaryExpression)body).Operand; } } if (body.NodeType == ExpressionType.MemberAccess) { memberExpr = (MemberExpression)body; } else { throw new NotSupportedException("Unsupported expression type " + body.NodeType + "; expected MemberAccess or Call"); } if (memberExpr.Expression.NodeType != ExpressionType.Parameter) { throw new NotSupportedException("Unrecognized member access pattern"); } var fieldReference = new Term() { type = Term.TermType.DATUM, datum = new Datum() { type = Datum.DatumType.R_STR, r_str = fieldConverter.GetDatumFieldName(memberExpr.Member) } }; if (direction == OrderByDirection.Ascending) { var newFieldRef = new Term() { type = Term.TermType.ASC, }; newFieldRef.args.Add(fieldReference); fieldReference = newFieldRef; } else if (direction == OrderByDirection.Descending) { var newFieldRef = new Term() { type = Term.TermType.DESC, }; newFieldRef.args.Add(fieldReference); fieldReference = newFieldRef; } else { throw new NotSupportedException(); } retval.Add(fieldReference); } } return(retval); }