sqlalchemy 判断表是否存在,执行sqlalchemy存在查询

I'm having trouble understanding how to execute a query to check and see if a matching record already exists in sqlalchemy. Most of the examples I can find online seem to reference "session" and "query" objects that I don't have.

Here's a short complete program that illustrates my problem:

1. sets up in-memory sqlite db with "person" table.

2. inserts two records into the person table.

3. check if a particular record exists in the table. This is where it barfs.

from sqlalchemy import create_engine, Table, Column, Integer, String, MetaData

from sqlalchemy.sql.expression import exists

engine = create_engine('sqlite:///:memory:', echo=False)

metadata = MetaData()

person = Table('person', metadata,

Column('id', Integer, primary_key=True),

你可能感兴趣的:(sqlalchemy,判断表是否存在)