Pass the type generated by the Azure Storage type provider in F #

I am trying to get my head around type providers in F # and what they can be used for. I have the following problem:

I have a series of JSON objects in Azure Blob storage, stored as follows:

container/YYYY/MM/DD/file.json 

I can easily go to a specific file on a specific date using a type provider. For example, I can access the JSON object as a string on May 5th as

 type Azure = AzureTypeProvider<"ConnectionString"> let containers = Azure.Containers.``container``.``2017/``.``05/``.``05/``.``file.json``.Read() 

How can I take a user input line, say, "2017-05-05" and get the corresponding JSON object with a safe type? Should I use type providers?

+5
source share
1 answer

You encounter a common β€œproblem” with the nature of many TPs, especially those that offer a schema against actual data, because it mixes the line between data and types, you need to know when working in a mode that works well with static types (i.e. i.e., during compilation, you use the blob container scheme that you work with) or work in a way that is essentially dynamic.

Here you have several options.

  • Let's get back to the native .NET SDK. Each blob / container has AsCloudBlob() or AsCloudContainer() methods, so you can use TP for the bits you know, for example, the name of the container, possibly the top level folder, etc., and then return to the native SDK for the weak -types.

  • Starting with the latest version of TP, programmatic access is now supported in several ways: -

    • You can use indexers to get unsafe descriptors for blob, for example. let blob = Azure.Containers.container.["2017/05/05/file.json"] . There is no guarantee that blob exists, so you need to check that you, etc.

    • You can use the TryGetBlockBlob() method, which returns the blob option async - behind the scenes, it will check if the blob exists or not, and then returns either None or Some blob.

You can see more examples of all of these alternatives here .

  1. If you know the front path you work with (at compile time - maybe some well-known paths, etc.), you can also use offline support in TP to create an explicit blob scheme at compile time without requiring a real account storage facilities.
+6
source