Example #1
0
'''here we drop all of our old tables.  we do this because create all (used below) does not create new tables if
that same table already exists'''
sets.drop(mys_engine,checkfirst=True)  
lifts.drop(mys_engine,checkfirst=True)
workout.drop(mys_engine,checkfirst=True)
user.drop(mys_engine,checkfirst=True)
 


'''this was the old function we used: meta.create_all(mys_engine)
this is stupid.  we didn't bind metadata and then used mys_engine in the bind parameter spot.
Although I don't know the pro's and con's of binding, we are going to bind then create - Project king'''

meta.bind=mys_engine '''mys_engine is now bound to our metadata'''
meta.create_all()       '''this creates all the tables that make up our metadata object'''

'''if we have bound our metadata to an engine, we can do connectionless queries from our table ojbects
        i.e. res=user.select().execute()'''

'''unbound this would look like:
    connection=engine.connect()
    res=connection.execute(user.select())'''

'''binding is quicker and i'm sure there are horrible downsides, but fuck it - Project King'''
 




Example #2
0
'''this is our new setup for the fitness charts using sql alchemy'''
#this creates our test tables
from tableSetup import sets,lifts,exercise,metcon,workout,user,meta
from sqlalchemy import create_engine,MetaData
from sqlalchemy.ext.declarative import declarative_base
#from test0Classes import User,Workout,Lifts,Sets,Metcon,Exercise

#mys_engine=create_engine('mysql+mysqldb://root:[email protected]/test0',echo=True)
mys_engine=create_engine('sqlite:////Users/Charles/ldb/ldb/test0.db',echo=True)

sets.drop(mys_engine,checkfirst=True)
lifts.drop(mys_engine,checkfirst=True)
exercise.drop(mys_engine,checkfirst=True)
metcon.drop(mys_engine,checkfirst=True)
workout.drop(mys_engine,checkfirst=True)
user.drop(mys_engine,checkfirst=True)


meta.create_all(mys_engine)