Beispiel #1
0
 def __init__(self, data, cache):
     QueryBase.__init__(self)
     try:
         name = data['connection_name']
         conn = cache.connections.get(name)
         # TODO simplify move parts to cache
         from craft.db.parser import DBParser
         from craft import model
         from craft.db.connector import DBConnector
         config = model.DBConfig(conn)
         db = DBConnector(config)
         parser = DBParser()
         structure = parser.parsetables(db.get_metadata(), db.dbversion)
         m = 'DatabaseStructure : %s' % name
         self.out_success_green(self.serialize(structure), m, 5000)
     except Exception, e:
         self.out_error(e.message)
Beispiel #2
0
 def __init__(self, data, cache):
     QueryBase.__init__(self)
     try:
         name = data['connection_name']
         query = data['query']
         conn = cache.connections.get(name)
         # TODO simplify move parts to cache
         from craft import model
         from craft.db.connector import DBConnector
         config = model.DBConfig(conn)
         db = DBConnector(config)
         result = db.execute(query)
         m = 'Query %s : %s' % (name, query)
         out = {
             'titles':result._metadata.keys,
             'data':[],
         }
         for one in result:
             out['data'].append(one._row)
         self.out_success_green(out, m, 5000)
     except Exception, e:
         self.out_error(e.message)
Beispiel #3
0
 def db_test(self):
     data = json.loads(request.data)
     config = model.DBConfig(data)
     db = DBConnector(config)
     db.create_session()
     return json.dumps({'code': 0, 'msg': 'Connection ok', 'time': constraints.POPUP_TIMEOUT, 'data': None})
Beispiel #4
0
def start(conf):
    db = DBConnector(conf)
    db.create_session()
    # reset database
    Base.metadata.drop_all(db._engine)
    Base.metadata.create_all(db._engine)