When to use SQLAlchemy .get() vs .filter(Foo.ID == primary_key_id).first()

后端 未结 3 1112
眼角桃花
眼角桃花 2020-12-10 13:43

Just curious about when I would want to use one vs the other. How are they different?

We have our system set up such that we can do this:

my_user = U         


        
3条回答
  •  执笔经年
    2020-12-10 14:45

    The first (.filter()) is more general: you can construct any conditional for any set of columns. The latter is a shortcut for the common case of a lookup by primary key.

    (note: this is a first impression; I haven't used SQLAlchemy, though I do have many years of programming experience)

提交回复
热议问题