Skip to content

Instantly share code, notes, and snippets.

@gamerlv
Created December 29, 2012 20:51
Show Gist options
  • Save gamerlv/4409270 to your computer and use it in GitHub Desktop.
Save gamerlv/4409270 to your computer and use it in GitHub Desktop.
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import Column, String, Integer, create_engine
Base = declarative_base()
class Ban(Base):
__tablename__="ab_list"
id = Column(Integer, primary_key=True )
nick = Column(String(64))
adminnick = Column(String(64))
ip = Column(String(35))
banfrom = Column(Integer)
banto = Column(Integer)
reason = Column(String(128))
unbannick = Column(String(64))
unbanreason = Column(String(64))
status = Column(Integer)
def __init__(self,nick,adminnick,ip,banfrom,banto,reason,unbannick,unbanreason,status):
super(Ban,self)
self.nick = nick
self.adminnick = adminnick
self.ip = ip
self.banfrom = banfrom
self.banto = banto
self.reason = reason
self.unbannick = None
self.unbanreason = None
self.status = 1
def getName(self):
return self.nick
if __name__ == '__main__':
engine = create_engine('mysql://user:password@host/database?charset=utf8', echo=False) # database urls: http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls
Session = sessionmaker(bind=engine)
Session = Session()
for banInsta in Session.query(Ban).filter_by(id=244):
print banInsta
print banInsta.reason + banInsta.nick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment