public static Task CreateIndexAsync(this IQueryIndexManager queryIndexManager, string bucketName, string indexName, IEnumerable <string> fields, Action <CreateQueryIndexOptions> configureOptions) { var options = new CreateQueryIndexOptions(); configureOptions(options); return(queryIndexManager.CreateIndexAsync(bucketName, indexName, fields, options)); }
public static string CreateIndexStatement(string bucketName, string indexName, IEnumerable<string> fields, CreateQueryIndexOptions options) { if(options.ScopeNameValue == null) { return $"CREATE INDEX {indexName.EscapeIfRequired()} ON {bucketName.EscapeIfRequired()}({string.Join(",", fields)}) USING GSI WITH {{\"defer_build\":{options.DeferredValue}}};"; } return $"CREATE INDEX {indexName.EscapeIfRequired()} ON {bucketName.EscapeIfRequired()}.{options.ScopeNameValue.EscapeIfRequired()}.{options.CollectionNameValue.EscapeIfRequired()}({string.Join(",", fields)}) USING GSI WITH {{\"defer_build\":{options.DeferredValue}}};"; }
public async Task CreateIndexAsync(string bucketName, string indexName, IEnumerable <string> fields, CreateQueryIndexOptions options = null) { options = options ?? CreateQueryIndexOptions.Default; Logger.LogInformation($"Attempting to create query index {indexName} on bucket {bucketName}"); try { var statement = $"CREATE INDEX {indexName} ON {bucketName}({string.Join(",", fields)}) USING GSI WITH {{\"defer_build\":{options.Deferred}}};"; await _queryClient.QueryAsync <dynamic>(statement, queryOptions => queryOptions.WithCancellationToken(options.CancellationToken) ); } catch (Exception exception) { Logger.LogError(exception, $"Error trying to create query index {indexName} on {bucketName}"); throw; } }