Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(samples): updated samples code to use async await #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 18 additions & 59 deletions samples/document-snippets/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,101 +14,67 @@
*/

const snippets = {
create: (instanceId, clusterId) => {
create: async (instanceId, clusterId) => {
// [START bigtable_create_cluster]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);

cluster
.create()
.then(result => {
const cluster = result[0];
const operation = result[1];
const apiResponse = result[2];
})
.catch(err => {
// Handle the error.
});
const [clusterResponse,operationResponse,apiResponse] = await cluster
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.create();
// [END bigtable_create_cluster]
},

delete: (instanceId, clusterId) => {
delete: async (instanceId, clusterId) => {
// [START bigtable_delete_cluster]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);

cluster
.delete()
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
const [apiResponse] = await cluster
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.delete();
// [END bigtable_delete_cluster]
},

exists: (instanceId, clusterId) => {
exists: async (instanceId, clusterId) => {
// [START bigtable_exists_cluster]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);

cluster
.exists()
.then(result => {
const exists = result[0];
})
.catch(err => {
// Handle the error.
});
const [exists] = await cluster
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.exists();
// [END bigtable_exists_cluster]
},

get: (instanceId, clusterId) => {
get: async (instanceId, clusterId) => {
// [START bigtable_get_cluster]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);

cluster
.get()
.then(result => {
const cluster = result[0];
const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
const [clusterResponse,apiResponse] = await cluster
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.get();
// [END bigtable_get_cluster]
},

getMeta: (instanceId, clusterId) => {
getMeta: async (instanceId, clusterId) => {
// [START bigtable_cluster_get_meta]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);

cluster
.getMetadata()
.then(result => {
const metadata = result[0];
const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
const [metadata,apiResponse] = await cluster
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.getMetadata();
// [END bigtable_cluster_get_meta]
},

setMeta: (instanceId, clusterId) => {
setMeta: async (instanceId, clusterId) => {
// [START bigtable_cluster_set_meta]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
Expand All @@ -119,15 +85,8 @@ const snippets = {
nodes: 4,
};

cluster
.setMetadata(metadata)
.then(result => {
const operation = result[0];
const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
const [operation,apiResponse] = await cluster
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.setMetadata(metadata);
// [END bigtable_cluster_set_meta]
},
};
Expand Down
75 changes: 18 additions & 57 deletions samples/document-snippets/family.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,55 @@
*/

const snippets = {
createColmFamily: (instanceId, tableId, familyId) => {
createColmFamily: async (instanceId, tableId, familyId) => {
// [START bigtable_create_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.create()
.then(result => {
const family = result[0];
// let apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
const [familyResponse,apiResponse] = await family
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.create();
// [END bigtable_create_family]
},
existsFamily: (instanceId, tableId, familyId) => {
existsFamily: async (instanceId, tableId, familyId) => {
// [START bigtable_exists_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.exists()
.then(result => {
const exists = result[0];
})
.catch(err => {
// Handle the error.
});
const [exists] = await family
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.exists();
// [END bigtable_exists_family]
},
getFamily: (instanceId, tableId, familyId) => {
getFamily: async (instanceId, tableId, familyId) => {
// [START bigtable_get_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.get()
.then(result => {
const family = result[0];
// const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
const [familyResponse,apiResponse] = await family
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.get();
// [END bigtable_get_family]
},
getMetadata: (instanceId, tableId, familyId) => {
getMetadata: async (instanceId, tableId, familyId) => {
// [START bigtable_get_family_meta]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.getMetadata()
.then(result => {
const metaData = result[0];
// const apiResponse = result[1];
})
.catch(err => {
// Handle the error.
});
const [metaData,apiResponse] = await family
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.getMetadata();
// [END bigtable_get_family_meta]
},
setMetadata: (instanceId, tableId, familyId) => {
setMetadata: async (instanceId, tableId, familyId) => {
// [START bigtable_set_family_meta]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
Expand All @@ -104,32 +77,20 @@ const snippets = {
},
};

family
.setMetadata(metadata)
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
const [apiResponse] = await family
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.setMetadata(metadata);
// [END bigtable_set_family_meta]
},
delFamily: (instanceId, tableId, familyId) => {
delFamily: async (instanceId, tableId, familyId) => {
// [START bigtable_del_family]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
const family = table.family(familyId);

family
.delete()
.then(result => {
const apiResponse = result[0];
})
.catch(err => {
// Handle the error.
});
const [apiResponse] = await family
praveenqlogic marked this conversation as resolved.
Show resolved Hide resolved
.delete();
// [END bigtable_del_family]
},
};
Expand Down
Loading