Function Database.createCollation
Creates and registers a collation function in the database.
void createCollation(T)
(
string name,
T fun
)
if (isFunctionPointer!T || isDelegate!T);
Parameters
Name | Description |
---|---|
name | The name that the function will have in the database. |
fun | a delegate or function that implements the collation. The function fun
must be nothrow ` and satisfy these criteria:
|
See Also
Example
// The implementation of the collation
int my_collation(string s1, string s2) nothrow
{
import std .uni : icmp;
import std .exception : assumeWontThrow;
return assumeWontThrow(icmp(s1, s2));
}
auto db = Database(":memory:");
db .createCollation("my_coll", &my_collation);
db .run("CREATE TABLE test (word TEXT);
INSERT INTO test (word) VALUES ('straße');
INSERT INTO test (word) VALUES ('strasses');");
auto word = db .execute("SELECT word FROM test ORDER BY word COLLATE my_coll")
.oneValue!string;
assert(word == "straße");