Skip to content

Commit

Permalink
Update README.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
Relrin committed Oct 1, 2018
1 parent 1e1c6b3 commit 745147f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This package should be installed using pip: ::
Example
=======
.. code-block:: python
#!/usr/bin/env python3
from sanic import Sanic, response
from sanic_mongodb_ext import MongoDbExtension
Expand All @@ -26,27 +27,30 @@ Example
app = Sanic(__name__)
# Configuration for MongoDB and uMongo
app.config.update({
"MONGODB_DATABASE": "app", # Make ensure that the `app` is really exists
"MONGODB_URI": "mongodb://user:password@mongodb:27017",
"MONGODB_DATABASE": "app", # Make ensure that the `app` database is really exists
"MONGODB_URI": "mongodb://root:root@mongodb:27017",
"LAZY_UMONGO": MotorAsyncIOInstance(),
})
# uMongo client is available as `app.mongodb` or `app.extensions['mongodb']`.
# The lazy client will be available as `app.lazy_mongodb` only when the database was specified,
# and which is a great choice for the structured projects.
MongoDbExtension(app)
# Describe the model
@app.lazy_umongo.register
class Artist(Document):
name = StringField(required=True, allow_none=False)
# And use it later for APIs
@app.route("/")
async def handle(request):
artist = Artist(name="A new rockstar!")
await artist.commit()
return response.json(artist.dump())
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
Expand Down

0 comments on commit 745147f

Please sign in to comment.