Beispiel #1
0
	def createCollection(self, className = 'Collection', waitForSync = False, **colArgs) :
		"""Creates a collection and returns it.
		ClassName the name of a class inheriting from Collection or Egdes, it can also be set to 'Collection' or 'Edges' in order to create untyped collections of documents or edges.
		Use colArgs to put things such as 'isVolatile = True' (see ArangoDB's doc
		for a full list of possible arugments)."""
		
		if className != 'Collection' and className != 'Edges' :
			colArgs['name'] = className
		else :
			if 'name' not in colArgs :
				raise ValueError("a 'name' argument mush be supplied if you want to create a generic collection")
					
		colClass = COL.getCollectionClass(className)

		if colArgs['name'] in self.collections :
			raise CreationError("Database %s already has a collection named %s" % (self.name, colArgs['name']) )

		if issubclass(colClass, COL.Edges) or colClass.__class__ is COL.Edges:
			colArgs["type"] = COL.COLLECTION_EDGE_TYPE
		else :
			colArgs["type"] = COL.COLLECTION_DOCUMENT_TYPE
		
		colArgs["waitForSync"] = waitForSync

		payload = json.dumps(colArgs)
		r = self.connection.session.post(self.collectionsURL, data = payload)
		data = r.json()
		
		if r.status_code == 200 and not data["error"] :
			col = colClass(self, data)
			self.collections[col.name] = col
			return self.collections[col.name]
		else :
			raise CreationError(data["errorMessage"], data)
Beispiel #2
0
	def reloadCollections(self) :
		"reloads the collection list."
		r = self.connection.session.get(self.collectionsURL)
		data = r.json()
		if r.status_code == 200 :
			self.collections = {}
			
			for colData in data["result"] :
				colName = colData['name']
				if colData['isSystem'] :
					colObj = COL.SystemCollection(self, colData)
				else :
					try :
						colClass = COL.getCollectionClass(colName)
						colObj = colClass(self, colData)
					except KeyError :
						if colData["type"] == COL.COLLECTION_EDGE_TYPE :
							colObj = COL.Edges(self, colData)
						elif colData["type"] == COL.COLLECTION_DOCUMENT_TYPE :
							colObj = COL.Collection(self, colData)
						else :
							print("Warning!! Collection of unknown type: %d, trying to load it as Collection nonetheless." % colData["type"])
							colObj = COL.Collection(self, colData)

				self.collections[colName] = colObj
		else :
			raise updateError(data["errorMessage"], data)
Beispiel #3
0
	def createCollection(self, className = 'Collection', waitForSync = False, **colArgs) :
		"""Creates a collection and returns it.
		ClassName the name of a class inheriting from Collection or Egdes, it can also be set to 'Collection' or 'Edges' in order to create untyped collections of documents or edges.
		Use colArgs to put things such as 'isVolatile = True' (see ArangoDB's doc
		for a full list of possible arugments)."""
		
		if className != 'Collection' and className != 'Edges' :
			colArgs['name'] = className
		else :
			if 'name' not in colArgs :
				raise ValueError("a 'name' argument mush be supplied if you want to create a generic collection")
					
		colClass = COL.getCollectionClass(className)

		if colArgs['name'] in self.collections :
			raise CreationError("Database %s already has a collection named %s" % (self.name, colArgs['name']) )

		if issubclass(colClass, COL.Edges) or colClass.__class__ is COL.Edges:
			colArgs["type"] = COL.COLLECTION_EDGE_TYPE
		else :
			colArgs["type"] = COL.COLLECTION_DOCUMENT_TYPE
		
		colArgs["waitForSync"] = waitForSync

		payload = json.dumps(colArgs)
		r = self.connection.session.post(self.collectionsURL, data = payload)
		data = r.json()
		
		if r.status_code == 200 and not data["error"] :
			col = colClass(self, data)
			self.collections[col.name] = col
			return self.collections[col.name]
		else :
			raise CreationError(data["errorMessage"], data)
Beispiel #4
0
	def reloadCollections(self) :
		"reloads the collection list."
		r = self.connection.session.get(self.collectionsURL)
		data = r.json()
		if r.status_code == 200 :
			self.collections = {}
			
			for colData in data["collections"] :
				colName = colData['name']
				if colData['isSystem'] :
					colObj = COL.SystemCollection(self, colData)
				else :
					try :
						colClass = COL.getCollectionClass(colName)
						# if colName[0] != "_" :
						colObj = colClass(self, colData)
					except KeyError :
						if colData["type"] == COL.COLLECTION_EDGE_TYPE :
							colObj = COL.Edges(self, colData)
						elif colData["type"] == COL.COLLECTION_DOCUMENT_TYPE :
							colObj = COL.Collection(self, colData)
						else :
							print("Warning!! Collection of unknown type: %d, trying to load it as Collection nonetheless." % colData["type"])
							colObj = COL.Collection(self, colData)

				self.collections[colName] = colObj
		else :
			raise updateError(data["errorMessage"], data)
Beispiel #5
0
    def reloadCollections(self):
        "reloads the collection list."
        r = requests.get(self.collectionsURL)
        data = r.json()
        if r.status_code == 200:
            self.collections = {}

            for colData in data["collections"]:
                colName = colData['name']
                if colData['isSystem']:
                    colObj = COL.SystemCollection(self, colData)
                else:
                    try:
                        colClass = COL.getCollectionClass(colName)
                        colObj = colClass(self, colData)
                    except KeyError:
                        colObj = COL.GenericCollection(self, colData)
                self.collections[colName] = colObj
        else:
            raise updateError(data["errorMessage"], data)
Beispiel #6
0
	def reloadCollections(self) :
		"reloads the collection list."
		r = self.connection.session.get(self.collectionsURL)
		data = r.json()
		if r.status_code == 200 :
			self.collections = {}
			
			for colData in data["collections"] :
				colName = colData['name']
				if colData['isSystem'] :
					colObj = COL.SystemCollection(self, colData)
				else :
					try :
						colClass = COL.getCollectionClass(colName)
						colObj = colClass(self, colData)
					except KeyError :
						colObj = COL.GenericCollection(self, colData)
				self.collections[colName] = colObj
		else :
			raise updateError(data["errorMessage"], data)