-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: user-defined functions #3740
Comments
Once we get #3636 in, it would be trivial for users to add queries to a separate table, and you could theoretically do something like:
This isn't quite what you suggested here, but it's close. It would be useful if we could parameterize the query, or store some subset of the Term tree from a given query - but I suppose that depends on how #3636 is settled. |
This is similar to #3739 and as @danielmewes mentioned over there you can accomplish something similar on the client-side. |
Here's what I would propose for this (note that this is similar to what was suggested in #1863, but allows for runtime parameterization):
|
It would be amazing to have something like r.cron("* * */1 * *", r.rql(....)) |
@thelinuxlich, I think that would be a cool use case for inserting into the r.db("rethinkdb").table("jobs").insert(
{ "type": "periodic_query", "info": { "query": r.rql(...) } }) |
@Tryneus I was about to mention the jobs table but I was unsure if it fits the case :) |
I'm not sure if the We should probably have a separate pseudo table ( |
Another proposal by @skizzerz #849 (comment) Bumping this issue, as the thought just occurred to me not too long ago that a client-visible macroing system would be incredibly useful to make it easier to use very complex queries, especially when you want to run the same query both manually in data explorer as well as multiple places throughout an application. My thoughts on how this would look are as follows (names chosen to be consistent with the db/table/index commands): r.macroCreate(macroName, function) → objectThis would create a macro with the given macroName using the given function. The function can return anything and can take parameters, which are passed in when executing the macro. Macro names are case-sensitive, must be unique, and are global across all databases. Example: Creates a macro to compute a golfer's score for a game. r.macroCreate('getscore',
function (player, net) {
return r.branch(
net.default(true),
player('gross_score').sub(player('course_handicap'),
player('gross_score')
);
}
).run(conn, callback); r.macroDrop(macroName) → objectDeletes a previously-created macro. Example r.macroDrop('getscore').run(conn, callback); r.macroRename(oldName, newName) → objectRenames a macro. Example r.macroRename('getscore', 'getScore').run(conn, callback); r.do([args]*, macroName) → anyany.do([args]*, macroName) → anyThis adds two overloads to the existing do command to execute a macro. In both overloads, the given macroName is executed as if the macro function itself were present in the do command instead of simply the name. For the first overload, if args are specified, they are passed in exactly as they would be if a function were passed to r.do. For the second overload, any specified arguments are passed after the previous result (in other words, the first argument would be the result of executing the part before .do, and any other arguments are as specified in the command). Examples r.do(
r.table('players').get('f19b5f16-ef14-468f-bd48-e194761df255'),
true,
'getscore'
).run(conn, callback);
// In this example, the "player" argument is the result of .get() and the "net" argument
// is the first argument passed into .do()
r.table('players').get('f19b5f16-ef14-468f-bd48-e194761df255').do(true, 'getscore').run(conn, callback); If overloading do is not desirable (and the syntax is rather clunky in order to make it fit with existing overloads), consider the following commands instead that achieve the same purpose:
Note that in this version, the macroName comes first, which is convenient when it is only a string as opposed to a potentially-gigantic function. The do overloads above kept the macroName last in order to be consistent with where the function would normally be located. |
I think that user-defined functions that run on the cluster would be a nice feature to have.
Examples:
The text was updated successfully, but these errors were encountered: