Skip to content

Commit

Permalink
quickstart code sample refactoring (Azure#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpapa authored and Christopher Anderson committed Aug 11, 2018
1 parent 6d6f9a5 commit 6259d17
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ Database Service](https://azure.microsoft.com/en-us/services/cosmos-db/). This p

[![latest npm badge](https://img.shields.io/npm/v/%40azure%2Fcosmos/latest.svg)](https://www.npmjs.com/package/@azure/cosmos)

```ts
import { CosmosClient } from "@azure/cosmos"
```js
// JavaScript
const cosmos = require('@azure/cosmos');
const CosmosClient = cosmos.CosmosClient;

const endpoint = "[hostendpoint]"; // Add your endpoint
const endpoint = "[hostendpoint]"; // Add your endpoint
const masterKey = "[database account masterkey]"; // Add the masterkey of the endpoint
const client = new CosmosClient({endpoint, auth: { masterKey }});
const client = new CosmosClient({ endpoint, auth: { masterKey } });

const databaseDefinition = { id: "sample database" };
const collectionDefinition = { id: "sample collection" };
const itemDefinition = { id: "hello world doc", content: "Hello World!" };
const databaseDefinition = { id: 'sample database' };
const collectionDefinition = { id: 'sample collection' };
const documentDefinition = { id: 'hello world doc', content: 'Hello World!' };

async function helloCosmos() {
const { database: db } = await client.databases.create(databaseDefinition);
console.log('created db');
const { database: db } = await client.databases.create(databaseDefinition);
console.log('created db');

const { container } = await db.containers.create(collectionDefinition);
console.log('created collection');
const { container } = await db.containers.create(collectionDefinition);
console.log('created collection');

const { body } = await container.items.create(documentDefinition);
console.log('Created item with content: ', body.content);
const { body } = await container.items.create(documentDefinition);
console.log('Created item with content: ', body.content);

await db.delete();
console.log("Deleted database");
});
await db.delete();
console.log('Deleted database');
}

helloCosmos().catch((err)=>{console.error(err)});
helloCosmos().catch(err => {
console.error(err);
});
```

## Useful links
Expand Down

0 comments on commit 6259d17

Please sign in to comment.