Closed begyy closed 4 years ago
Thanks for trying this extension in such an early stage! We @YUMEYA are still working on this, please kindly wait for the initial release, or use GINO 0.8 for now.
Okey)
@begyy Oh sorry I didn't notice the issue is for GINO 0.8.5. I'll leave that to @YUMEYA to solve.
Hello @begyy , I can't reproduce in the same conditions. Please double check your postgresql settings, especially the privileges of your user on the database.
Hello @YUMEYA I checked the database. on this exemplar https://github.com/python-gino/gino-starlette/blob/master/example/app.py works does not work on mine:)) Can you show me another example? with a router
@YUMEYA can you check my code? https://github.com/begyy/gino_and_starlette_hello_world ?)
@begyy OK, I'll look into it.
@begyy I changed your code as following and worked:
import os
import uvicorn
from gino.ext.starlette import Gino
from starlette.applications import Starlette
DB_ARGS = dict(
host=os.getenv("DB_HOST", "localhost"),
port=os.getenv("DB_PORT", 5432),
user=os.getenv("DB_USER", "postgres"),
password=os.getenv("DB_PASS", ""),
database=os.getenv("DB_NAME", "gino"),
)
PG_URL = "postgresql://{user}:{password}@{host}:{port}/{database}".format(**DB_ARGS)
# Initialize Starlette app
# Don't pass `route` param here, register route with `app.route()` decorator later in `view.py`.
app = Starlette()
# Initialize Gino object
db = Gino(dsn=PG_URL)
db.init_app(app)
# Import your route functions to make them effective.
# To prevent cyclic importing (`view.py` and `user.py`
# will import `app` and `db` instances above),
# don't put it at the top of this file.
from view import *
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=5000)
from starlette.responses import JSONResponse
from user import User
# Import starlette app instance from `main.py`.
from main import app
# Register your route.
@app.route("/")
async def homepage(request):
results = []
users = await User.query.gino.all()
for user in users:
results.append({"id": user.id, "name": user.username})
return JSONResponse(results)
# Import gino instance from main.py
from main import db
class User(db.Model):
__tablename__ = "gino_users"
id = db.Column(db.BigInteger(), primary_key=True)
username = db.Column(db.String(50), default="unnamed")
password = db.Column(db.String(250))
Here's my screenshot:
@YUMEYA thanks a lot
@begyy You are welcome! Feel free to ask any questions or suggest any ideas on our project! 😊
@YUMEYA okey 😄
Steps to Reproduce the Problem
Specifications