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


Python connection.vendor方法代码示例

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


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

示例1: _run

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def _run(anonymizer, objs):
    values = {}
    replacer_attr = tuple(r[0] for r in anonymizer.replacers)
    for obj in objs.iterator():
        retval = anonymizer.alter_object(obj)
        if retval is False:
            continue

        values[obj.pk] = {attname: getattr(obj, attname) for attname in replacer_attr}

    query = anonymizer.create_query(replacer_attr)
    query_args = anonymizer.create_query_args(values, replacer_attr)

    with transaction.atomic():
        with connection.cursor() as cursor:
            if connection.vendor == 'postgresql':
                cursor.execute('SET CONSTRAINTS ALL DEFERRED')
            cursor.executemany(query, query_args) 
开发者ID:BetterWorks,项目名称:django-anonymizer,代码行数:20,代码来源:base.py

示例2: settings

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def settings(self):
        if self.cached_settings:
            return self.cached_settings
        else:
            from django.conf import settings
            allowed_configurations = {
                'CONTENT_TYPE_CLASS': ContentType,
                'USER_CLASS': settings.AUTH_USER_MODEL,
                'PERMISSION_CLASS': Permission,
                'GROUP_CLASS': Group,
                'INJECT_MODEL_ADMIN': False
            }
            river_settings = {}
            for key, default in allowed_configurations.items():
                river_settings[key] = getattr(settings, self.get_with_prefix(key), default)

            river_settings['IS_MSSQL'] = connection.vendor == 'microsoft'
            self.cached_settings = river_settings

            return self.cached_settings 
开发者ID:javrasya,项目名称:django-river,代码行数:22,代码来源:config.py

示例3: create_db_comments

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def create_db_comments(table_name, table_comment, column_comments=None):
    """Populate comments for non-model tables (like Django-specific tables)"""

    if connection.vendor != 'postgresql':
        return

    with connection.cursor() as cursor:
        try:
            cursor.execute(
                'comment on table "{}" is %s'.format(table_name), [table_comment]
            )
        except ProgrammingError:
            print(_exception_message)

        if column_comments is not None:
            for column, comment in column_comments.items():
                try:
                    cursor.execute(
                        'comment on column "{}"."{}" is %s'.format(table_name, column), [comment]
                    )
                except ProgrammingError as e:
                    print('{} -- {}'.format(_exception_message, e)) 
开发者ID:bcgov,项目名称:tfrs,代码行数:24,代码来源:db_actions.py

示例4: test_index_name

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def test_index_name(self):
        """
        Index names on the built-in database backends::
            * Are truncated as needed.
            * Include all the column names.
            * Include a deterministic hash.
        """
        long_name = 'l%sng' % ('o' * 100)
        with connection.schema_editor() as editor:
            index_name = editor._create_index_name(
                model=Article,
                column_names=('c1', 'c2', long_name),
                suffix='ix',
            )
        expected = {
            'mysql': 'indexes_article_c1_c2_looooooooooooooooooo_255179b2ix',
            'oracle': 'indexes_a_c1_c2_loo_255179b2ix',
            'postgresql': 'indexes_article_c1_c2_loooooooooooooooooo_255179b2ix',
            'sqlite': 'indexes_article_c1_c2_l%sng_255179b2ix' % ('o' * 100),
        }
        if connection.vendor not in expected:
            self.skipTest('This test is only supported on the built-in database backends.')
        self.assertEqual(index_name, expected[connection.vendor]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:tests.py

示例5: test_index_name

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def test_index_name(self):
        """
        Index names on the built-in database backends::
            * Are truncated as needed.
            * Include all the column names.
            * Include a deterministic hash.
        """
        long_name = 'l%sng' % ('o' * 100)
        with connection.schema_editor() as editor:
            index_name = editor._create_index_name(
                table_name=Article._meta.db_table,
                column_names=('c1', 'c2', long_name),
                suffix='ix',
            )
        expected = {
            'mysql': 'indexes_article_c1_c2_looooooooooooooooooo_255179b2ix',
            'oracle': 'indexes_a_c1_c2_loo_255179b2ix',
            'postgresql': 'indexes_article_c1_c2_loooooooooooooooooo_255179b2ix',
            'sqlite': 'indexes_article_c1_c2_l%sng_255179b2ix' % ('o' * 100),
        }
        if connection.vendor not in expected:
            self.skipTest('This test is only supported on the built-in database backends.')
        self.assertEqual(index_name, expected[connection.vendor]) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例6: test_basic

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def test_basic(self):
        querysets = [
            Tag.objects.filter(name='test'),
            Tag.objects.filter(name='test').select_related('parent'),
            Tag.objects.filter(name='test').prefetch_related('children'),
            Tag.objects.filter(name='test').annotate(Count('children')),
            Tag.objects.filter(name='test').values_list('name'),
            Tag.objects.order_by().union(Tag.objects.order_by().filter(name='test')),
            Tag.objects.all().select_for_update().filter(name='test'),
        ]
        supported_formats = connection.features.supported_explain_formats
        all_formats = (None,) + tuple(supported_formats) + tuple(f.lower() for f in supported_formats)
        for idx, queryset in enumerate(querysets):
            for format in all_formats:
                with self.subTest(format=format, queryset=idx):
                    if connection.vendor == 'mysql':
                        # This does a query and caches the result.
                        connection.features.needs_explain_extended
                    with self.assertNumQueries(1), CaptureQueriesContext(connection) as captured_queries:
                        result = queryset.explain(format=format)
                        self.assertTrue(captured_queries[0]['sql'].startswith(connection.ops.explain_prefix))
                        self.assertIsInstance(result, str)
                        self.assertTrue(result) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:test_explain.py

示例7: test_mutation

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def test_mutation(raises=True):
    def wrapper(mutation_func):
        def test(test_case_instance, *args, **kwargs):
            class TestFunc(Func):
                output_field = models.IntegerField()

                def __init__(self):
                    self.attribute = 'initial'
                    super().__init__('initial', ['initial'])

                def as_sql(self, *args, **kwargs):
                    mutation_func(self)
                    return '', ()

            if raises:
                msg = 'TestFunc Func was mutated during compilation.'
                with test_case_instance.assertRaisesMessage(AssertionError, msg):
                    getattr(TestFunc(), 'as_' + connection.vendor)(None, None)
            else:
                getattr(TestFunc(), 'as_' + connection.vendor)(None, None)

        return test
    return wrapper 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:test_gis_tests_utils.py

示例8: test_index_name

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def test_index_name(self):
        """
        Index names on the built-in database backends::
            * Are truncated as needed.
            * Include all the column names.
            * Include a deterministic hash.
        """
        long_name = 'l%sng' % ('o' * 100)
        editor = connection.schema_editor()
        index_name = editor._create_index_name(
            table_name=Article._meta.db_table,
            column_names=('c1', 'c2', long_name),
            suffix='ix',
        )
        expected = {
            'mysql': 'indexes_article_c1_c2_looooooooooooooooooo_255179b2ix',
            'oracle': 'indexes_a_c1_c2_loo_255179b2ix',
            'postgresql': 'indexes_article_c1_c2_loooooooooooooooooo_255179b2ix',
            'sqlite': 'indexes_article_c1_c2_l%sng_255179b2ix' % ('o' * 100),
        }
        if connection.vendor not in expected:
            self.skipTest('This test is only supported on the built-in database backends.')
        self.assertEqual(index_name, expected[connection.vendor]) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例9: setUp

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def setUp(self):
        self.is_sqlite = connection.vendor == 'sqlite'
        self.is_mysql = connection.vendor == 'mysql'
        self.is_postgresql = connection.vendor == 'postgresql'
        self.force_repoen_connection()

    # TODO: Remove this workaround when this issue is fixed:
    #       https://code.djangoproject.com/ticket/29494 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:10,代码来源:test_utils.py

示例10: tearDown

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def tearDown(self):
        if connection.vendor == 'postgresql':
            flush_sql_list = connection.ops.sql_flush(
                no_style(), (PostgresModel._meta.db_table,), ())
            with transaction.atomic():
                for sql in flush_sql_list:
                    with connection.cursor() as cursor:
                        cursor.execute(sql) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:10,代码来源:test_utils.py

示例11: force_repoen_connection

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def force_repoen_connection(self):
        if connection.vendor in ('mysql', 'postgresql'):
            # We need to reopen the connection or Django
            # will execute an extra SQL request below.
            connection.cursor() 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:7,代码来源:test_utils.py

示例12: can_migrate

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def can_migrate(self, connection):
        """
        Return True if the model can/should be migrated on the `connection`.
        `connection` can be either a real connection or a connection alias.
        """
        if self.proxy or self.swapped or not self.managed:
            return False
        if isinstance(connection, str):
            connection = connections[connection]
        if self.required_db_vendor:
            return self.required_db_vendor == connection.vendor
        if self.required_db_features:
            return all(getattr(connection.features, feat, False)
                       for feat in self.required_db_features)
        return True 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:options.py

示例13: as_sql

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def as_sql(self, compiler, connection):
        """
        Responsible for returning a (sql, [params]) tuple to be included
        in the current query.

        Different backends can provide their own implementation, by
        providing an `as_{vendor}` method and patching the Expression:

        ```
        def override_as_sql(self, compiler, connection):
            # custom logic
            return super().as_sql(compiler, connection)
        setattr(Expression, 'as_' + connection.vendor, override_as_sql)
        ```

        Arguments:
         * compiler: the query compiler responsible for generating the query.
           Must have a compile method, returning a (sql, [params]) tuple.
           Calling compiler(value) will return a quoted `value`.

         * connection: the database connection used for the current query.

        Return: (sql, params)
          Where `sql` is a string containing ordered sql parameters to be
          replaced with the elements of the list `params`.
        """
        raise NotImplementedError("Subclasses must implement as_sql()") 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:29,代码来源:expressions.py

示例14: create_db_comments_from_models

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def create_db_comments_from_models(models):
    """Populate comments for model tables"""

    if connection.vendor != 'postgresql':
        return

    with connection.cursor() as cursor:
        for model_class in models:
            table = model_class.db_table_name() \
                if hasattr(model_class, 'db_table_name') else None
            table_comment = model_class.db_table_comment_or_name() \
                if hasattr(model_class, 'db_table_comment_or_name') else None
            column_comments = model_class.db_column_comments() \
                if hasattr(model_class, 'db_column_comments') else None

            if table_comment is not None:
                try:
                    cursor.execute(
                        'comment on table "{}" is %s'.format(table), [table_comment]
                    )
                except ProgrammingError as e:
                    print('{} -- {}'.format(_exception_message, e))

            if column_comments is not None:
                for column, comment in column_comments.items():
                    try:
                        if comment is not None:
                            cursor.execute(
                                'comment on column "{}"."{}" is %s'.format(table, column), [comment]
                            )
                    except ProgrammingError as e:
                        print('{} -- {}'.format(_exception_message, e)) 
开发者ID:bcgov,项目名称:tfrs,代码行数:34,代码来源:db_actions.py

示例15: rename_table_sequences

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import vendor [as 别名]
def rename_table_sequences(_apps, schema_editor):
    """
    Renames the table sequences so they match what the name of the actual
    tables are
    """
    if connection.vendor == 'postgresql':
        schema_editor.execute(
            'ALTER SEQUENCE carbon_intensity_determination_type_id_seq '
            'RENAME TO determination_type_id_seq;'
        )

        schema_editor.execute(
            'ALTER SEQUENCE approved_fuel_provision_id_seq '
            'RENAME TO carbon_intensity_fuel_determination_id_seq;'
        )

        schema_editor.execute(
            'ALTER SEQUENCE approved_fuel_id_seq '
            'RENAME TO approved_fuel_type_id_seq;'
        )

        schema_editor.execute(
            'ALTER SEQUENCE fuel_transport_mode_id_seq '
            'RENAME TO fuel_transport_mode_type_id_seq;'
        )

        schema_editor.execute(
            'ALTER SEQUENCE fuel_provisions_id_seq '
            'RENAME TO provision_act_id_seq;'
        ) 
开发者ID:bcgov,项目名称:tfrs,代码行数:32,代码来源:0151_rename_table_sequences.py


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