Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No happy-path for creating a table if it doesn't exist. #41

Closed
tdietrich513 opened this issue Mar 9, 2015 · 6 comments
Closed

No happy-path for creating a table if it doesn't exist. #41

tdietrich513 opened this issue Mar 9, 2015 · 6 comments

Comments

@tdietrich513
Copy link
Contributor

It would be nice to have exposed methods to create storage tables when they don't already exist, or at least get a TableReference to the table being managed by the TableSet<T> so that the standard methods can be used.

It seems like it should be easy enough to store the CloudTable reference generated in the TableSet constructor as a class member rather than having it be a local variable and expose that- if that approach works for you I can submit a pull request.

@dtretyakov
Copy link
Owner

Hi Tom,

Nice idea to add such feature. So it would be great if you extend ITableSet interface and add a new method a la CreateIfNotExists. Waiting for your PR.

@tdietrich513
Copy link
Contributor Author

Just submitted a very simple pull request which just exposes the CloudTable via a Table() method on the TableSet. Using this you could do tableSet.Table().CreateIfNotExists().

@dtretyakov
Copy link
Owner

Unfortunately such implementation exposes types from Azure .NET SDK library, but ITableSet should use only abstract data types. So it's better to just add pair of methods CreateIfNotExists / CreateIfNotExistsAsync in the interface like that:

private readonly CloudTable _cloudTable;
public TableSet(CloudTableClient cloudTableClient, string tableName)
{
    ...
    _cloudTable = cloudTableClient.GetTableReference(tableName);
    ...
}
public bool CreateIfNotExists()
{
    _cloudTable.CreateIfNotExists();
}
public Task<bool> CreateIfNotExistsAsync()
{
    _cloudTable.CreateIfNotExistsAsync();
}

@tdietrich513
Copy link
Contributor Author

I was considering taking that approach, but it seems like it opens Pandora's box of other CloudTable methods that might be desired, such as deleting the table if appropriate. But I'll yield to you on that design point. Submitting that pull request in a minute.

@dtretyakov
Copy link
Owner

Thanks, it was published:
https://www.nuget.org/packages/WindowsAzure.StorageExtensions/

@tdietrich513
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants