def db_connect(): """ Create a new connection to the DataBase (SQLObject use connection pool) associated to the current thread. """ #if not jcl.model.db_connected: jcl.model.hub.threadConnection = connectionForURI(db_connection_str)
def __init__(self): connection = connectionForURI("sqlite:/:memory:") sqlhub.processConnection = connection try: User.createTable() Stocks.createTable() except: pass
import os from sqlobject.col import StringCol, ForeignKey, BoolCol from sqlobject.dbconnection import connectionForURI from sqlobject.main import sqlhub, SQLObject db_filename = os.path.abspath('data.db') connection_string = 'sqlite:' + db_filename connection = connectionForURI(connection_string) sqlhub.processConnection = connection class User(SQLObject): username = StringCol(unique=True, notNone=True) country_code = StringCol(notNone=True) @staticmethod def get_user(username): return User.selectBy(username=username.lower()).getOne(default=None) class Stream(SQLObject): user = ForeignKey('User') title = StringCol(notNone=True) url = StringCol(notNone=True) ended = BoolCol(default=False) User.createTable(ifNotExists=True) Stream.createTable(ifNotExists=True)
def main(): if len(sys.argv[1:]) != 2: usage() oldConn = dbconnection.connectionForURI(sys.argv[1]) newConn = dbconnection.connectionForURI(sys.argv[2]) dbCopy(oldConn, newConn)