Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Azure Cosmos DB

Azure Cosmos DB

Azure Cosmos DB Presentation made during Node.js Paris meetup (https://www.meetup.com/fr-FR/Nodejs-Paris/events/256644371/)

Sylvain PONTOREAU

December 05, 2018
Tweet

More Decks by Sylvain PONTOREAU

Other Decks in Programming

Transcript

  1. const { database} = await client .databases .create({ id: databaseId

    }); const { container } = await database .container .create({ id: containerId }); @spontoreau Node.js Paris 12/05/2018 const client = new CosmosClient({ endpoint: myEndpoint, auth: { masterKey: myKey } });
  2. @spontoreau Node.js Paris 12/05/2018 const querySpec: SqlQuerySpec = { query:

    "SELECT root.firstName root.lastName FROM root WHERE root.email = @email", parameters: [{ name: "@email", value: "[email protected]" }] }; const { result } = await container .items .query(querySpec) .toArray(); const item = await container .item(id); const { body: readDoc } = item.read();
  3. @spontoreau Node.js Paris 12/05/2018 const person = { firstName: "Sylvain",

    lastName: "PONTOREAU", email: "[email protected]" }; const { body } = await container .items .create(person); if(body !== undefined) { console.log(body.id); } const item = await container .item(body.id); const { body: readDoc } = item.read(); readDoc.email = "sylvain @microsoft.com"; await item.replace(readDoc); await item.delete();
  4. @spontoreau Node.js Paris 12/05/2018 function hello(firstName, lastName) { return `Hello

    ${firstName} ${lastName}`; } SELECT udf.hello(root.firstName, root.lastName) as helloFullName FROM root
  5. @spontoreau Node.js Paris 12/05/2018 { "bindings": [ { "type": "cosmosDBTrigger",

    "name": "input", "direction": "in", "leaseCollectionName": "leases", "connectionStringSetting": "myConnectionString", "databaseName": "myDatabase", "collectionName": "myCollection", "createLeaseCollectionIfNotExists": true } ] } module.exports = function (context, input) { const id = input[0].id; context.log(`Document Id ${ id }`); context.done(); };