当前位置: 首页>>代码示例>>Python>>正文


Python Index.suffix方法代码示例

本文整理汇总了Python中django.db.models.Index.suffix方法的典型用法代码示例。如果您正苦于以下问题:Python Index.suffix方法的具体用法?Python Index.suffix怎么用?Python Index.suffix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.Index的用法示例。


在下文中一共展示了Index.suffix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _model_indexes_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _model_indexes_sql(self, model):
        """
        Return a list of all index SQL statements (field indexes,
        index_together, Meta.indexes) for the specified model.
        """
        if not model._meta.managed or model._meta.proxy or model._meta.swapped:
            return []
        output = []
        for field in model._meta.local_fields:
            output.extend(self._field_indexes_sql(model, field))

        for field_names in model._meta.index_together:
            fields = [model._meta.get_field(field) for field in field_names]
            output.append(self._create_index_sql(model, fields, suffix="_idx"))

        for index in model._meta.indexes:
            output.append(index.create_sql(model, self))
        return output 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:schema.py

示例2: _create_fk_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_fk_sql(self, model, field, suffix):
        from_table = model._meta.db_table
        from_column = field.column
        to_table = field.target_field.model._meta.db_table
        to_column = field.target_field.column

        def create_fk_name(*args, **kwargs):
            return self.quote_name(self._create_index_name(*args, **kwargs))

        return Statement(
            self.sql_create_fk,
            table=Table(from_table, self.quote_name),
            name=ForeignKeyName(from_table, [from_column], to_table, [to_column], suffix, create_fk_name),
            column=Columns(from_table, [from_column], self.quote_name),
            to_table=Table(to_table, self.quote_name),
            to_column=Columns(to_table, [to_column], self.quote_name),
            deferrable=self.connection.ops.deferrable_sql(),
        ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:schema.py

示例3: _create_fk_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_fk_sql(self, model, field, suffix):
        from_table = model._meta.db_table
        from_column = field.column
        _, to_table = split_identifier(field.target_field.model._meta.db_table)
        to_column = field.target_field.column

        def create_fk_name(*args, **kwargs):
            return self.quote_name(self._create_index_name(*args, **kwargs))

        return Statement(
            self.sql_create_fk,
            table=Table(from_table, self.quote_name),
            name=ForeignKeyName(from_table, [from_column], to_table, [to_column], suffix, create_fk_name),
            column=Columns(from_table, [from_column], self.quote_name),
            to_table=Table(field.target_field.model._meta.db_table, self.quote_name),
            to_column=Columns(field.target_field.model._meta.db_table, [to_column], self.quote_name),
            deferrable=self.connection.ops.deferrable_sql(),
        ) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:20,代码来源:schema.py

示例4: _create_index_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_index_sql(self, model, fields, suffix="", sql=None):
        """
        Return the SQL statement to create the index for one or several fields.
        `sql` can be specified if the syntax differs from the standard (GIS
        indexes, ...).
        """
        tablespace_sql = self._get_index_tablespace_sql(model, fields)
        columns = [field.column for field in fields]
        sql_create_index = sql or self.sql_create_index
        return sql_create_index % {
            "table": self.quote_name(model._meta.db_table),
            "name": self.quote_name(self._create_index_name(model, columns, suffix=suffix)),
            "using": "",
            "columns": ", ".join(self.quote_name(column) for column in columns),
            "extra": tablespace_sql,
        } 
开发者ID:Yeah-Kun,项目名称:python,代码行数:18,代码来源:schema.py

示例5: _model_indexes_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _model_indexes_sql(self, model):
        """
        Return all index SQL statements (field indexes, index_together,
        Meta.indexes) for the specified model, as a list.
        """
        if not model._meta.managed or model._meta.proxy or model._meta.swapped:
            return []
        output = []
        for field in model._meta.local_fields:
            output.extend(self._field_indexes_sql(model, field))

        for field_names in model._meta.index_together:
            fields = [model._meta.get_field(field) for field in field_names]
            output.append(self._create_index_sql(model, fields, suffix="_idx"))

        for index in model._meta.indexes:
            output.append(index.create_sql(model, self))
        return output 
开发者ID:Yeah-Kun,项目名称:python,代码行数:20,代码来源:schema.py

示例6: _create_fk_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_fk_sql(self, model, field, suffix):
        from_table = model._meta.db_table
        from_column = field.column
        to_table = field.target_field.model._meta.db_table
        to_column = field.target_field.column
        suffix = suffix % {
            "to_table": to_table,
            "to_column": to_column,
        }

        return self.sql_create_fk % {
            "table": self.quote_name(from_table),
            "name": self.quote_name(self._create_index_name(model, [from_column], suffix=suffix)),
            "column": self.quote_name(from_column),
            "to_table": self.quote_name(to_table),
            "to_column": self.quote_name(to_column),
            "deferrable": self.connection.ops.deferrable_sql(),
        } 
开发者ID:Yeah-Kun,项目名称:python,代码行数:20,代码来源:schema.py

示例7: get_constraints

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def get_constraints(self, cursor, table_name):
        constraint = {}

        indexes = cursor.db_conn[table_name].index_information()
        for name, info in indexes.items():
            if name == '_id_':
                continue

            columns = [field[0] for field in info['key']]
            orders = ['ASC' if field[1] == 1 else 'DESC'
                      for field in info['key']]
            constraint[name] = {
                'columns': columns,
                'primary_key': name == '__primary_key__',
                'unique': info.get('unique', False),
                'index': True,
                'orders': orders,
                "foreign_key": False,
                "check": False,
                'type': Index.suffix
            }
        return constraint 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:introspection.py

示例8: alter_index_together

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def alter_index_together(self, model, old_index_together, new_index_together):
        """
        Deal with a model changing its index_together. The input
        index_togethers must be doubly-nested, not the single-nested
        ["foo", "bar"] format.
        """
        olds = {tuple(fields) for fields in old_index_together}
        news = {tuple(fields) for fields in new_index_together}
        # Deleted indexes
        for fields in olds.difference(news):
            self._delete_composed_index(model, fields, {'index': True}, self.sql_delete_index)
        # Created indexes
        for field_names in news.difference(olds):
            fields = [model._meta.get_field(field) for field in field_names]
            self.execute(self._create_index_sql(model, fields, suffix="_idx")) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:schema.py

示例9: _create_index_name

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_index_name(self, table_name, column_names, suffix=""):
        """
        Generate a unique name for an index/unique constraint.

        The name is divided into 3 parts: the table name, the column names,
        and a unique digest and suffix.
        """
        _, table_name = split_identifier(table_name)
        hash_data = [table_name] + list(column_names)
        hash_suffix_part = '%s%s' % (self._digest(*hash_data), suffix)
        max_length = self.connection.ops.max_name_length() or 200
        # If everything fits into max_length, use that name.
        index_name = '%s_%s_%s' % (table_name, '_'.join(column_names), hash_suffix_part)
        if len(index_name) <= max_length:
            return index_name
        # Shorten a long suffix.
        if len(hash_suffix_part) > max_length / 3:
            hash_suffix_part = hash_suffix_part[:max_length // 3]
        other_length = (max_length - len(hash_suffix_part)) // 2 - 1
        index_name = '%s_%s_%s' % (
            table_name[:other_length],
            '_'.join(column_names)[:other_length],
            hash_suffix_part,
        )
        # Prepend D if needed to prevent the name from starting with an
        # underscore or a number (not permitted on Oracle).
        if index_name[0] == "_" or index_name[0].isdigit():
            index_name = "D%s" % index_name[:-1]
        return index_name 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:31,代码来源:schema.py

示例10: _create_index_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_index_sql(self, model, fields, *, name=None, suffix='', using='',
                          db_tablespace=None, col_suffixes=(), sql=None):
        """
        Return the SQL statement to create the index for one or several fields.
        `sql` can be specified if the syntax differs from the standard (GIS
        indexes, ...).
        """
        tablespace_sql = self._get_index_tablespace_sql(model, fields, db_tablespace=db_tablespace)
        columns = [field.column for field in fields]
        sql_create_index = sql or self.sql_create_index
        table = model._meta.db_table

        def create_index_name(*args, **kwargs):
            nonlocal name
            if name is None:
                name = self._create_index_name(*args, **kwargs)
            return self.quote_name(name)

        return Statement(
            sql_create_index,
            table=Table(table, self.quote_name),
            name=IndexName(table, columns, suffix, create_index_name),
            using=using,
            columns=Columns(table, columns, self.quote_name, col_suffixes=col_suffixes),
            extra=tablespace_sql,
        ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:28,代码来源:schema.py

示例11: _create_index_name

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_index_name(self, table_name, column_names, suffix=""):
        """
        Generate a unique name for an index/unique constraint.

        The name is divided into 3 parts: the table name, the column names,
        and a unique digest and suffix.
        """
        _, table_name = split_identifier(table_name)
        hash_suffix_part = '%s%s' % (self._digest(table_name, *column_names), suffix)
        max_length = self.connection.ops.max_name_length() or 200
        # If everything fits into max_length, use that name.
        index_name = '%s_%s_%s' % (table_name, '_'.join(column_names), hash_suffix_part)
        if len(index_name) <= max_length:
            return index_name
        # Shorten a long suffix.
        if len(hash_suffix_part) > max_length / 3:
            hash_suffix_part = hash_suffix_part[:max_length // 3]
        other_length = (max_length - len(hash_suffix_part)) // 2 - 1
        index_name = '%s_%s_%s' % (
            table_name[:other_length],
            '_'.join(column_names)[:other_length],
            hash_suffix_part,
        )
        # Prepend D if needed to prevent the name from starting with an
        # underscore or a number (not permitted on Oracle).
        if index_name[0] == "_" or index_name[0].isdigit():
            index_name = "D%s" % index_name[:-1]
        return index_name 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:30,代码来源:schema.py

示例12: create_sql

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def create_sql(self, model, schema_editor, using=''):
        statement = super().create_sql(model, schema_editor, using=' USING %s' % self.suffix)
        with_params = self.get_with_params()
        if with_params:
            statement.parts['extra'] = 'WITH (%s) %s' % (
                ', '.join(with_params),
                statement.parts['extra'],
            )
        return statement 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:11,代码来源:indexes.py

示例13: alter_index_together

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def alter_index_together(self, model, old_index_together, new_index_together):
        """
        Deals with a model changing its index_together.
        Note: The input index_togethers must be doubly-nested, not the single-
        nested ["foo", "bar"] format.
        """
        olds = set(tuple(fields) for fields in old_index_together)
        news = set(tuple(fields) for fields in new_index_together)
        # Deleted indexes
        for fields in olds.difference(news):
            self._delete_composed_index(model, fields, {'index': True}, self.sql_delete_index)
        # Created indexes
        for field_names in news.difference(olds):
            fields = [model._meta.get_field(field) for field in field_names]
            self.execute(self._create_index_sql(model, fields, suffix="_idx")) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:17,代码来源:schema.py

示例14: _create_index_name

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def _create_index_name(self, model, column_names, suffix=""):
        """
        Generates a unique name for an index/unique constraint.

        The name is divided into 3 parts: the table name, the column names,
        and a unique digest and suffix.
        """
        table_name = strip_quotes(model._meta.db_table)
        hash_data = [table_name] + list(column_names)
        hash_suffix_part = '%s%s' % (self._digest(*hash_data), suffix)
        max_length = self.connection.ops.max_name_length() or 200
        # If everything fits into max_length, use that name.
        index_name = '%s_%s_%s' % (table_name, '_'.join(column_names), hash_suffix_part)
        if len(index_name) <= max_length:
            return index_name
        # Shorten a long suffix.
        if len(hash_suffix_part) > max_length / 3:
            hash_suffix_part = hash_suffix_part[:max_length // 3]
        other_length = (max_length - len(hash_suffix_part)) // 2 - 1
        index_name = '%s_%s_%s' % (
            table_name[:other_length],
            '_'.join(column_names)[:other_length],
            hash_suffix_part,
        )
        # Prepend D if needed to prevent the name from starting with an
        # underscore or a number (not permitted on Oracle).
        if index_name[0] == "_" or index_name[0].isdigit():
            index_name = "D%s" % index_name[:-1]
        return index_name 
开发者ID:Yeah-Kun,项目名称:python,代码行数:31,代码来源:schema.py

示例15: max_name_length

# 需要导入模块: from django.db.models import Index [as 别名]
# 或者: from django.db.models.Index import suffix [as 别名]
def max_name_length(self):
        # Allow an index name longer than 30 characters when the suffix is
        # longer than the usual 3 character limit. The 30 character limit for
        # cross-database compatibility isn't applicable to PostgreSQL-specific
        # indexes.
        return Index.max_name_length - len(Index.suffix) + len(self.suffix) 
开发者ID:vintasoftware,项目名称:django-zombodb,代码行数:8,代码来源:base_indexes.py


注:本文中的django.db.models.Index.suffix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。