2017-03-10 21 views
0

nodejsとgoogle cloudデータストアを使用してすべてのデータを取得する方法があります。Google Datastoreのクエリ(nodejsを使用)

var query = ContactModel.query();//contact model is a schema which instantiates gstore schema 

query.run().then((result) => { 
    const response = result[0]; 
    var entities  = response.entities; 
    callback('',entities); 
}); 

カスタムクエリを実行する方法や、単にnodejsとgoogle-datastoreを使用してフィルタを設定する方法はありますか。 nodejsとgoogle-dataStoreを使用しているクエリの例は1つしか見つかりませんでした。

答えて

0
var query = ContactModel.query() 

query.filter(key, value) 

query.run().then((result) => { 
    const response = result[0], 
     entities = response.entities 

    callback('',entities) 
}) 

フィルタ関数は、キーと値に対してフィルタ処理し、フィルタ関数は、オプションの第三の引き数に等しいような状態である第1、より少ない、などを取る..しかし、あなたは2つだけを提供する場合それが等しいかどうかをチェックします。制限、注文、groupByなどの他の機能があります。hereのドキュメントを探してください。

0

は、私はあなたがgstore-nodeを使用することをお勧め、それは非常にシンプルかつ効率的なAPIを持ち、そしてdocumentationは、すべての要素を一覧表示する方法の詳細ですexample in the documentationのための高度なquerys

を作成する方法の多くの例があり

// blog-post.model.js 

// Create Schema 
const blogPostSchema = new gstore.Schema({ 
    title : { type: 'string' }, 
    isDraft: { type: 'boolean' } 
}); 

// List query settings 
const listQuerySettings = { 
    limit : 10, 
    order : { property: 'title', descending: true }, // descending defaults to false and is optional 
    select : 'title', 
    ancestors : ['Parent', 123], // will add an "hasAncestor" filter 
    filters : ['isDraft', false] // operator defaults to "=", 
}; 

// Add settings to schema 
blogPostSchema.queries('list', listQuerySettings); 

// Create Model 
const BlogPost = gstore.model('BlogPost', blogPostSchema); 
関連する問題