2017-01-08 11 views
0

私はNodejsを使用しており、カウントを取得するクエリがあります。私はcount > 0がtrueを返すかどうかをチェックしたい、そうでなければfalseを返す。 しかし、私はnodejsを使ってそれを処理することはできません。count> 0の場合、sequelize countと返すブール値をチェックする方法

const uidIsConnection = (model, entityId, uid) => 
 
\t \t models[model].count({ 
 
\t \t \t where: { entityId, profileId: uid } 
 
\t \t }); 
 

 
var data = uidIsConnection('ProfileData', user.id, id); 
 
//I want this variable data to have the value of true or false

は今、dataリターンが約束:

Promise { 
 
    _bitField: 2097152, 
 
    _fulfillmentHandler0: undefined, 
 
    _rejectionHandler0: undefined, 
 
    _promise0: undefined, 
 
    _receiver0: undefined, 
 
    _boundTo: profiledata }

はどのように約束し、count > 0に応じて、ブール値を返さないために は、ここに私のコードですか?

答えて

1

Sequelize countはあなたのdataが解決しているPromiseを返します。あなたがすべき機能の実際のカウントを取得するには:将来的には

const uidIsConnection = (model, entityId, uid) => 
     models[model].count({ 
      where: { entityId, profileId: uid } 
     }); 

uidIsConnection('ProfileData', user.id, id).then(count => { 
    console.log('boolean version of count', !!count); 
}); 

を、あなたは同期的にこれを解決するためにasycawaitを使用することができますが、機能がwidely supported yetではありません。

関連する問題