metricq / aiocouch

🛋 An asynchronous client library for CouchDB 2.x and 3.x
https://aiocouch.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
29 stars 10 forks source link

Implement CouchDB.info() #9

Closed adrienverge closed 4 years ago

adrienverge commented 4 years ago

Add function to get CouchDB server information (i.e. GET /). This allows, for example, getting the server version with:

couchdb = CouchDB(url)
info = await couchdb.info()
print(info['version'])
adrienverge commented 4 years ago

I updated the pull request thanks to your suggestion. Here is the diff since last time:

--- a/aiocouch/couchdb.py
+++ b/aiocouch/couchdb.py
@@ -41,4 +41,4 @@ class CouchDB(object):
         return await self._server._all_dbs(**params)

     async def info(self):
-        return await self._server._get('/')
+        return await self._server._info()
--- a/aiocouch/remote.py
+++ b/aiocouch/remote.py
@@ -103,6 +103,10 @@ class RemoteServer(object):
         await self._http_session.close()
         await asyncio.sleep(0.250 if has_ssl_conn else 0)

+    @raises(401, "Invalid credentials")
+    async def _info(self):
+        return await self._get("/")
+
     @raises(401, "Authentification failed, check provided credentials.")
     async def _check_session(self):
         await self._get("/_session")