mysql - findOne({key:value}) or findOne().where({key:value}) when querying database with waterline? -
i'm using waterline query mysql database sails. found 2 ways that.
don't know 1 better?
way, how handle error both case?
1. model.findone().where({key: value}).then(function(data){ console.log(data);}) 2. phase.findone({key: value}).then(function(data){ console.log(phase);})
either work. in method catch error seen below.
1. model.findone().where({key: value}).then(function(data){ console.log(data);}).catch(function(err){/*....*/}) 2. phase.findone({key: value}).then(function(data){ console.log(phase);}).catch(function(err){/*....*/})
another option
phase.findone({key: value}).exec(function(err, data){ if(err) /* error */ console.log(phase); })
also, if searching primary key can
phase.findone(pk)
https://github.com/balderdashy/waterline-docs/blob/master/query.md#query-language