Home  >  Q&A  >  body text

peewee - Python's ORM queries the database. If no results are found, an error will be reported?

I am using peewee, and I found that when querying a piece of data, I use the get method. If there is no matching data in the database, a DoesNotExist error will be thrown directly. I really can't stand this kind of framework that throws errors at every turn. Because I wrote a global error capture, I always automatically enter the global error capture method. You have to be forced to manually write try to nest. Sometimes there are too many queries and you have to nest several levels of try.

I just want to ask, is there any ORM framework like Java or C# that returns null if the query cannot find the result? Is it possible to encapsulate it yourself?

迷茫迷茫2711 days ago1069

reply all(2)I'll reply

  • 迷茫

    迷茫2017-05-18 10:59:01

    SQLAlchemy

    reply
    0
  • PHPz

    PHPz2017-05-18 10:59:01

    # SQLAlchemy
    city = sesion.query(User.city).filter(User.name=="Hello").one()

    If city is null, and this query returns None (null) instead of throwing an exception, does this record exist or not?

    reply
    0
  • Cancelreply