Michael,
Following is just a suggestion.
...
that sounds very strange. 0.4 and earlier would use TEXT for String with
no size. In 0.5 we did away with that, as its a surprise - we had lot of
"string with no length" complaints, but I would prefer people learn about
String/String(50) instead of assuming that String always needs a length,
since that adds to the "verbose" narrative which really isn't true.
When I started to use SA I also thought one had to be very verbose until
you showed me some tricks.
If "verbose" is still something "hanging" on SA I would suggest to
change the tutorials, e.g. to something like this:
Most tutorial/sample code for declarative show something like this:
class User(Base):
""""""
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
password = Column(String)
#----------------------------------------------------------------------
def __init__(self, name, fullname, password):
"""Constructor"""
self.name = name
self.fullname = fullname
self.password = password
def __repr__(self):
return "<User('%s','%s', '%s')>" % (self.name, self.fullname,
self.password)
Much shorter would be the following and I believe it would work with all
databases.
class User(Base):
""""""
__tablename__ = "users"
id = Column(Integer, Sequence('users_id'), primary_key=True)
name = Column(String(30))
fullname = Column(String(30))
password = Column(String(20))
Then in the text explain that "sequence" and (30) is only needed with
certain db's.
Use the above type of definition with the following:
class BaseExt(object):
"""Does much nicer repr/print of class instances
from sqlalchemy list suggested by Michael Bayer
"""
def __repr__(self):
return "%s(%s)" % (
(self.__class__.__name__),
', '.join(["%s=%r" % (key, getattr(self, key))
for key in sorted(self.__dict__.keys())
if not key.startswith('_')]))
Base = declarative_base(cls=BaseExt)
Werner
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.