On Jan 3, 2012, at 4:14 PM, sector119 wrote:
> Now I get
>
> File "/home/eps/devel/tourclub/sqlalchemy/lib/sqlalchemy/sql/visitors.py",
> line 59, in _compiler_dispatch
> return getter(visitor)(self, **kw)
> File "/home/eps/devel/tourclub/sqlalchemy/lib/sqlalchemy/sql/compiler.py",
> line 370, in visit_column
> raise exc.CompileError("Cannot compile Column object until "
> CompileError: Cannot compile Column object until it's 'name' is assigned.
>
> With
>
> case([(cls.last_read != None, cls.last_read <= func.now() -
> datetime.timedelta(minutes=30))], else_=literal(False))
> case([(cls.last_read != None, literal(cls.last_read <= func.now() -
> datetime.timedelta(minutes=30)))], else_=literal(False))
> case([(cls.last_read != None, literal(cls.last_read <= func.now() -
> datetime.timedelta(minutes=30)).label('foo'))], else_=literal(False))
please forego the usage of column_property() here in favor of a hybrid. An
example is attached, and the SQLAlchemy documentation is being updated right
now to stress that hybrids should be used unless there's a specific performance
advantage to column_property().
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sqlalchemy/-/vRfXbta7DoMJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
import datetime
Base= declarative_base()
class UserMixin(object):
id = Column(Integer, primary_key=True)
username = Column(String(255), unique=True, nullable=False)
last_read = Column("last_read", DateTime)
@hybrid_property
def is_online(self):
if self.last_read is not None:
return self.last_read <= \
datetime.datetime.now() - \
datetime.timedelta(minutes=30)
else:
return False
@is_online.expression
def is_online(cls):
return case([(cls.last_read != None,
cls.last_read <= func.now() -
datetime.timedelta(minutes=30))], else_=literal(False))
class User(UserMixin, Base):
__tablename__ = 'user'
s = Session()
print s.query(User.is_online)