Skip to content

Fix error when create database and query #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,4 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/
.vscode
22 changes: 14 additions & 8 deletions src/CouchDB.Driver/CouchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CouchClient(string connectionString, Action<CouchSettings> couchSettingsF
#region CRUD

/// <summary>
/// Returns an instance of the CouchDB database with the given name.
/// Returns an instance of the CouchDB database with the given name.
/// If EnsureDatabaseExists is configured, it creates the database if it doesn't exists.
/// </summary>
/// <typeparam name="TSource">The type of database documents.</typeparam>
Expand Down Expand Up @@ -107,7 +107,12 @@ public async Task<CouchDatabase<TSource>> CreateDatabaseAsync<TSource>(string da
throw new ArgumentNullException(nameof(database));
}

if (!_systemDatabases.Contains(database) && !new Regex(@"^[a-z][a-z0-9_$()+/-]*$").IsMatch(database))
//if (!_systemDatabases.Contains(database) && !new Regex(@"^[a-z][a-z0-9_$()+/-]*$").IsMatch(database))
//{
// throw new ArgumentException($"Name {database} contains invalid characters. Please visit: https://docs.couchdb.org/en/stable/api/database/common.html#put--db", nameof(database));
//}

if (_systemDatabases.Contains(database))
{
throw new ArgumentException($"Name {database} contains invalid characters. Please visit: https://docs.couchdb.org/en/stable/api/database/common.html#put--db", nameof(database));
}
Expand Down Expand Up @@ -158,7 +163,8 @@ public async Task DeleteDatabaseAsync<TSource>(string database) where TSource :
.SendRequestAsync()
.ConfigureAwait(false);

if (!result.Ok) {
if (!result.Ok)
{
throw new CouchException("Something went wrong during the delete.", "S");
}
}
Expand All @@ -168,7 +174,7 @@ public async Task DeleteDatabaseAsync<TSource>(string database) where TSource :
#region CRUD reflection

/// <summary>
/// Returns an instance of the CouchDB database of the given type.
/// Returns an instance of the CouchDB database of the given type.
/// If EnsureDatabaseExists is configured, it creates the database if it doesn't exists.
/// </summary>
/// <typeparam name="TSource">The type of database documents.</typeparam>
Expand All @@ -179,7 +185,7 @@ public CouchDatabase<TSource> GetDatabase<TSource>() where TSource : CouchDocume
}

/// <summary>
/// Creates a new database of the given type in the server.
/// Creates a new database of the given type in the server.
/// The name must begin with a lowercase letter and can contains only lowercase characters, digits or _, $, (, ), +, - and /.s
/// </summary>
/// <typeparam name="TSource">The type of database documents.</typeparam>
Expand Down Expand Up @@ -235,7 +241,7 @@ public CouchDatabase<TUser> GetUsersDatabase<TUser>() where TUser : CouchUser
#region Utils

/// <summary>
/// Determines whether the server is up, running, and ready to respond to requests.
/// Determines whether the server is up, running, and ready to respond to requests.
/// </summary>
/// <returns>true is the server is not in maintenance_mode; otherwise, false.</returns>
public async Task<bool> IsUpAsync()
Expand All @@ -249,7 +255,7 @@ public async Task<bool> IsUpAsync()
.ConfigureAwait(false);
return result.Status == "ok";
}
catch(CouchNotFoundException)
catch (CouchNotFoundException)
{
return false;
}
Expand Down Expand Up @@ -305,7 +311,7 @@ protected virtual void Dispose(bool disposing)
{
if (_settings.AuthenticationType == AuthenticationType.Cookie && _settings.LogOutOnDispose)
{
AsyncContext.Run(() => LogoutAsync().ConfigureAwait(false));
_ = AsyncContext.Run(() => LogoutAsync().ConfigureAwait(false));
}
_flurlClient.Dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion src/CouchDB.Driver/CouchDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private async Task<List<TSource>> SendQueryAsync(Func<IFlurlRequest, Task<HttpRe

return findResult.Docs.ToList();
}

/// Finds all documents with given IDs.
/// </summary>
/// <param name="docIds">The collection of documents IDs.</param>
Expand Down
4 changes: 2 additions & 2 deletions src/CouchDB.Driver/CouchQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public object GetCouchList<T>(string body)
{
FindResult<T> result = _flurlClient
.Request(_connectionString)
.AppendPathSegments(_db, "_find")
.AppendPathSegments(Uri.EscapeDataString(_db), "_find")
.WithHeader("Content-Type", "application/json")
.PostStringAsync(body).ReceiveJson<FindResult<T>>()
.SendRequest();
Expand Down Expand Up @@ -142,7 +142,7 @@ private object InvokeUnsupportedMethodCallExpression(object result, MethodCallEx
MethodInfo queryableMethodInfo = methodCallExpression.Method;
Expression[] queryableMethodArguments = methodCallExpression.Arguments.ToArray();

// Since Max and Min are not map 1 to 1 from Queryable to Enumerable
// Since Max and Min are not map 1 to 1 from Queryable to Enumerable
// they need to be handled differently
MethodInfo FindEnumerableMethod()
{
Expand Down
4 changes: 2 additions & 2 deletions src/CouchDB.Driver/QueryTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma warning disable IDE0058 // Expression value is never used
namespace CouchDB.Driver
{
{
internal partial class QueryTranslator : ExpressionVisitor
{
private readonly CouchSettings _settings;
Expand All @@ -22,7 +22,7 @@ internal string Translate(Expression expression)
_sb = new StringBuilder();
_sb.Append("{");
Visit(expression);

// If no Where() calls
if (!_isSelectorSet)
{
Expand Down