Here's my model class:
module.exports =
{
attributes:
{
id : {type: 'integer', unique: true, primaryKey: true},
title : {type:'string', required:true},
firstName : {type:'string', required:true},
lastName : {type:'string', required:true},
phone : {type:'string', required:true},
email : {type:'string', required:true, unique: true},
password : {type:'string', required:false},
roles : {type:'array'}
}
}
How to set index for the email and phone attributes? Also, is it possible to create compule index like index(firstName,lastName)?
I tried hard to search on Google but did not find any result about creating an index in model class.
You can add an index property to any attribute to create an index if your adapter supports it. You specify an index attribute.
Currently Waterline doesn't support multi-column indexes in the attributes definition.
Also, when adding a unique property to an attribute, an index will automatically be created for that attribute.
In your example, we just need to add index: true, to the phone attribute.
module.exports =
{
attributes:
{
id : {type: 'integer', unique: true, primaryKey: true},
title : {type:'string', required:true},
firstName : {type:'string', required:true},
lastName : {type:'string', required:true},
phone : {type:'string', required:true, index: true},
email : {type:'string', required:true, unique: true},
password : {type:'string', required:false},
roles : {type:'array'}
}
}
Although you are using Sailsjs, this is actually in the documentation for the Sails ORM which is Waterline - see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With