コード例 #1
0
ファイル: test_sqlalchemy.py プロジェクト: polyactis/test
	def __init__(self, name=None):
		self.keyword_name = name
	def __repr__(self):
		return self.keyword_name

#clear_mappers()

mapper(Article, articles, properties = {
    'keywords': relation(Keyword, secondary=association, backref='articles'),
})
mapper(Keyword, keywords)

a1 = Article(headline="Python is cool!")
a1.body="(to be written)"
a2 = Article(headline="SQLAlchemy Tutorial", body="You're reading it")
session.save(a1)
session.save(a2)
a3 = Article(headline='whatever 1')
session.save(a3)
a3 = Article(headline='whatever 2')
session.save(a3)
#session.flush()

print "check stuff in db before flush:"
#entries above wouldn't be found because session.flush() was commented out. Old stuff in db would be shown if it exists.
i = 0
row = session.query(Article).offset(i).limit(1).list()
while row:
	row = row[0]
	print row.headline
	print row.keywords
コード例 #2
0
ファイル: __init__.py プロジェクト: Ciemaar/oaf
user_mapper= mapper( User, users_table, properties= {"oafs":relation(Oaf)})            
oaf_mapper= mapper( Oaf, oafs_table, properties= {"pagemonitors":relation(PageMonitor)})            
page_mapper = mapper( PageMonitor, pagemonitors_table)

            
if __name__=="__main__":
    print "Setting up database with test data"
    print "Creating tables"
    meta.create_all()
    
    apf = Oaf("Andy Fundinger")
    #apf.pagemonitors.append(PageMonitor("http://216.254.64.114:8813/factory","Gerri Lit"))
    apf.pagemonitors.append(PageMonitor("http://localhost:8813/bookstore/Wilson", "Wilhelm Lit"))
    apf.pagemonitors.append(PageMonitor("http://localhost:8956/systems/rocketLaunch", "Daes dae'mar"))
    
    ivm = Oaf("IVM")
    ivm.pagemonitors.append(PageMonitor("http://localhost:8293/feedServer/"))
    
    mmbx = Oaf("MMBX")
    mmbx.pagemonitors.append(PageMonitor("http://example.com/"))
    mmbx.pagemonitors.append(PageMonitor("http://localhost/"))

    cf = User(AVNAME, AVUUID)
    cf.oafs.append(apf)
    cf.oafs.append(ivm)    
    Session.save(cf)
    Session.commit()
    
    print PageMonitor.all()
    print Oaf.all()