Skip to content

Commit 15acf11

Browse files
jabubakeGautamSharda
authored andcommitted
Updating README snippet (#192)
* Updating README with embedmd snippet (campoy/embedmd) Updating samples table * updating snippet
1 parent 1b0fe62 commit 15acf11

1 file changed

Lines changed: 36 additions & 24 deletions

File tree

handwritten/bigtable/README.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,43 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
6262

6363
### Using the client library
6464

65+
[embedmd]:# (samples/quickstart.js javascript /.*Imports/ /}\)\(\);/)
6566
```javascript
6667
// Imports the Google Cloud client library
6768
const Bigtable = require('@google-cloud/bigtable');
6869

69-
// Creates a client
70-
const bigtable = new Bigtable();
71-
72-
// The name for the new instance
73-
const instanceName = 'my-new-instance';
74-
75-
// Creates the new instance
76-
bigtable
77-
.createInstance(instanceName, {
78-
clusters: [
79-
{
80-
name: 'my-cluster',
81-
location: 'us-central1-c',
82-
nodes: 3,
83-
},
84-
],
85-
})
86-
.then(() => {
87-
console.log(`Instance ${instanceName} created.`);
88-
})
89-
.catch(err => {
90-
console.log('ERROR:', err);
91-
});
70+
// The name of the Cloud Bigtable instance
71+
const INSTANCE_NAME = 'my-bigtable-instance';
72+
// The name of the Cloud Bigtable table
73+
const TABLE_NAME = 'my-table';
74+
75+
(async () => {
76+
try {
77+
// Creates a Bigtable client
78+
const bigtable = new Bigtable();
79+
80+
// Connect to an existing instance:my-bigtable-instance
81+
const instance = bigtable.instance(INSTANCE_NAME);
82+
83+
// Connect to an existing table:my-table
84+
const table = instance.table(TABLE_NAME);
85+
86+
// Read a row from my-table using a row key
87+
let [singleRow] = await table.row('r1').get();
88+
89+
// Print the row key and data (column value, labels, timestamp)
90+
console.log(
91+
`Row key: ${singleRow.id}\nData: ${JSON.stringify(
92+
singleRow.data,
93+
null,
94+
4
95+
)}`
96+
);
97+
} catch (err) {
98+
// Handle error performing the read operation
99+
console.error(`Error reading row r1:`, err);
100+
}
101+
})();
92102
```
93103

94104
## Samples
@@ -98,7 +108,9 @@ has instructions for running the samples.
98108

99109
| Sample | Source Code | Try it |
100110
| --------------------------- | --------------------------------- | ------ |
101-
| Instances | [source code](https://github.com/googleapis/nodejs-bigtable/blob/master/samples/instances.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigtable&page=editor&open_in_editor=samples/instances.js,samples/README.md) |
111+
| Hello World | [source code](https://github.com/googleapis/nodejs-bigtable/blob/master/samples/hello-world/index.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigtable&page=editor&open_in_editor=samples/hello-world/index.js,samples/hello-world/README.md) |
112+
| Instance operations | [source code](https://github.com/googleapis/nodejs-bigtable/blob/master/samples/instances.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigtable&page=editor&open_in_editor=samples/instances.js,samples/README.md) |
113+
| Table operations | [source code](https://github.com/googleapis/nodejs-bigtable/blob/master/samples/tableadmin.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigtable&page=editor&open_in_editor=samples/tableadmin.js,samples/README.md) |
102114

103115
The [Cloud Bigtable Node.js Client API Reference][client-docs] documentation
104116
also contains samples.

0 commit comments

Comments
 (0)