public void avoid_shadowing_seralized_ast_lambda_expressions() { //Full Query / No Seralization var filter = R.Expr(R.Array(5, 4, 3)).Filter(doc => IsForbidden(doc).Not()); var result = filter.RunResult <List <int> >(conn); result.Dump(); result.Should().BeEquivalentTo(5, 4); //RESULT: //[5,4] //This is unbound? ReqlFunction1 func = expr => IsForbidden(expr).Not(); var str = ReqlRaw.ToRawString(func); str.Dump(); var rawFilter = ReqlRaw.FromRawString(str); var filterWithRaw = R.Expr(R.Array(5, 4, 3)).Filter(rawFilter); //Not Allowed in C# //var filterWithRaw = R.Expr(R.Array(5, 4, 3)).Filter( x => rawFilter.SomethingElse ); var result2 = filterWithRaw.RunResult <List <int> >(conn); result2.Should().BeEquivalentTo(5, 4); //ExtensionsForTesting.Dump(result2); }
public void can_stich_together_some_crazy_reql_expr_thing() { ClearDefaultTable(); var foos = new[] { new Foo { id = "a", Baz = 1, Bar = 1, Idx = "qux" }, new Foo { id = "b", Baz = 2, Bar = 2, Idx = "bub" }, new Foo { id = "c", Baz = 3, Bar = 3, Idx = "qux" } }; R.Db(DbName).Table(TableName).Insert(foos).Run(conn); ReqlFunction1 filter = expr => expr["Bar"].Gt(2); var str = ReqlRaw.ToRawString(filter); str.Dump(); var filterTerm = ReqlRaw.FromRawString(str); var result = table.Filter(filterTerm).RunResult <List <Foo> >(conn); result.Dump(); result[0].id.Should().Be(foos[2].id); result[0].Baz.Should().Be(3); result.Count.Should().Be(1); }
/// <summary> /// <para>Create a new secondary index on a table. Secondary indexes improve the speed of many read queries at the slight cost of increased storage space and decreased write performance. For more information about secondary indexes, read the article "<a href="/docs/secondary-indexes/">Using secondary indexes in RethinkDB</a>."</para> /// </summary> /// <example><para>Example: Create a simple index based on the field <code>postId</code>.</para> /// <code>r.table('comments').indexCreate('postId').run(conn, callback) /// </code></example> public IndexCreate IndexCreate(Object expr, ReqlFunction1 func1) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(expr); arguments.CoerceAndAdd(func1); return(new IndexCreate(arguments)); }
/// <summary> /// Mounts the bucket. Mount is necessary before using a bucket to ensure the existence of tables and indexes. /// </summary> public async Task MountAsync(CancellationToken cancelToken = default) { if (this.Mounted) { return; } var filesTableResult = await EnsureTable(this.fileTableName, cancelToken) .ConfigureAwait(false); if (filesTableResult.TablesCreated == 1) { //index the file paths of completed files and status ReqlFunction1 pathIx = row => { return(R.Array(row[FileInfo.StatusJsonName], row[FileInfo.FileNameJsonName], row[FileInfo.FinishedDateJsonName])); }; await CreateIndex(this.fileTableName, this.fileIndex, pathIx, cancelToken) .ConfigureAwait(false); //prefix IX ReqlFunction1 prefixIx = doc => { //return r.array(doc[FileInfo.FileNameJsonName].split("/").slice(1, -1), doc[FileInfo.FinishedDateJsonName]); return(R.Branch(doc[FileInfo.StatusJsonName].Eq(Status.Completed), R.Array(doc[FileInfo.FileNameJsonName].Split("/").Slice(1, -1), doc[FileInfo.FinishedDateJsonName]), R.Error())); }; await CreateIndex(this.fileTableName, this.fileIndexPrefix, prefixIx, cancelToken) .ConfigureAwait(false); } // CHUNK TAABLE INDEXES var chunkTableResult = await EnsureTable(this.chunkTableName, cancelToken) .ConfigureAwait(false); if (chunkTableResult.TablesCreated == 1) { //Index the chunks and their parent [fileid, n]. ReqlFunction1 chunkIx = row => { return(R.Array(row[Chunk.FilesIdJsonName], row[Chunk.NumJsonName])); }; await CreateIndex(this.chunkTableName, this.chunkIndexName, chunkIx, cancelToken) .ConfigureAwait(false); } this.Mounted = true; }
/// <summary> /// Helper function to create an index /// </summary> protected internal async Task <JArray> CreateIndex(string tableName, string indexName, ReqlFunction1 indexFunc, CancellationToken cancelToken = default) { await this.db.Table(tableName) .IndexCreate(indexName, indexFunc).RunAtomAsync <JObject>(conn, cancelToken) .ConfigureAwait(false); return(await this.db.Table(tableName) .IndexWait(indexName).RunAtomAsync <JArray>(conn, cancelToken) .ConfigureAwait(false)); }
/// <summary> /// <para>Finds the maximum element of a sequence.</para> /// </summary> /// <example><para>Example: Return the maximum value in the list <code>[3, 5, 7]</code>.</para> /// <code>r.expr([3, 5, 7]).max().run(conn, callback); /// </code></example> public Max max ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Max (arguments ); }
/// <summary> /// <para>Transform each element of one or more sequences by applying a mapping function to them. If <code>map</code> is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence.</para> ///</summary> /// <example><para>Example: Return the first five squares.</para> /// <code>r.expr([1, 2, 3, 4, 5]).map(function (val) { /// return val.mul(val); /// }).run(conn, callback); /// // Result passed to callback /// [1, 4, 9, 16, 25] /// </code></example> public Map map ( Object expr, ReqlFunction1 func1 ) { Arguments arguments = new Arguments(); arguments.CoerceAndAdd(expr); arguments.CoerceAndAdd(func1); return new Map (arguments); }
/// <summary> /// <para>Takes a stream and partitions it into multiple groups based on the /// fields or functions provided. Commands chained after <code>group</code> will be /// called on each of these grouped sub-streams, producing grouped data.</para> /// </summary> /// <example><para>Example: What is each player's best game?</para> /// <code>r.table('games').group('player').max('points').run(conn, callback) /// </code></example> public Group group ( ReqlFunction1 func1, ReqlFunction1 func1A, Object exprA, Object exprB ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(exprA); arguments.CoerceAndAdd(exprB); return new Group (arguments ); }
/// <summary> /// <para>Sums all the elements of a sequence. If called with a field name, /// sums all the values of that field in the sequence, skipping elements /// of the sequence that lack that field. If called with a function, /// calls that function on every element of the sequence and sums the /// results, skipping elements of the sequence where that function returns /// <code>null</code> or a non-existence error.</para> /// </summary> /// <example><para>Example: What's 3 + 5 + 7?</para> /// <code>r.expr([3, 5, 7]).sum().run(conn, callback) /// </code></example> public Sum sum ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Sum (arguments ); }
/// <summary> /// <para>Replace documents in a table. Accepts a JSON document or a ReQL expression, and replaces /// the original document with the new one. The new document must have the same primary key /// as the original document.</para> /// </summary> /// <example><para>Example: Replace the document with the primary key <code>1</code>.</para> /// <code>r.table("posts").get(1).replace({ /// id: 1, /// title: "Lorem ipsum", /// content: "Aleas jacta est", /// status: "draft" /// }).run(conn, callback) /// </code></example> public Replace replace ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Replace (arguments ); }
/// <summary> /// <para>Loop over a sequence, evaluating the given write query for each element.</para> /// </summary> /// <example><para>Example: Now that our heroes have defeated their villains, we can safely remove them from the villain table.</para> /// <code>r.table('marvel').forEach(function(hero) { /// return r.table('villains').get(hero('villainDefeated')).delete() /// }).run(conn, callback) /// </code></example> public ForEach forEach ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new ForEach (arguments ); }
/// <summary> /// <para>Returns whether or not a sequence contains all the specified values, or if functions are /// provided instead, returns whether or not a sequence contains values matching all the /// specified functions.</para> /// </summary> /// <example><para>Example: Has Iron Man ever fought Superman?</para> /// <code>r.table('marvel').get('ironman')('opponents').contains('superman').run(conn, callback) /// </code></example> public Contains contains ( ReqlFunction1 func1, ReqlFunction1 func1A, ReqlFunction1 func1B, ReqlFunction1 func1C ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(func1B); arguments.CoerceAndAdd(func1C); return new Contains (arguments ); }
/// <summary> /// <para>Merge two or more objects together to construct a new object with properties from all. When there is a conflict between field names, preference is given to fields in the rightmost object in the argument list.</para> /// </summary> /// <example><para>Example: Equip Thor for battle.</para> /// <code>r.table('marvel').get('thor').merge( /// r.table('equipment').get('hammer'), /// r.table('equipment').get('pimento_sandwich') /// ).run(conn, callback) /// </code></example> public Merge merge ( ReqlFunction1 func1, ReqlFunction1 func1A, Object exprA, Object exprB ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(exprA); arguments.CoerceAndAdd(exprB); return new Merge (arguments ); }
internal Group group ( ReqlFunction1 func1, ReqlFunction1 func1A, ReqlFunction1 func1B, Object exprA ) { return Group ( func1, func1A, func1B, exprA ); }
internal IndexCreate indexCreate(Object expr, ReqlFunction1 func1) { return(IndexCreate(expr, func1)); }
internal Max max ( ReqlFunction1 func1 ) { return Max ( func1 ); }
internal Min min ( ReqlFunction1 func1 ) { return Min ( func1 ); }
internal Avg avg ( ReqlFunction1 func1 ) { return Avg ( func1 ); }
internal Sum sum ( ReqlFunction1 func1 ) { return Sum ( func1 ); }
/// <summary> /// <para>Merge two or more objects together to construct a new object with properties from all. When there is a conflict between field names, preference is given to fields in the rightmost object in the argument list.</para> /// </summary> /// <example><para>Example: Equip Thor for battle.</para> /// <code>r.table('marvel').get('thor').merge( /// r.table('equipment').get('hammer'), /// r.table('equipment').get('pimento_sandwich') /// ).run(conn, callback) /// </code></example> public Merge merge ( ReqlFunction1 func1, ReqlFunction1 func1A, ReqlFunction1 func1B, ReqlFunction1 func1C ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(func1B); arguments.CoerceAndAdd(func1C); return new Merge (arguments ); }
/// <summary> /// <para>Update JSON documents in a table. Accepts a JSON document, a ReQL expression, or a /// combination of the two. You can pass options like <code>returnChanges</code> that will return the old /// and new values of the row you have modified.</para> /// </summary> /// <example><para>Example: Update the status of the post with <code>id</code> of <code>1</code> to <code>published</code>.</para> /// <code>r.table("posts").get(1).update({status: "published"}).run(conn, callback) /// </code></example> public Update update ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Update (arguments ); }
/// <summary> /// <para>Get all the documents for which the given predicate is true.</para> /// <para><code>filter</code> can be called on a sequence, selection, or a field containing an array of /// elements. The return type is the same as the type on which the function was called on.</para> /// <para>The body of every filter is wrapped in an implicit <code>.default(false)</code>, which means that /// if a non-existence errors is thrown (when you try to access a field that does not exist /// in a document), RethinkDB will just ignore the document. /// The <code>default</code> value can be changed by passing an object with a <code>default</code> field. /// Setting this optional argument to <code>r.error()</code> will cause any non-existence errors to /// return a <code>RqlRuntimeError</code>.</para> /// </summary> /// <example><para>Example: Get all the users that are 30 years old.</para> /// <code>r.table('users').filter({age: 30}).run(conn, callback) /// </code></example> public Filter filter ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Filter (arguments ); }
public Funcall do_ ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Funcall (arguments ); }
/// <summary> /// <para>Concatenate one or more elements into a single sequence using a mapping function.</para> /// </summary> /// <example><para>Example: Construct a sequence of all monsters defeated by Marvel heroes. The field "defeatedMonsters" is an array of one or more monster names.</para> /// <code>r.table('marvel').concatMap(function(hero) { /// return hero('defeatedMonsters') /// }).run(conn, callback) /// </code></example> public ConcatMap concatMap ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new ConcatMap (arguments ); }
/// <summary> /// <para>Handle non-existence errors. Tries to evaluate and return its first argument. If an /// error related to the absence of a value is thrown in the process, or if its first /// argument returns <code>null</code>, returns its second argument. (Alternatively, the second argument /// may be a function which will be called with either the text of the non-existence error /// or <code>null</code>.)</para> /// </summary> /// <example><para>Example: Suppose we want to retrieve the titles and authors of the table <code>posts</code>. /// In the case where the author field is missing or <code>null</code>, we want to retrieve the string /// <code>Anonymous</code>.</para> /// <code>r.table("posts").map( function(post) { /// return { /// title: post("title"), /// author: post("author").default("Anonymous") /// } /// }).run(conn, callback) /// </code></example> public Default default_ ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Default (arguments ); }
/// <summary> /// <para>Get the indexes of an element in a sequence. If the argument is a predicate, get the indexes of all elements matching it.</para> /// </summary> /// <example><para>Example: Find the position of the letter 'c'.</para> /// <code>r.expr(['a','b','c']).offsetsOf('c').run(conn, callback) /// </code></example> public OffsetsOf offsetsOf ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new OffsetsOf (arguments ); }
/// <summary> /// <para>Takes a stream and partitions it into multiple groups based on the /// fields or functions provided. Commands chained after <code>group</code> will be /// called on each of these grouped sub-streams, producing grouped data.</para> /// </summary> /// <example><para>Example: What is each player's best game?</para> /// <code>r.table('games').group('player').max('points').run(conn, callback) /// </code></example> public Group group ( ReqlFunction1 func1, ReqlFunction1 func1A, ReqlFunction1 func1B, ReqlFunction1 func1C ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(func1B); arguments.CoerceAndAdd(func1C); return new Group (arguments ); }
/// <summary> /// <para>Sort the sequence by document values of the given key(s). To specify /// the ordering, wrap the attribute with either <code>r.asc</code> or <code>r.desc</code> /// (defaults to ascending).</para> /// <para>Sorting without an index requires the server to hold the sequence in /// memory, and is limited to 100,000 documents (or the setting of the <code>arrayLimit</code> option for <a href="/api/javascript/run">run</a>). Sorting with an index can /// be done on arbitrarily large tables, or after a <code>between</code> command /// using the same index.</para> /// </summary> /// <example><para>Example: Order all the posts using the index <code>date</code>. </para> /// <code>r.table('posts').orderBy({index: 'date'}).run(conn, callback) /// </code> /// <para>The index must have been previously created with <a href="/api/javascript/index_create/">indexCreate</a>.</para> /// <code>r.table('posts').indexCreate('date').run(conn, callback) /// </code> /// <para>You can also select a descending ordering:</para> /// <code>r.table('posts').orderBy({index: r.desc('date')}).run(conn, callback) /// </code></example> public OrderBy orderBy ( ReqlFunction1 func1, ReqlFunction1 func1A, Object exprA, Object exprB ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(exprA); arguments.CoerceAndAdd(exprB); return new OrderBy (arguments ); }
/// <summary> /// <para>Averages all the elements of a sequence. If called with a field name, /// averages all the values of that field in the sequence, skipping /// elements of the sequence that lack that field. If called with a /// function, calls that function on every element of the sequence and /// averages the results, skipping elements of the sequence where that /// function returns <code>null</code> or a non-existence error.</para> /// </summary> /// <example><para>Example: What's the average of 3, 5, and 7?</para> /// <code>r.expr([3, 5, 7]).avg().run(conn, callback) /// </code></example> public Avg avg ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Avg (arguments ); }
internal Group group ( ReqlFunction1 func1, ReqlFunction1 func1A, Object exprA, Object exprB ) { return Group ( func1, func1A, exprA, exprB ); }
/// <summary> /// <para>Returns whether or not a sequence contains all the specified values, or if functions are /// provided instead, returns whether or not a sequence contains values matching all the /// specified functions.</para> /// </summary> /// <example><para>Example: Has Iron Man ever fought Superman?</para> /// <code>r.table('marvel').get('ironman')('opponents').contains('superman').run(conn, callback) /// </code></example> public Contains contains ( Object exprA, ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(exprA); arguments.CoerceAndAdd(func1); return new Contains (arguments ); }
/// <summary> /// <para>Count the number of elements in the sequence. With a single argument, count the number /// of elements equal to it. If the argument is a function, it is equivalent to calling /// filter before count.</para> /// </summary> /// <example><para>Example: Just how many super heroes are there?</para> /// <code>r.table('marvel').count().add(r.table('dc').count()).run(conn, callback) /// </code></example> public Count count ( ReqlFunction1 func1 ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); return new Count (arguments ); }
public Funcall do_ ( Object expr, ReqlFunction1 func1 ) { Arguments arguments = new Arguments(); arguments.CoerceAndAdd(expr); arguments.CoerceAndAdd(func1); return new Funcall (arguments); }
/// <summary> /// <para>Join tables using a field or function on the left-hand sequence matching primary keys or secondary indexes on the right-hand table. <code>eqJoin</code> is more efficient than other ReQL join types, and operates much faster. Documents in the result set consist of pairs of left-hand and right-hand documents, matched when the field on the left-hand side exists and is non-null and an entry with that field's value exists in the specified index on the right-hand side.</para> /// <para>Example: Match players with the games they've played against one another.</para> /// <para><code>js /// r.table('players').eqJoin('gameId', r.table('games')).run(conn, callback)</code></para> /// </summary> /// <example></example> public EqJoin eqJoin ( ReqlFunction1 func1, Object exprA ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(exprA); return new EqJoin (arguments ); }
/// <summary> /// <para>Sort the sequence by document values of the given key(s). To specify /// the ordering, wrap the attribute with either <code>r.asc</code> or <code>r.desc</code> /// (defaults to ascending).</para> /// <para>Sorting without an index requires the server to hold the sequence in /// memory, and is limited to 100,000 documents (or the setting of the <code>arrayLimit</code> option for <a href="/api/javascript/run">run</a>). Sorting with an index can /// be done on arbitrarily large tables, or after a <code>between</code> command /// using the same index.</para> /// </summary> /// <example><para>Example: Order all the posts using the index <code>date</code>. </para> /// <code>r.table('posts').orderBy({index: 'date'}).run(conn, callback) /// </code> /// <para>The index must have been previously created with <a href="/api/javascript/index_create/">indexCreate</a>.</para> /// <code>r.table('posts').indexCreate('date').run(conn, callback) /// </code> /// <para>You can also select a descending ordering:</para> /// <code>r.table('posts').orderBy({index: r.desc('date')}).run(conn, callback) /// </code></example> public OrderBy orderBy ( ReqlFunction1 func1, ReqlFunction1 func1A, ReqlFunction1 func1B, ReqlFunction1 func1C ) { Arguments arguments = new Arguments(this); arguments.CoerceAndAdd(func1); arguments.CoerceAndAdd(func1A); arguments.CoerceAndAdd(func1B); arguments.CoerceAndAdd(func1C); return new OrderBy (arguments ); }
internal Group group ( ReqlFunction1 func1, ReqlFunction1 func1A, ReqlFunction1 func1B, ReqlFunction1 func1C ) { return Group ( func1, func1A, func1B, func1C ); }