I want to create a databease schema using the TypeScript. It's pretty simple, but I can't, or don't know how, there to define the key generator. In the User Guide, for example, such a code snippet(using JavaScript):
var schema = {
...
indexes: [
{
name: 'name', // index for case in-sensitive sorting
generator: function(obj) {
var name = obj.first + ' ' + obj.last;
return name.toLowerCase();
}
}
],
Can I define this generator using the library ydn.db-1.0.ts (downloaded from the YDN-DB server) or ydn-db.d.ts(downloaded from DefinitelyTyped)?
For example I wrote this ts file:
/// <reference path="typings/ydn-db/ydn-db.d.ts" />
module YdnDbTest
{
module DatabaseHelper
{
interface Place
{
Name: string;
Location: string;
}
var AppDbSchema: DatabaseSchemaJson =
{
stores:
[
{
name: "AppDbStore",
keyPath: "Name",
indexes:
[
{
name: "idxLocation",
keyPath: "Location",
unique: true,
}
]
}
]
}
}
, and I would like for the Location wrote a generator. I would like to write something like:
...
indexes:
[
{
name: "idxLocation",
generator: (record: Place): string =>
{ return record.Location.toLowerCase() },
unique: true,
}
]
...
Like I wrote generator for master key(Name), but it probably is not possible.