Skip to content

Instantly share code, notes, and snippets.

@lauramorillo
lauramorillo / creating_users.js
Last active July 3, 2016 16:04
First gcloud use for node.js
var gcloud = require('gcloud')({
projectId: 'testing-project',
apiEndpoint: 'http://localhost:8080'
});
function createUser(userData){
return new Promise((resolve, reject) => {
const key = datastore.key(['Users', userData.dni]);
datastore.save({ key: key, data: userData }, err => {
if (!err) {
@lauramorillo
lauramorillo / search.js
Last active July 3, 2016 17:39
Example for reading from Google Cloud Datastore with two fields
function usersByNameAndGreaterAge(name, age){
return new Promise((resolve, reject) => {
console.log(name.constructor.name + age.constructor.name);
const query = datastore.createQuery('Users')
.filter('name', name)
.filter('age', '>=', age);
datastore.runQuery(query, (err, users) => {
if (!err) {
resolve(users);
} else {
@lauramorillo
lauramorillo / index.yaml
Last active July 3, 2016 17:52
Index file containing the autogenerated keys for Google Cloud Datastore from emulator.
indexes:
# AUTOGENERATED
# This index.yaml is automatically updated whenever the Cloud Datastore
# emulator detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the "# AUTOGENERATED" marker line above.
# If you want to manage some indexes manually, move them above the marker line.
- kind: "Users"
properties: