Пример #1
0
 def tableInfo(self, tableNo=1):
     """
     Get table info for a single table number
     @return A dictionary of table information
     """
     self._checkRequestReply()
     self._checkSingleConnection()
     #Send request
     self.socket.send(b"\x31\x01\x06", zmq.SNDMORE)
     self._sendBinary32(tableNo, more=False)
     #Check reply message
     replyParts = self.socket.recv_multipart(copy=True)
     YakDBConnectionBase._checkHeaderFrame(replyParts, b'\x06')
     return YakDBConnectionBase._mapScanToDict(replyParts[1:])
Пример #2
0
 def tableInfo(self, tableNo=1):
     """
     Get table info for a single table number
     @return A dictionary of table information
     """
     self._checkRequestReply()
     self._checkSingleConnection()
     #Send request
     self.socket.send(b"\x31\x01\x06", zmq.SNDMORE)
     self._sendBinary32(tableNo, more=False)
     #Check reply message
     replyParts = self.socket.recv_multipart(copy=True)
     YakDBConnectionBase._checkHeaderFrame(replyParts, b'\x06')
     return YakDBConnectionBase._mapScanToDict(replyParts[1:])
Пример #3
0
    def scan(self, tableNo, startKey=None, endKey=None, limit=None, keyFilter=None, valueFilter=None, skip=0, invert=False, mapData=False, requestId=b""):
        """
        Synchronous scan. Scans an entire range at once.
        The scan stops at the table end, endKey (exclusive) or when
        *limit* keys have been read, whatever occurs first

        See self.read() documentation for an explanation of how
        non-str values are mapped.

        @param tableNo The table number to scan in
        @param startKey The first key to scan, inclusive, or None or "" (both equivalent) to start at the beginning
        @param endKey The last key to scan, exclusive, or None or "" (both equivalent) to end at the end of table
        @param limit The maximum number of keys to read, or None, if no limit shall be imposed
        @param keyFilter If this is non-None, the server filters for keys containing (exactly) this substring
        @param valueFilter If this is non-None, the server filters for values containing (exactly) this substring
        @param skip The number of records to skip at the beginning. Filter mismatches do not count.
        @param invert Set this to True to invert the scan direction
        @param mapData If this is set to False, a list of tuples is returned instead of a directory
        @return A dictionary of the returned key/value pairs
        """
        #Check parameters and create binary-string only key list
        YakDBConnectionBase._checkParameterType(skip, int, "skip")
        YakDBConnectionBase._checkParameterType(tableNo, int, "tableNo")
        YakDBConnectionBase._checkParameterType(limit, int, "limit",  allowNone=True)
        #Check if this connection instance is setup correctly
        self._checkSingleConnection()
        self._checkRequestReply()
        #Send header frame
        self.socket.send(b"\x31\x01\x13" + (b"\x01" if invert else b"\x00") + requestId, zmq.SNDMORE)
        #Send the table number frame
        self._sendBinary32(tableNo)
        #Send limit frame
        self._sendBinary64(limit)
        #Send range. "" --> empty frame --> start/end of table
        self._sendRange(startKey,  endKey, more=True)
        #Send key filter parameters
        self.socket.send(b"" if keyFilter is None else keyFilter, zmq.SNDMORE)
        #Send value filter parameters
        self.socket.send(b"" if valueFilter is None else valueFilter, zmq.SNDMORE)
        #Send skip number
        self._sendBinary64(skip, more=False)
        #Wait for reply
        msgParts = self.socket.recv_multipart(copy=True)
        YakDBConnectionBase._checkHeaderFrame(msgParts, b'\x13') #Remap the returned key/value pairs to a dict
        dataParts = msgParts[1:]
        #Return appropriate data format
        if mapData:
            return YakDBConnectionBase._mapScanToDict(dataParts)
        else:
            return YakDBConnectionBase._mapScanToTupleList(dataParts)
Пример #4
0
    def scan(self,
             tableNo,
             startKey=None,
             endKey=None,
             limit=None,
             keyFilter=None,
             valueFilter=None,
             skip=0,
             invert=False,
             mapData=False,
             requestId=b""):
        """
        Synchronous scan. Scans an entire range at once.
        The scan stops at the table end, endKey (exclusive) or when
        *limit* keys have been read, whatever occurs first

        See self.read() documentation for an explanation of how
        non-str values are mapped.

        @param tableNo The table number to scan in
        @param startKey The first key to scan, inclusive, or None or "" (both equivalent) to start at the beginning
        @param endKey The last key to scan, exclusive, or None or "" (both equivalent) to end at the end of table
        @param limit The maximum number of keys to read, or None, if no limit shall be imposed
        @param keyFilter If this is non-None, the server filters for keys containing (exactly) this substring
        @param valueFilter If this is non-None, the server filters for values containing (exactly) this substring
        @param skip The number of records to skip at the beginning. Filter mismatches do not count.
        @param invert Set this to True to invert the scan direction
        @param mapData If this is set to False, a list of tuples is returned instead of a directory
        @return A dictionary of the returned key/value pairs
        """
        #Check parameters and create binary-string only key list
        YakDBConnectionBase._checkParameterType(skip, int, "skip")
        YakDBConnectionBase._checkParameterType(tableNo, int, "tableNo")
        YakDBConnectionBase._checkParameterType(limit,
                                                int,
                                                "limit",
                                                allowNone=True)
        #Check if this connection instance is setup correctly
        self._checkSingleConnection()
        self._checkRequestReply()
        #Send header frame
        self.socket.send(
            b"\x31\x01\x13" + (b"\x01" if invert else b"\x00") + requestId,
            zmq.SNDMORE)
        #Send the table number frame
        self._sendBinary32(tableNo)
        #Send limit frame
        self._sendBinary64(limit)
        #Send range. "" --> empty frame --> start/end of table
        self._sendRange(startKey, endKey, more=True)
        #Send key filter parameters
        self.socket.send(b"" if keyFilter is None else keyFilter, zmq.SNDMORE)
        #Send value filter parameters
        self.socket.send(b"" if valueFilter is None else valueFilter,
                         zmq.SNDMORE)
        #Send skip number
        self._sendBinary64(skip, more=False)
        #Wait for reply
        msgParts = self.socket.recv_multipart(copy=True)
        YakDBConnectionBase._checkHeaderFrame(
            msgParts, b'\x13')  #Remap the returned key/value pairs to a dict
        dataParts = msgParts[1:]
        #Return appropriate data format
        if mapData:
            return YakDBConnectionBase._mapScanToDict(dataParts)
        else:
            return YakDBConnectionBase._mapScanToTupleList(dataParts)