postgraas是一个超级简单的postgresql-as-a-service
postgraas-server的Python项目详细描述
postgraas是一个超级简单的postgresql-as-a-service
什么是Postgraas?
postgraas通过一个简单的rest api为完整的postgresql数据库实例提供CRUD操作。 数据库实例是docker容器,api服务器是几百loc flask应用程序。 它并不是一个面向生产的解决方案,而是一个概念证明,可以让您自己轻松地传播创建“即服务”服务的理念,并应该激励您现在就开始使用自己的云基础设施。 但事实上,它很好地证明了这一概念,而且如果您需要一个快速的postgresql实例(例如集成测试、玩花哨的showhn项目或其他实验),那么它对于交付postgresql实例是非常有用的。 当然,通过rest api进行crud管理也是为现代软件项目构建自动化连续交付管道的必要前提。
安装
您可以在docs中找到详细说明
通过PIP安装:
pip install postgraas_server
启动wsgi api服务器,例如通过gunicorn:
pip install gunicorn gunicorn -w 4 -b 0.0.0.0:8080 postgraas_server.postgraas_api:app
用法
我们需要将创建所需的所有参数作为http请求发送。 创建一个文件,例如my_postgraas.json:
{ "postgraas_instance_name": "my_postgraas", "db_name": "my_db", "db_username": "db_user", "db_pwd": "secret" }
使用curl向collection资源发出post请求:
curl -H "Content-Type: application/json" -X POST --data @my_postgraas.json http://localhost:8080/api/v2/postgraas_instances
现在您的实例已创建,作为响应,您将获得实例的详细信息:
{ "postgraas_instance_id": 1, "container_id": "193f0d94d49fa26626fdbdb583e9453f923468b01eac59207b4852831a105c03", "db_pwd": "secret", "host": "not imlemented yet", "db_name": "my_db", "db_username": "db_user", "port": 54648 }
我们现在可以连接到数据库,例如通过psql:
psql -h localhost -p 54648 -U db_user my_db
太棒了,不是吗?