diff --git a/docs/.vuepress/sidebar.ts b/docs/.vuepress/sidebar.ts index 7a03377d..5684490f 100644 --- a/docs/.vuepress/sidebar.ts +++ b/docs/.vuepress/sidebar.ts @@ -65,6 +65,7 @@ export default sidebar({ "litestar", "blacksheep", "robyn", + "panther", ] }, ], diff --git a/docs/usage/frameworks/panther.md b/docs/usage/frameworks/panther.md new file mode 100644 index 00000000..35d25ced --- /dev/null +++ b/docs/usage/frameworks/panther.md @@ -0,0 +1,48 @@ +--- +title: Panther +--- + +There is the default example for `Panther` framework. + +We strongly recommend to use the following example as a standard way to use `PSQLPy` with `Panther` framework. + +## Complete example + +```python +import uvicorn +from psqlpy import ConnectionPool + +from panther import Panther +from panther.app import API +from panther.configs import config +from panther.events import Event +from panther.response import Response + + +@Event.startup +async def create_connection_pool(): + config.connection_pool = ConnectionPool( + dsn="postgres://postgres:postgres@localhost:5432/postgres", + max_db_pool_size=10, + ) + + +@Event.shutdown +async def close_connection_pool(): + config.connection_pool.close() + + +@API() +async def pg_pool_example(): + connection = await config.connection_pool.connection() + query_result = await connection.execute( + "SELECT * FROM users", + ) + return Response(data=query_result.result()) + + +app = Panther(__name__, configs=__name__, urls={'/': pg_pool_example}) + +if __name__ == "__main__": + uvicorn.run(app) +``` \ No newline at end of file