public static string CreateGetAllIndexesStatement(GetAllQueryIndexOptions options)
        {
            var bucketCondition = "(bucket_id = $bucketName)";
            var scopeCondition = "(" + bucketCondition + " AND scope_id = $scopeName)";
            var collectionCondition = "(" + scopeCondition + " AND keyspace_id = $collectionName)";

            string whereCondition;
            if (options.CollectionNameValue != null)
                whereCondition = collectionCondition;
            else if(options.ScopeNameValue != null)
                whereCondition = scopeCondition;
            else
                whereCondition = bucketCondition;

            if(Default.Equals(options.CollectionNameValue) ||
                string.IsNullOrWhiteSpace(options.CollectionNameValue))
            {
                var defaultCollectionCondition = "(bucket_id IS MISSING AND keyspace_id = $bucketName)";
                whereCondition = "(" + whereCondition + " OR " + defaultCollectionCondition + ")";
            }

            return "SELECT idx.* FROM system:indexes AS idx" +
                    " WHERE " + whereCondition +
                    " AND `using` = \"gsi\"" +
                    " ORDER BY is_primary DESC, name ASC";
        }
        public static Task <IEnumerable <QueryIndex> > GetAllIndexesAsync(this IQueryIndexManager queryIndexManager, string bucketName, Action <GetAllQueryIndexOptions> configureOptions)
        {
            var options = new GetAllQueryIndexOptions();

            configureOptions(options);

            return(queryIndexManager.GetAllIndexesAsync(bucketName, options));
        }
        public async Task <IEnumerable <QueryIndex> > GetAllIndexesAsync(string bucketName, GetAllQueryIndexOptions options = null)
        {
            options = options ?? GetAllQueryIndexOptions.Default;
            Logger.LogInformation($"Attempting to get query indexes for bucket {bucketName}");

            try
            {
                var statement = $"SELECT i.* FROM system:indexes AS i WHERE i.keyspace_id=\"{bucketName}\" AND `using`=\"gsi\";";
                var result    = await _queryClient.QueryAsync <QueryIndex>(statement,
                                                                           queryOptions => queryOptions.WithCancellationToken(options.CancellationToken)
                                                                           );

                var indexes = new List <QueryIndex>();
                foreach (var row in result)
                {
                    indexes.Add(row);
                }

                return(indexes);
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Error trying to get query indexes for bucket {bucketName}");
                throw;
            }
        }