Esempio n. 1
0
    def column_family_name(cls, include_keyspace=True):
        """
        Returns the column family name if it's been defined
        otherwise, it creates it from the module and class name
        """
        cf_name = protect_name(cls._raw_column_family_name())
        if include_keyspace:
            keyspace = cls._get_keyspace()
            if not keyspace:
                raise CQLEngineException("Model keyspace is not set and no default is available. Set model keyspace or setup connection before attempting to generate a query.")
            return '{0}.{1}'.format(protect_name(keyspace), cf_name)

        return cf_name
Esempio n. 2
0
def _get_index_name_by_column(table, column_name):
    """
    Find the index name for a given table and column.
    """
    protected_name = metadata.protect_name(column_name)
    possible_index_values = [protected_name, "values(%s)" % protected_name]
    for index_metadata in table.indexes.values():
        options = dict(index_metadata.index_options)
        if options.get('target') in possible_index_values:
            return index_metadata.name
Esempio n. 3
0
 def test_protect_name(self):
     """
     Test dse.metadata.protect_name output
     """
     self.assertEqual(protect_name('tests'), 'tests')
     self.assertEqual(protect_name('test\'s'), '"test\'s"')
     self.assertEqual(protect_name('test\'s'), "\"test's\"")
     self.assertEqual(protect_name('tests ?!@#$%^&*()'),
                      '"tests ?!@#$%^&*()"')
     self.assertEqual(protect_name('1'), '"1"')
     self.assertEqual(protect_name('1test'), '"1test"')
Esempio n. 4
0
 def _drop_keyspace(name, connection=None):
     cluster = get_cluster(connection)
     if name in cluster.metadata.keyspaces:
         execute("DROP KEYSPACE {0}".format(metadata.protect_name(name)), connection=connection)