Repository: encode/databases

Issue:
Bug: sqlite url replace does not work
Testcase:

```python
def test_replace_database_url_components_sqlite():
    u = DatabaseURL("sqlite:///mydatabase.db")

    assert u.database == "mydatabase.db"
    new = u.replace(database="test_" + u.database)
    assert new.database == "test_mydatabase.db"
    assert str(new) == "sqlite:///test_mydatabase.db"
```

Pytest traceback:

```
E       AssertionError: assert 'sqlite:/test_mydatabase.db' == 'sqlite:///test_mydatabase.db'
E         - sqlite:/test_mydatabase.db
E         + sqlite:///test_mydatabase.db
E         ?        ++
```
If I find a solution I'll make a PR. But so far I couldn't make it work

Discussion:

Patch:
diff --git a/databases/core.py b/databases/core.py
index c9e074f..62a2487 100644
--- a/databases/core.py
+++ b/databases/core.py
@@ -246,6 +246,11 @@ class Transaction:
             await self._connection.__aexit__()
 
 
+class _EmptyNetloc(str):
+    def __bool__(self) -> bool:
+        return True
+
+
 class DatabaseURL:
     def __init__(self, url: typing.Union[str, "DatabaseURL"]):
         self._url = str(url)
@@ -282,6 +287,10 @@ class DatabaseURL:
     def port(self) -> typing.Optional[int]:
         return self.components.port
 
+    @property
+    def netloc(self) -> typing.Optional[str]:
+        return self.components.netloc
+
     @property
     def database(self) -> str:
         return self.components.path.lstrip("/")
@@ -317,6 +326,11 @@ class DatabaseURL:
             driver = kwargs.pop("driver", self.driver)
             kwargs["scheme"] = f"{dialect}+{driver}" if driver else dialect
 
+        if not kwargs.get("netloc", self.netloc):
+            # Using an empty string that evaluates as True means we end
+            # up with URLs like `sqlite:///database` instead of `sqlite:/database`
+            kwargs["netloc"] = _EmptyNetloc()
+
         components = self.components._replace(**kwargs)
         return self.__class__(components.geturl())
 


Test patch:
diff --git a/tests/test_database_url.py b/tests/test_database_url.py
index 49ad281..d587df9 100644
--- a/tests/test_database_url.py
+++ b/tests/test_database_url.py
@@ -40,3 +40,9 @@ def test_replace_database_url_components():
     new = u.replace(port=123)
     assert new.port == 123
     assert str(new) == "postgresql://localhost:123/mydatabase"
+
+    u = DatabaseURL("sqlite:///mydatabase")
+    assert u.database == "mydatabase"
+    new = u.replace(database="test_" + u.database)
+    assert new.database == "test_mydatabase"
+    assert str(new) == "sqlite:///test_mydatabase"