Ejemplo n.º 1
0
def open(uri, serializer_name='pickle'):
    ''' open collection by URI, 
    
    if collection does not exist kvlite will try to create it
        
    serializer_name: see details in SERIALIZERS section

    returns MysqlCollection or SqliteCollection object in case of successful 
    opening or creation new collection    
    '''
    # TODO use `None` for serializer to store messages in plain text, suitable for strings, integers, etc

    manager = CollectionManager(uri)
    params = manager.parse_uri(uri)
    if params['collection'] not in manager.collections():
        manager.create(params['collection'])
        
    collection = manager.collection_class(manager.connection, 
                                        params['collection'], 
                                        SERIALIZERS[serializer_name])
    if collection.meta is None:
        collection.meta = {
            'name': params['collection'],
            'serializer': serializer_name,
            'kvlite-version': kvlite.__version__,
        } 
    return collection
Ejemplo n.º 2
0
    def test_sqlite_manager(self):

        URI = 'sqlite://tests/db/testdb.sqlite'
        collection_name = 'kvlite_test'

        manager = CollectionManager(URI)

        if collection_name in manager.collections():
            manager.remove(collection_name)

        self.assertNotIn(collection_name, manager.collections())

        manager.create(collection_name)
        self.assertIn(collection_name, manager.collections())

        manager.remove(collection_name)
        self.assertNotIn(collection_name, manager.collections())
Ejemplo n.º 3
0
    def test_sqlite_manager(self):
        
        URI = 'sqlite://tests/db/testdb.sqlite'
        collection_name = 'kvlite_test'
        
        manager = CollectionManager(URI)

        if collection_name in manager.collections():
            manager.remove(collection_name)
            
        self.assertNotIn(collection_name, manager.collections())

        manager.create(collection_name)
        self.assertIn(collection_name, manager.collections())

        manager.remove(collection_name)
        self.assertNotIn(collection_name, manager.collections())
Ejemplo n.º 4
0
    def test_mysql_manager(self):

        URI = 'mysql://*****:*****@localhost/kvlite_test'
        collection_name = 'kvlite_test'

        manager = CollectionManager(URI)

        if collection_name in manager.collections():
            manager.remove(collection_name)

        self.assertNotIn(collection_name, manager.collections())

        manager.create(collection_name)
        self.assertIn(collection_name, manager.collections())

        manager.remove(collection_name)
        self.assertNotIn(collection_name, manager.collections())
Ejemplo n.º 5
0
    def test_mysql_manager(self):
        
        URI = 'mysql://*****:*****@localhost/kvlite_test'
        collection_name = 'kvlite_test'
        
        manager = CollectionManager(URI)

        if collection_name in manager.collections():
            manager.remove(collection_name)
            
        self.assertNotIn(collection_name, manager.collections())

        manager.create(collection_name)
        self.assertIn(collection_name, manager.collections())

        manager.remove(collection_name)
        self.assertNotIn(collection_name, manager.collections())