Skip to content
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

Added the ability to register custom SQL functions #26

Merged
merged 17 commits into from
Apr 13, 2017

Conversation

JoshuaWise
Copy link
Member

@JoshuaWise JoshuaWise commented Apr 9, 2017

This is a pending feature.

db.register(function add2(a, b) {return a + b;});
db.prepare("SELECT add2(?, ?)").pluck().get(12, 6); // => 18
db.prepare("SELECT add2(?, ?)").pluck().get("foo", "bar"); // => "foobar"

// throws an Error because the wrong number of arguments were passed
db.prepare("SELECT add2(?)").get(12);
db.prepare("SELECT add2(?, ?, ?)").get(12, 6, 22);

// available options
db.register({
  name: "void", // defaults to function.name
  deterministic: true, // improves performance if applicable (default false)
  varargs: true, // allows any number of arguments to be passed (default false)
  safeIntegers: true, // integer arguments will be Int64s (default false)
}, function () {});
db.prepare("SELECT void(?)").get(55); // => null
db.prepare("SELECT void(?, ?)").get(55, 19); // => null (not an error because varargs = true)

@JoshuaWise JoshuaWise merged commit 0d4e336 into master Apr 13, 2017
@JoshuaWise JoshuaWise deleted the custom_functions branch April 13, 2017 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant