Пример #1
0
 def test_with_base_idx_is_one(self):
     values = [[6],
               [['_id', 'UInt32'],
                ['item', 'item_query'],
                ['sequence', 'sequence_query'],
                ['time', 'Time'],
                ['type', 'event_type']],
               [1, 's', 'deadbeef', 12.0, ''],
               [2, 'se', 'deadbeef', 13.0, ''],
               [3, 'sea', 'deadbeef', 14.0, 'submit']]
     expected = [
         {'_id': 1,
          'item': 's',
          'sequence': 'deadbeef',
          'time': 12.0,
          'type': ''},
         {'_id': 2,
          'item': 'se',
          'sequence': 'deadbeef',
          'time': 13.0,
          'type': ''},
         {'_id': 3,
          'item': 'sea',
          'sequence': 'deadbeef',
          'time': 14.0,
          'type': 'submit'}]
     result = utils.to_python(values, 1)
     assert result == expected
Пример #2
0
 def test_with_base_idx_is_zero(self):
     values = [[
         ["id", "UInt32"],
         ["name", "ShortText"],
         ["path", "ShortText"],
         ["flags", "ShortText"],
         ["domain", "ShortText"],
         ["range", "ShortText"],
         ["default_tokenizer", "ShortText"],
         ["normalizer", "ShortText"]],
         [256,
          "TestTable",
          "a.db.0000100",
          "TABLE_HASH_KEY|PERSISTENT",
          "ShortText",
          None,
          None,
          None]]
     expected = [{
         'id': 256,
         'name': 'TestTable',
         'path': 'a.db.0000100',
         'flags': 'TABLE_HASH_KEY|PERSISTENT',
         'domain': 'ShortText',
         'range': None,
         'default_tokenizer': None,
         'normalizer': None,
         }]
     result = utils.to_python(values, 0)
     assert result == expected
Пример #3
0
    def __init__(self, cls, results, maxlen=None):
        """Construct of GroongaResultBase

        :param cls: Class for mappings.
        :param results: query results.
        :param maxlen: maximum length of mapping results. Default is all.
        """
        self._result = tuple(GroongaRecord(cls, **mapped) for mapped in
            utils.to_python(results, 1, maxlen))
        self._all_len = results[0][0]
Пример #4
0
    def create_all(cls):
        """Create the all defined tables and columns

        :param grn: instance of :class:`pyroonga.groonga.Groonga`\ .
        """
        if not isinstance(cls.grn, Groonga):
            raise TypeError("%s object is not bind" % Groonga.__name__)
        table_queries = []
        column_queries = []
        json_results = json.loads(cls.grn.query('table_list'))
        defined_tables = utils.to_python(json_results, 0)
        defined_table_names = tuple(v['name'] for v in defined_tables)
        for tbl in (t for t in cls._tables if t.__tablename__ not in
                    defined_table_names):
            table_queries.append(str(tbl))
            column_queries.extend(str(col) for col in tbl.columns)
        for queries in (table_queries, column_queries):
            for query in queries:
                logger.debug(query)
                cls.grn.query(query)