public void LikeClauseIsCorrectlyTranslated(string query)
        {
            var parsedQuery = DataApiSqlQueryParser.Parse(query);
            var actual      = AggregatePipelineBuilder.Build(parsedQuery);

            Assert.That(actual.ToString(), Contains.Substring("$regex"));
        }
Exemple #2
0
        public async IAsyncEnumerable <GenericDataContainer> GetManyAsync(
            string dataType,
            string whereArguments,
            string orderByArguments,
            uint?limit = null)
        {
            if (whereArguments != null && (whereArguments.Contains("{") || whereArguments.Contains("}")))
            {
                throw new FormatException(); // SECURITY NOTE: This is crucial in order to prevent SQL-injection like attacks (only with MongoDB-syntax instead of SQL)
            }
            var collection = rdDataClient.DataDatabase.GetCollection <BsonDocument>(dataType);

            var parsedQuery = new DataApiSqlQuery(
                fromArguments: dataType,
                whereArguments: whereArguments,
                orderByArguments: orderByArguments,
                limitArguments: limit >= 0 ? limit.ToString() : null);
            var pipeline = AggregatePipelineBuilder.Build(parsedQuery, limit);

            using var cursor = await collection.AggregateAsync(pipeline);

            while (await cursor.MoveNextAsync())
            {
                foreach (var result in cursor.Current)
                {
                    yield return(BsonSerializer.Deserialize <GenericDataContainer>(result));
                }
            }
        }
Exemple #3
0
        public async IAsyncEnumerable <BsonDocument> SearchAsync(DataApiSqlQuery parsedQuery, uint?maxResults = null)
        {
            var pipeline   = AggregatePipelineBuilder.Build(parsedQuery, maxResults);
            var collection = rdDataClient.DataDatabase.GetCollection <BsonDocument>(parsedQuery.FromArguments);

            using var cursor = await collection.AggregateAsync(pipeline);

            while (await cursor.MoveNextAsync())
            {
                foreach (var result in cursor.Current)
                {
                    yield return(result);
                }
            }
        }