예제 #1
0
	def __init__(self):
		mongoDB_uri = os.environ.get("MONGOLAB_URI", "localhost:27017")

		last_slash = mongoDB_uri.rfind("/")
		dbName = mongoDB_uri[last_slash + 1:]

		if dbName == mongoDB_uri:
			dbName = "operationBryan"

		try:
			connection = Connection(mongoDB_uri)
			connection.register([Concept])
			self.database = connection[dbName]
		except ConnectionError:
			print('Error: Unable to connect to database.')
			sys.exit(1)
class DBSimpleClient(object):
    '''
    Class for communicating with the database's first version conveniently
    '''
    def __init__(self):
        '''
        Sets a connection to mongodb
        '''
        self.connection = Connection()
        self.connection.register([Function])

    def insert(self, function_data):
        '''
        Inserts given function data to the database
        '''
        function = self.connection.Function()
        function['source_website'] = function_data['source_website']
        function['package'] = function_data['package']
        function['download_link'] = function_data['download_link']
        function['elf_name'] = function_data['elf_name']
        function['function_name'] = function_data['function_name']
        if all(isinstance(s, str) for s in function_data['subgraphs']):
            function['subgraphs'] = [
                bson.binary.Binary(s) for s in function_data['subgraphs']
            ]
        elif all(
                isinstance(s, bson.binary.Binary)
                for s in function_data['subgraphs']):
            function['subgraphs'] = function_data['subgraphs']
        else:
            raise ValueError(
                'Subgraphs type is illegal (not string nor binary)')
        function.save()

    def get_all(self):
        '''
        Returns the functions data in the DB
        '''
        return [
            Function(func_doc)
            for func_doc in self.connection.function.functions.find()[:]
        ]

    def connections_number(self):
        return 1
예제 #3
0
class DBSimpleClient(object):
    '''
    Class for communicating with the database's first version conveniently
    '''
    
    def __init__(self):
        '''
        Sets a connection to mongodb
        '''
        self.connection = Connection()
        self.connection.register([Function]) 
        
    def insert(self, function_data):
        '''
        Inserts given function data to the database
        '''
        function = self.connection.Function()
        function['source_website'] = function_data['source_website']
        function['package'] = function_data['package']
        function['download_link'] = function_data['download_link']
        function['elf_name'] = function_data['elf_name']
        function['function_name'] = function_data['function_name']
        if all(isinstance(s, str) for s in function_data['subgraphs']):
            function['subgraphs'] = [bson.binary.Binary(s) for s in function_data['subgraphs']]
        elif all(isinstance(s, bson.binary.Binary) for s in function_data['subgraphs']):
            function['subgraphs'] = function_data['subgraphs']
        else:
            raise ValueError('Subgraphs type is illegal (not string nor binary)')        
        function.save()

    def get_all(self):
        '''
        Returns the functions data in the DB
        '''
        return [Function(func_doc) for func_doc in self.connection.function.functions.find()[:]]
    
    def connections_number(self):
        return 1
 def __init__(self):
     '''
     Sets a connection to mongodb
     '''
     self.connection = Connection()
     self.connection.register([Function])
    "CACHE_TYPE" : "redis",
    "CACHE_REDIS_HOST": "127.0.0.1",
    "CACHE_REDIS_PORT": 6379,
    "CACHE_REDIS_DB": 0

})


#register others controller
#app.register_blueprint(account_api)

path = os.path.dirname(os.path.abspath(__file__))


# connect to the database
connection = Connection(app.config['MONGODB_HOST'],app.config['MONGODB_PORT'])


#registre schemes

connection.register([User])

collection = connection['test'].users


CONFIG_POOL = {
    'pool_name':"simple-pool",
    'pool_size':10,
    'autocommit':True,
    'user':"******",
    'password':"",
예제 #6
0
 def __init__(self):
     '''
     Sets a connection to mongodb
     '''
     self.connection = Connection()
     self.connection.register([Function])