Coder Social home page Coder Social logo

acosmosconnectionfunction's Introduction

Going to go in and out on CosmosDB Hopefully...

  1. Create new HTTP Trigger from Azure Function extensions.
  2. Try to talk to Cosmos Attribute...
  3. Add some app setting strings to local.settings.json: it needs to be "CosmosDBConnection" for the setting name
    "CosmosDBConnection": "AccountEndpoint=https://my-db.documents.azure.com:443/;AccountKey=fjAfOKqbDhKJoJoCSE5XhBUNnECQi2B97nnk0xK44mopXaWnhlMT4PHjIlEMpVvQVHmrbCBIE1mT6Vhw==;"
  1. Add Cosmos Extension by editing .csproj file: As of September 27th, 2018 I could only get this to build with the Beta...
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.22" />
    <PackageReference Include="Microsoft.Azure.Webjobs.Extensions.CosmosDB" Version="3.0.0-beta7"/>
  </ItemGroup>
  1. Run a restore or try to build.
  2. Then you can the CosmosDB attribute to your function:
public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req,
            [CosmosDB(
                databaseName: "CheeseBurgerDatabase",
                collectionName: "CollectionOfCheeseburgers",
                ConnectionStringSetting = "CosmosDBConnection"
                )] ICollector<CheeseBurger> item,
             ILogger log)
        {
            ... 

Okay, there are going to be dozen of different permutations for how to talk to Cosmos from your function.

First we need to distinguish between Binding to the Cosmos Attribute and Binding to the Document Client.

Then we need to visit how Functions can read, update, insert, and delete and entry, and entries.

So that's

2 types of connection patterns... * 4 types of operations * 2 (singular and plural) = 16 total functions:

Using the Document Client:

  1. Create an Entry

  2. Update an Entry

  3. Delete an Entry

  4. Read an Entry

  5. Create Entries

  6. Update Entries

  7. Delete Entries

  8. Read Entries

Binding to a "Cosmos Document", I guess that's what we're doing.

  1. Create an Entry - that doesn't make sense

  2. Update an Entry

  3. Delete an Entry - does that make sense?

  4. Read an Entry

  5. Create Entries

  6. Update Entries

  7. Delete Entries

  8. Read Entries

Proposed Function Names for DocumentClient:

  1. DocumentClientCreateEntry
  2. DocumentClientUpdateEntry
  3. DocumentClientDeleteAnEntry
  4. DocumentClientReadAnEntry

I'm also looking at these and thinking of all the permutations of return. The OkActionResult, from IActionResult, or just a string, or elaborate Http responses?

  1. DocumentClientCreateEntries
  2. DocumentClientUpdateEntries

Inside of update, we can also have update, or upsert. +1

  1. DocumentClientDeleteEntries
  2. DocumentClientReadEntries

Proposed Function Names for "CosmosDocBinding"

  1. CosmosDocBindingCreateAnEntry - this still doesn't make sense to me.
  2. CosmosDocBindingUpdateAnEntry
  3. CosmosDocBindingDeleteAnEntry - call and destroy lolz
  4. CosmosDocBindingReadAnEntry
  5. CosmosDocBindingCreateEntries - why? why wouldn't we always use our document client?
  6. CosmosDocBindingUpdateEntries - could be nice with docs you change regularly
  7. CosmosDocBindingDeleteEntries - call and destroy many lololz
  8. CosmosDocBindingReadEntries - Why would I bind and read like this?

First I'm going to start with some base functions that we should be able to use for the subsequent Functions.

  1. DocumentClientBase This will contain this header function declaration:
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;

public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", 
                Route = null)]HttpRequest req,
            [CosmosDB(
                databaseName: "ToDoItems",
                collectionName: "Items",
                ConnectionStringSetting = "CosmosDBConnection")] DocumentClient client,
            TraceWriter log)

Then we'll use that client to do all sorts of fun stuff.

Okay, so we also need these usings... Which don't come with the CosmosDB Extension. Let's try some other stuff.

Going to add this to .csproj : https://www.nuget.org/packages/Microsoft.Azure.DocumentDB/ But why does it say DocumentDB?

This is what my PackageReference list includes now:

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.22" />
    <PackageReference Include="Microsoft.Azure.Webjobs.Extensions.CosmosDB" Version="3.0.1-rc1"/>
    <PackageReference Include="Microsoft.Azure.DocumentDB" Version ="2.1.1" />
  </ItemGroup>

Okay that fixed the missing reference.

acosmosconnectionfunction's People

Contributors

timmyreilly avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.