Esempio n. 1
0
        /// <inheritdoc />
        public async Task <ICouchDatabase <TSource> > GetOrCreateDatabaseAsync <TSource>(string database,
                                                                                         int?shards = null, int?replicas = null, string?discriminator = null, CancellationToken cancellationToken = default)
            where TSource : CouchDocument
        {
            QueryContext   queryContext = NewQueryContext(database);
            IFlurlResponse response     = await CreateDatabaseAsync(queryContext, shards, replicas, cancellationToken)
                                          .ConfigureAwait(false);

            if (response.IsSuccessful() || response.StatusCode == (int)HttpStatusCode.PreconditionFailed)
            {
                return(new CouchDatabase <TSource>(_flurlClient, _options, queryContext, discriminator));
            }

            throw new CouchException($"Something wrong happened while creating database {database}.");
        }