Table¶
- class
sqlalchemy.schema.
Table
¶ meta = MetaData() table = Table( 'user', meta, Column('id', Integer, primary_key=True), Column('profile_id', Integer), Column('version_id', Integer), ForeignKey('profile.id'), ForeignKeyConstraint( ['profile_id', 'version_id'], ['profile.profile_id', 'profile.version_id'] ), # FOREIGN KEY(story_id, version_id) REFERENCES story (story_id, version_id) ) # автозагрузка таблицы из базы table = Table('user', meta, autoload=True, autoload_with=engine)
-
columns
¶ Коллекция столбцов
sqlalchemy.schema.Column()
table.c # <...ImmutableColumnCollection...> table.columns # <...ImmutableColumnCollection...> str(table.columns) # ['user.id', 'user.name']
-
name
¶ Название таблицы
table.name # 'user'
-
primary_key
¶ Первичные ключи таблицы
table.primary_key # PrimaryKeyConstraint(Column('id')) str(table.primary_key.columns) # ['user.id'] table.primary_key.columns.id # Column('id', Integer())
-
create
()¶ table.create() # create table "user" ()
-
delete
()¶ table.delete() # delete from "user"
-
drop
()¶ table.drop(engine) # drop table "user"
-
join
()¶ user_table.join( address_table, user_table.c.id == address_table.c.user_id ) # "user" join address on "user".id = address.user_id
-
insert
()¶ table.insert() # insert into "user" (id, name) values (:id, :name) insert_stmt = table.insert().values(username='ilnurgi') conn.execute(insert_stmt)
-
outerjoin
()¶
-
select
()¶ table.select() # select * from "user"
-
update
()¶ table.update() # update "user" set id=:id, name=:name
-