|
@@ -262,6 +262,21 @@ namespace TEAMModelOS.SDK.DI
|
|
AsyncPageable<int> query = container.container.GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
|
|
AsyncPageable<int> query = container.container.GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
|
|
return await ResultsFromFeedIterator(query);
|
|
return await ResultsFromFeedIterator(query);
|
|
}
|
|
}
|
|
|
|
+ public static async Task<List<int>> FindCountByDict<T>(this AzureCosmosFactory azureCosmosFactory,JsonElement json)
|
|
|
|
+ {
|
|
|
|
+ Type type = typeof(T);
|
|
|
|
+ AzureCosmosModel container = azureCosmosFactory.GetCosmosModel(type.Name);
|
|
|
|
+ string pk = type.Name;
|
|
|
|
+ StringBuilder sql = new StringBuilder("select value count(c) from c");
|
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(json, sql, pk);
|
|
|
|
+ if (cosmosDbQuery == null)
|
|
|
|
+ {
|
|
|
|
+ return new List<int> { 0 };
|
|
|
|
+ }
|
|
|
|
+ QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
|
|
|
|
+ AsyncPageable<int> query = container.container.GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
|
|
|
|
+ return await ResultsFromFeedIterator(query);
|
|
|
|
+ }
|
|
public static async Task<List<dynamic>> FindCountByDict(this AzureCosmosFactory azureCosmosFactory, string CollectionName, Dictionary<string, object> dict)
|
|
public static async Task<List<dynamic>> FindCountByDict(this AzureCosmosFactory azureCosmosFactory, string CollectionName, Dictionary<string, object> dict)
|
|
{
|
|
{
|
|
if (azureCosmosFactory.CosmosDict.typeCosmos.TryGetValue(CollectionName, out AzureCosmosModel container))
|
|
if (azureCosmosFactory.CosmosDict.typeCosmos.TryGetValue(CollectionName, out AzureCosmosModel container))
|
|
@@ -286,6 +301,37 @@ namespace TEAMModelOS.SDK.DI
|
|
throw new BizException("CollectionName named:" + CollectionName + " dose not exsit in Database!");
|
|
throw new BizException("CollectionName named:" + CollectionName + " dose not exsit in Database!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public static async Task<List<dynamic>> FindCountByDict(this AzureCosmosFactory azureCosmosFactory, string CollectionName,JsonElement json)
|
|
|
|
+ {
|
|
|
|
+ if (azureCosmosFactory.CosmosDict.typeCosmos.TryGetValue(CollectionName, out AzureCosmosModel container))
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
|
+ var emobj = json.EnumerateObject();
|
|
|
|
+ while (emobj.MoveNext())
|
|
|
|
+ {
|
|
|
|
+ if (emobj.Current.Name != "@CURRPAGE"||
|
|
|
|
+ emobj.Current.Name != "@PAGESIZE" ||
|
|
|
|
+ emobj.Current.Name != "@ASC" ||
|
|
|
|
+ emobj.Current.Name != "@DESC") {
|
|
|
|
+ dict[emobj.Current.Name] = emobj.Current.Value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ string pk = container.type.Name;
|
|
|
|
+ StringBuilder sql = new StringBuilder("select value count(c) from c");
|
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql, pk);
|
|
|
|
+ if (cosmosDbQuery == null)
|
|
|
|
+ {
|
|
|
|
+ return new List<dynamic> { 0 };
|
|
|
|
+ }
|
|
|
|
+ QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
|
|
|
|
+ AsyncPageable<dynamic> query = container.container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
|
|
|
|
+ return await ResultsFromFeedIterator(query);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ throw new BizException("CollectionName named:" + CollectionName + " dose not exsit in Database!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
public static async Task<T> Update<T>(this AzureCosmosFactory azureCosmosFactory, T entity) where T : ID
|
|
public static async Task<T> Update<T>(this AzureCosmosFactory azureCosmosFactory, T entity) where T : ID
|
|
{
|
|
{
|
|
Type type = typeof(T);
|
|
Type type = typeof(T);
|
|
@@ -385,6 +431,33 @@ namespace TEAMModelOS.SDK.DI
|
|
QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
|
|
QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
|
|
return await ResultsFromQueryAndOptions<T>(azureCosmosFactory,cosmosDbQuery, queryRequestOptions);
|
|
return await ResultsFromQueryAndOptions<T>(azureCosmosFactory,cosmosDbQuery, queryRequestOptions);
|
|
}
|
|
}
|
|
|
|
+ public static async Task<List<T>> FindByDict<T>(this AzureCosmosFactory azureCosmosFactory, JsonElement jsonElement, List<string> propertys = null) where T : ID
|
|
|
|
+ {
|
|
|
|
+ StringBuilder sql;
|
|
|
|
+ sql = SQLHelper.GetSQLSelect(propertys);
|
|
|
|
+ string pk = typeof(T).Name;
|
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(jsonElement, sql, pk);
|
|
|
|
+ QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
|
|
|
|
+ return await ResultsFromQueryAndOptions<T>(azureCosmosFactory, cosmosDbQuery, queryRequestOptions);
|
|
|
|
+ }
|
|
|
|
+ public static async Task<List<dynamic>> FindByDict(this AzureCosmosFactory azureCosmosFactory, string CollectionName, JsonElement json, List<string> propertys = null)
|
|
|
|
+ {
|
|
|
|
+ if (azureCosmosFactory.CosmosDict.typeCosmos.TryGetValue(CollectionName, out AzureCosmosModel container))
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ string pk = container.type.Name;
|
|
|
|
+ StringBuilder sql;
|
|
|
|
+ sql = SQLHelper.GetSQLSelect(propertys);
|
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(json, sql, pk);
|
|
|
|
+ QueryRequestOptions queryRequestOptions = GetDefaultQueryRequestOptions(itemsPerPage: GetEffectivePageSize(-1, null));
|
|
|
|
+ AsyncPageable<dynamic> query = container.container.GetItemQueryIterator<dynamic>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: queryRequestOptions);
|
|
|
|
+ return await ResultsFromFeedIterator(query);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ throw new BizException("CollectionName named:" + CollectionName + " dose not exsit in Database!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
public static async Task<List<dynamic>> FindByDict(this AzureCosmosFactory azureCosmosFactory, string CollectionName, Dictionary<string, object> dict, List<string> propertys = null)
|
|
public static async Task<List<dynamic>> FindByDict(this AzureCosmosFactory azureCosmosFactory, string CollectionName, Dictionary<string, object> dict, List<string> propertys = null)
|
|
{
|
|
{
|
|
if (azureCosmosFactory.CosmosDict.typeCosmos.TryGetValue(CollectionName, out AzureCosmosModel container))
|
|
if (azureCosmosFactory.CosmosDict.typeCosmos.TryGetValue(CollectionName, out AzureCosmosModel container))
|
|
@@ -462,6 +535,11 @@ namespace TEAMModelOS.SDK.DI
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ public static async Task<List<IdPk>> DeleteAll<T>(this AzureCosmosFactory azureCosmosFactory, JsonElement dict) where T : ID
|
|
|
|
+ {
|
|
|
|
+ List<T> list = await azureCosmosFactory.FindByDict<T>(dict);
|
|
|
|
+ return await azureCosmosFactory.DeleteAll(list);
|
|
|
|
+ }
|
|
public static async Task<List<IdPk>> DeleteAll<T>(this AzureCosmosFactory azureCosmosFactory, List<T> enyites) where T : ID
|
|
public static async Task<List<IdPk>> DeleteAll<T>(this AzureCosmosFactory azureCosmosFactory, List<T> enyites) where T : ID
|
|
{
|
|
{
|
|
Type type = typeof(T);
|
|
Type type = typeof(T);
|