-
-
Save ThiefMaster/00f812a5be0ce321c91241de297dbdd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import * | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import * | |
Base = declarative_base() | |
class Foo(Base): | |
__tablename__ = 'foo' | |
id = Column(Integer, primary_key=True) | |
class Bar(Base): | |
__tablename__ = 'bar' | |
id = Column(Integer, primary_key=True) | |
foo_id = Column(Integer, ForeignKey('foo.id')) | |
foo = relationship(Foo, lazy=False, backref=backref('bars', lazy=False)) | |
e = create_engine('sqlite:///', echo=True) | |
Base.metadata.create_all(e) | |
s = Session(e) | |
s.add(Foo()) | |
s.commit() | |
print 'default' | |
print s.query(s.query(Foo).exists()).scalar() | |
print 'without eagerloads' | |
print s.query(s.query(Foo).enable_eagerloads(False).exists()).scalar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2016-12-01 15:36:46,224 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 | |
2016-12-01 15:36:46,224 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,224 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 | |
2016-12-01 15:36:46,225 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,225 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("foo") | |
2016-12-01 15:36:46,225 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,225 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("bar") | |
2016-12-01 15:36:46,225 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,226 INFO sqlalchemy.engine.base.Engine | |
CREATE TABLE foo ( | |
id INTEGER NOT NULL, | |
PRIMARY KEY (id) | |
) | |
2016-12-01 15:36:46,226 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,226 INFO sqlalchemy.engine.base.Engine COMMIT | |
2016-12-01 15:36:46,227 INFO sqlalchemy.engine.base.Engine | |
CREATE TABLE bar ( | |
id INTEGER NOT NULL, | |
foo_id INTEGER, | |
PRIMARY KEY (id), | |
FOREIGN KEY(foo_id) REFERENCES foo (id) | |
) | |
2016-12-01 15:36:46,227 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,227 INFO sqlalchemy.engine.base.Engine COMMIT | |
2016-12-01 15:36:46,229 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) | |
2016-12-01 15:36:46,229 INFO sqlalchemy.engine.base.Engine INSERT INTO foo DEFAULT VALUES | |
2016-12-01 15:36:46,229 INFO sqlalchemy.engine.base.Engine () | |
2016-12-01 15:36:46,229 INFO sqlalchemy.engine.base.Engine COMMIT | |
default | |
2016-12-01 15:36:46,231 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) | |
2016-12-01 15:36:46,231 INFO sqlalchemy.engine.base.Engine SELECT EXISTS (SELECT 1 | |
FROM foo LEFT OUTER JOIN bar AS bar_1 ON foo.id = bar_1.foo_id) AS anon_1 | |
2016-12-01 15:36:46,231 INFO sqlalchemy.engine.base.Engine () | |
True | |
without eagerloads | |
2016-12-01 15:36:46,232 INFO sqlalchemy.engine.base.Engine SELECT EXISTS (SELECT 1 | |
FROM foo) AS anon_1 | |
2016-12-01 15:36:46,232 INFO sqlalchemy.engine.base.Engine () | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment