This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.expr([ | |
{ | |
"sub_queries" : [ | |
{ | |
"sent_params" : { | |
"show_take_out_items" : null, | |
"show_in_store_items" : null, | |
"show_delivery_items" : null, | |
"location_id" : 448, | |
"category_id" : 5333 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db("foo").table("bar").filter( lamda doc: | |
doc["emails"].map(lamda email: email == "[email protected]").reduce( lambda acc, val: acc | val, False) | |
).run(connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Query 1 | |
cursor = r.db('test').table('test').filter(lambda doc: | |
(doc['status'] == 'open') & doc['baseaddresses'].map(lambda address: address == '[email protected]').reduce(lambda acc, val: acc | val) ).order_by('date').run() | |
for doc in cursor: | |
print doc | |
# Query 2 | |
cursor = r.db('test').table('test').filter(lambda doc: ((doc['status'] == 'open') | (doc['status'] == 'paused')) & doc['baseaddresses'].map(lambda address: address == '[email protected]').reduce(lambda acc, val: acc | val) ).order_by('date').run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"values_":{ | |
"1":1, | |
"2":{ | |
"values_":{ | |
"1":16, | |
"3":[ | |
{ | |
"values_":{ | |
"1":15, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('test').table('test').update(function(doc) { | |
return r.branch( | |
doc('skills').contains('html'), | |
doc.merge({skills: doc('skills').merge({'html': doc('skills')('html').add(3)})}), | |
doc.merge({skills: doc('skills').merge({'html': 3})}) | |
) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Suppose needed_category = [1,2,3] | |
r.db('foo').table('bar') | |
.filter( function(movie) { | |
r.expr( needed_category ).map( function(category) { | |
return category.eq(movie('category'); | |
}).redunce( function(left, right) | |
return left.or(right); | |
}, false) | |
}).run( connection, function(err, cursor) { ... } ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.table('polls').filter( function(poll) { | |
return poll("id").eq("d_you_want").and( | |
poll("processed").map( function(user) { return user.eq("forbidden_user") } ) // map if the user is the one we don't want | |
.reduce( function(left, right) { return left.or(right) }, false ) // compute a huge OR | |
.not() // Flip boolean | |
) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reduction := func(left, right r.Exp) r.Exp { return left.Or(right) } | |
filterFunc := func (job r.Exp) r.Exp { | |
return job.Attr("categories").Map(func (category r.Exp) r.Exp { | |
return category.Eq(job.Attr("category") | |
}).Reduce(reduction, false) | |
} | |
r.Table("heroes").Filter(r.Row.Attr("area").Eq("area")).Filter(filterFunc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.table("table_name").filter( function(score) { | |
return score("scoreboard")("teamPlayerParticipantStats")("externalizedData").map( function(data) { | |
return data("summonerName") | |
}).contains("some_string") | |
.or( | |
score("scoreboard")("otherTeamPlayerParticipantStats")("externalizedData").map( function(data) { | |
return data("summonerName") | |
}).contains("some_string") | |
) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.table('apps') | |
.orderBy("install_date") // order by date | |
.map( { | |
name: r.row("name"), | |
install_date: r.row("name").year().add("-").add(r.row("name").month()).add("-").add(r.row("name").day()) | |
}) |
OlderNewer