當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。