GithubHelp home page GithubHelp logo

fastapi-crud-async's Introduction

fastapi-crud-async's People

Contributors

amirtds avatar mjhea0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastapi-crud-async's Issues

No relation in psql?

Hi,

After cloning the repository and building all the dockers I have encountered this problem. It seems that no relation is created in pqsql and therefore the table notes it is not there. Then the code is not able to find the table notes and it crashes.

docker-compose exec db psql --username=hello_fastapi --dbname=hello_fastapi_dev

psql (12.1)
Type "help" for help.

hello_fastapi_dev=# \c hello_fastapi_dev
You are now connected to database "hello_fastapi_dev" as user "hello_fastapi".
hello_fastapi_dev=# \dt
Did not find any relations.
hello_fastapi_dev=# \d
Did not find any relations.
hello_fastapi_dev=#

What should I do? Thanks :D

Error running on mac

I have pulled the source code and i am having this issue i am not able to get around. Its an error from the db container, and it has not successfully created the table due to this error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

Error during testing

Everything is working awesome, but when i am executing the test comand it throws errors,
you set test_app as a parameter in all the functions issue is from test_app only.
This is the error message.
file /usr/src/app/test/test_notes.py, line 8
def test_create_note(test_app, monkeypatch):
E fixture 'test_app' not found

  available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
  use 'pytest --fixtures [testpath]' for help on them.

Kindly help me in this.

Issue renaming test_main.py to test_ping.py

Thanks for the great tutorial! Whilst working through it I came upon an issue when renaming test_main.py file to test_ping.py - after renaming running the tests fails with the error: E AssertionError: PosixPath('/usr/src/app/tests/test_ping.py') is not a file (isdir=False, exists=True, islink=False)

I found it was necessary to delete the container and then rebuild without cache using docker compose build --no-cache in order for the tests to be discoverable and run correctly after changing the name of the original test file. Not sure if this issue is worth updating the tutorial to reflect in case others run into the same error.

fastapi cannot connect to postgresql

So even with creating it in this way or cloning whole app an running docker-compose i receive this error.
When i restart app again same error.
Runing it with the loop gives me "waiting for db"


`return self.dbapi.connect(*cargs, **cparams)
File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Host is unreachable
Is the server running on host "db" (172.24.0.2) and accepting
TCP/IP connections on port 5432?`

`docker-compose:

services:
  web:
    build: ./src
    command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8000
    volumes:
      - ./src/:/usr/src/app/
    ports:
      - 8002:8000
    environment:
      - DATABASE_URL=postgresql://test:test@db/test
  db:
    image: postgres:12.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
      - POSTGRES_USER=test
      - POSTGRES_PASSWORD=test
      - POSTGRES_DB=test

volumes:
  postgres_data:

network:

ef16fd637e2d fastapi_default bridge local

network inspect:

[
    {
        "Name": "fastapi_default",
        "Id": "ef16fd637e2d42e97630ee4caf9fd32f2752e255978b85ac69aa31a2e5c6ac29",
        "Created": "2020-11-03T18:37:58.24200589Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.26.0.0/16",
                    "Gateway": "172.26.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "3296e1012abc89b7b56c560aaaf102b53f9a6549e61835437d7d5484409e7bb6": {
                "Name": "fastapi_web_1",
                "EndpointID": "ab702323d9c1f0c0c452fce36a20f459e333568c5f96d370d3944fd9eeccc4f0",
                "MacAddress": "02:42:ac:1a:00:03",
                "IPv4Address": "172.26.0.3/16",
                "IPv6Address": ""
            },
            "c82ac1745965997a3f21875fe11221c8e9d4adb2f48a75e443692433abb44094": {
                "Name": "fastapi_db_1",
                "EndpointID": "a125d228f2bd997285fbb016d68d9735a57ea6bc0f940b61d9d214984d819589",
                "MacAddress": "02:42:ac:1a:00:02",
                "IPv4Address": "172.26.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "fastapi",
            "com.docker.compose.version": "1.27.4"
        }
    }
]

docker ps
`

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
3296e1012abc        fastapi_web         "uvicorn app.main:ap…"   About a minute ago   Up About a minute   0.0.0.0:8002->8000/tcp   fastapi_web_1
c82ac1745965        postgres:12.1-alpine        "docker-entrypoint.s…"   About a minute ago   Up About a minute   5432/tcp                 fastapi_db_1

db.py

import os
from sqlalchemy import (Column, DateTime, Integer, MetaData, String, Table, create_engine, exc)
from sqlalchemy.sql import func
from databases import Database
import time

DATABASE_URL = os.getenv("DATABASE_URL")

while 1:
    try:
        engine = create_engine(DATABASE_URL, pool_pre_ping=True)
        engine.execute('select 1')
    except exc.OperationalError:
        print('Waiting for database...')
        time.sleep(1)
    else:
        break

print('Connected!')

metadata = MetaData()
notes = Table(
    "notes",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("title", String(50)),
    Column("description", String(50)),
    Column("created_date", DateTime, default=func.now(), nullable=False),
)

metadata.create_all(engine)
# databases query builder
database = Database(DATABASE_URL)

`

Relationships between tables

Can you please add an example of the tables with relationships (eg: Users that own Notes) in the article or at least give me a clue about it?
The way that FastApi's documentation introduces relationships is different than this tutorial and I like your approach, but couldn't implement two tables with a relationship.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.