The name that the function will have in the database.
a delegate or function that implements the function. fun must satisfy the following criteria:
or
Pass a null function pointer to delete the function from the database connection.
Tells SQLite whether the result of the function is deterministic, i.e. if the result is the same when called with the same parameters. Recent versions of SQLite perform optimizations based on this. Set to Deterministic.no otherwise.
string star(int count, string starSymbol = "*") { import std.range : repeat; import std.array : join; return starSymbol.repeat(count).join; } auto db = Database(":memory:"); db.createFunction("star", &star); assert(db.execute("SELECT star(5)").oneValue!string == "*****"); assert(db.execute("SELECT star(3, '♥')").oneValue!string == "♥♥♥");
// The implementation of the new function string myList(ColumnData[] args) { import std.array : appender; import std.string : format, join; auto app = appender!(string[]); foreach (arg; args) { if (arg.type == SqliteType.TEXT) app.put(`"%s"`.format(arg)); else app.put("%s".format(arg)); } return app.data.join(", "); } auto db = Database(":memory:"); db.createFunction("my_list", &myList); auto list = db.execute("SELECT my_list(42, 3.14, 'text', NULL)").oneValue!string; assert(list == `42, 3.14, "text", null`);
Creates and registers a new function in the database.
If a function with the same name and the same arguments already exists, it is replaced by the new one.
The memory associated with the function will be released when the database connection is closed.