示例#1
0
 def __init__(self, data, db, cache):
     QueryBase.__init__(self)
     session = db.session()
     try:
         conn = self.make_db_connection(data)
         session.add(conn)
         session.commit()
         cache.connections.add(data['connection_name'], data)
         m = 'Added %s connection' % conn.connection_name
         self.out_success_green(conn.connection_name, m, 5000)
     except Exception, e:
         self.out_error(e.message)
示例#2
0
 def __init__(self, data, db, cache):
     QueryBase.__init__(self)
     session = db.session()
     try:
         name = data['connection_name']
         query = session.query(db_model.DatabaseConnection)\
             .filter(db_model.DatabaseConnection.connection_name == name).first()
         session.delete(query)
         session.commit()
         cache.connections.remove(name)
         m = 'Removed %s connection' % name
         self.out_success_blue(name, m, 5000)
     except Exception, e:
         self.out_error(e.message)
示例#3
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)
示例#4
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)