DB Swap
Last post I mentioned about swapping the DB for some data. Well... I've done it. Mostly done it.
I've got code written for it. I still need to get the IaC set up for the DB and connection strings... blah blah... I got the code ... some code... written.
Ignoring the fact it probably won't work perfectly on the first attempt; I'm'a share!
Here's the original COSMOS version
public sealed class CollectorCardCountDetailsCosmosQuery : ICosmosQuery<ISelfSerialize>
{
private readonly ICosmosContainerQuery<CollectorCardCountDetailsModel> _cosmosContainerQuery;
private readonly StaticQueryDefinition _queryDefinition;
public CollectorCardCountDetailsCosmosQuery(CardId cardId, CollectorId collectorId) : this(new DiscoveryCollectionCosmosContainerQuery<CollectorCardCountDetailsModel>(), new CollectorCardCountDetailsCosmosQueryDefinition(cardId, collectorId)) { }
private CollectorCardCountDetailsCosmosQuery(ICosmosContainerQuery<CollectorCardCountDetailsModel> cosmosContainerQuery, StaticQueryDefinition queryDefinition)
{
_cosmosContainerQuery = cosmosContainerQuery;
_queryDefinition = queryDefinition;
}
public async Task<ISelfSerialize> ExecuteAsync()
{
ICollection<CollectorCardCountDetailsModel> results = await _cosmosContainerQuery.ExecuteAsync(_queryDefinition);
return results.FirstOrDefault(new CollectorCardCountDetailsModel());
}
}
and now the modified version
public sealed class CollectorCardCountDetailsCosmosQuery : ICosmosQuery<ISelfSerialize>
{
private readonly DiscoveryAzSqlQuery<CollectorCardCountDetailsModel> _cosmosContainerQuery;
private readonly IAzureSqlQueryDefinition _queryDefinition;
public CollectorCardCountDetailsCosmosQuery(CardId cardId, CollectorId collectorId) : this(new DiscoveryAzSqlQuery<CollectorCardCountDetailsModel>(), new CollectionCardsCosmosQueryDefinition(cardId, collectorId)) { }
private CollectorCardCountDetailsCosmosQuery(DiscoveryAzSqlQuery<CollectorCardCountDetailsModel> cosmosContainerQuery, IAzureSqlQueryDefinition queryDefinition)
{
_cosmosContainerQuery = cosmosContainerQuery;
_queryDefinition = queryDefinition;
}
public async Task<ISelfSerialize> ExecuteAsync()
{
IEnumerable<CollectorCardCountDetailsModel> results = await _query.ExecuteAsync(_queryDefinition).NoSync();
return results.FirstOrDefault(new CollectorCardCountDetailsModel());
}
}
This is almost a drop in replacement using a new "Source" and new "Query" types.
Sure; sure - there's some new interfaces, but I have a generalized form that both AzSql and Cosmos interfaces will derive from.
It's gonna be really close to a single wrapper to get the data out from any source! Once I get it working for the collection...
Make similar things more similar.
I'll get everything updated to the new form. That way if more gets switched away from Cosmos, it'll be ready to go.
Anyway; I gotta get back to working on making it work so I can get back to entering cards.