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


Python extensions.AsIs方法代码示例

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


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

示例1: drop_db

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def drop_db(hostname="localhost", username=None, password=None, dbname=None, port=None):
    """
    Drop database.
    :param hostname: string
    :param username: string
    :param password: string
    :param dbname: string
    """
    cn = create_cn(hostname, password, username, "postgres", port)

    # ISOLATION_LEVEL_AUTOCOMMIT = 0
    # Needed for DB drop.
    cn.set_isolation_level(0)

    with cn.cursor() as cr:
        cr.execute("drop database if exists %s", (AsIs(dbname),))

    close_cn(cn) 
开发者ID:dbcli,项目名称:pgcli,代码行数:20,代码来源:db_utils.py

示例2: update_schema

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def update_schema(self):
        if self.owner != self.old_owner:
            log.info("alter schema %s owner to %s", self.old_schema, self.owner)
            with self.connection.cursor() as cursor:
                cursor.execute(
                    "ALTER SCHEMA %s OWNER TO %s",
                    [AsIs(self.old_schema), AsIs(self.owner)],
                )

        if self.schema != self.old_schema:
            log.info("alter schema %s rename to %s", self.old_schema, self.schema)
            with self.connection.cursor() as cursor:
                cursor.execute(
                    "ALTER SCHEMA %s RENAME TO %s",
                    [AsIs(self.old_schema), AsIs(self.schema)],
                ) 
开发者ID:binxio,项目名称:cfn-postgresql-user-provider,代码行数:18,代码来源:postgresql_schema_provider.py

示例3: pg_users

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def pg_users():
    uid = str(uuid.uuid4()).replace("-", "")
    name = f'user_{uid}'
    name2 = f'user2_{uid}'
    r = Request('Create', name, name)
    with r.db_connection() as connection:
        with connection.cursor() as cursor:
            for n in [name, name2]:
                cursor.execute(
                    "CREATE ROLE %s LOGIN ENCRYPTED PASSWORD %s", [AsIs(n), n]
                )
        connection.commit()

        yield (name, name2)

        with connection.cursor() as cursor:
            #cursor.execute("DROP OWNED BY %s CASCADE", [AsIs(name)])
            for n in [name, name2]:
                cursor.execute("DROP ROLE %s", [AsIs(n)])
            connection.commit() 
开发者ID:binxio,项目名称:cfn-postgresql-user-provider,代码行数:22,代码来源:test_postgresql_schema_provider.py

示例4: register_numpy_types

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def register_numpy_types():
    # Credit: https://github.com/musically-ut/psycopg2_numpy_ext
    """Register the AsIs adapter for following types from numpy:
      - numpy.int8
      - numpy.int16
      - numpy.int32
      - numpy.int64
      - numpy.float16
      - numpy.float32
      - numpy.float64
      - numpy.float128
    """
    for typ in ['int8', 'int16', 'int32', 'int64',
                'float16', 'float32', 'float64', 'float128',
                'bool_']:
        register_adapter(np.__getattribute__(typ), AsIs) 
开发者ID:MattKleinsmith,项目名称:pbt,代码行数:18,代码来源:utils.py

示例5: test_run

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def test_run(self):
        SqlStep(self.database, ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 1),
                ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 2),
                ("INSERT INTO {0} VALUES ('3')".format(TABLE_NAME))).run()

        self.database.open()
        self.database.execute(
            "SELECT COUNT(*) FROM %s",
            (AsIs(TABLE_NAME),))
        count = int(self.database.cursor.fetchone()[0])

        self.assertEqual(3, count)

        self.database.execute(
            "SELECT * FROM %s",
            (AsIs(TABLE_NAME),))
        values = list(self.database.cursor.fetchall())

        self.assertEqual([('1',), ('2',), ('3',)], values) 
开发者ID:Dwolla,项目名称:arbalest,代码行数:21,代码来源:test_sql_step.py

示例6: test_execute

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def test_execute(self):
        self.database.open()
        sql = SqlStep(self.database)
        sql.execute(("INSERT INTO %s VALUES('%s')", TABLE_NAME, 1))
        sql.execute(("INSERT INTO %s VALUES('%s')", TABLE_NAME, 2))
        sql.execute(("INSERT INTO {0} VALUES ('3')".format(TABLE_NAME)))
        self.database.commit()

        self.database.open()
        self.database.execute(
            "SELECT COUNT(*) FROM %s",
            (AsIs(TABLE_NAME),))
        count = int(self.database.cursor.fetchone()[0])

        self.assertEqual(3, count)

        self.database.execute(
            "SELECT * FROM %s",
            (AsIs(TABLE_NAME),))
        values = list(self.database.cursor.fetchall())

        self.assertEqual([('1',), ('2',), ('3',)], values) 
开发者ID:Dwolla,项目名称:arbalest,代码行数:24,代码来源:test_sql_step.py

示例7: test_insert_update

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def test_insert_update(self):
        table = TargetTable(self.schema, self.database)
        table.create()
        table.stage_update()
        self.database.execute("INSERT INTO %s VALUES('%s')",
                              (AsIs(TABLE_NAME), AsIs(1),))
        self.database.execute("INSERT INTO %s VALUES('%s')",
                              (AsIs(self.schema.update_table), AsIs(2),))
        self.database.execute("INSERT INTO %s VALUES('%s')",
                              (AsIs(self.schema.update_table), AsIs(3),))

        table.insert_update()

        self.database.execute(
            "SELECT * FROM %s",
            (AsIs(TABLE_NAME),))
        values = list(self.database.cursor.fetchall())

        self.assertEqual([('1',), ('2',), ('3',)], values) 
开发者ID:Dwolla,项目名称:arbalest,代码行数:21,代码来源:test_target_table.py

示例8: _get_channels_by_user_ids

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def _get_channels_by_user_ids(user_ids):
    # TODO: use database.query instead of raw SQL
    with db.conn() as conn:
        cur = conn.execute('''
            SELECT name
            FROM %(schema_name)s.user_channel
            WHERE _owner_id in %(user_ids)s
            LIMIT %(len)s;
            ''', {
            'schema_name': AsIs(_get_schema_name()),
            'user_ids': tuple(user_ids),
            'len': len(user_ids),
        }
        )

        results = []
        for row in cur:
            results.append(row[0])

        return results 
开发者ID:SkygearIO,项目名称:chat,代码行数:22,代码来源:utils.py

示例9: getReceiptList

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def getReceiptList(self):
        """
        Returns a list of message receipt statuses.
        """
        receipts = list()
        with db.conn() as conn:
            cur = conn.execute('''
                SELECT receipt.user, read_at, delivered_at
                FROM %(schema_name)s.receipt
                WHERE
                    "message" = %(message_id)s AND
                    (read_at IS NOT NULL or delivered_at is NOT NULL)
                ''', {
                    'schema_name': AsIs(_get_schema_name()),
                    'message_id': self.id.key
                }
            )

            for row in cur:
                receipts.append({
                    'user': row['user'],
                    'read_at': to_rfc3339_or_none(row['read_at']),
                    'delivered_at': to_rfc3339_or_none(row['delivered_at'])
                })
        return receipts 
开发者ID:SkygearIO,项目名称:chat,代码行数:27,代码来源:message.py

示例10: _get_new_last_message_id

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def _get_new_last_message_id(conn, message):
    # TODO rewrite with database.query
    cur = conn.execute('''
            SELECT _id FROM %(schema_name)s.message
            WHERE
                deleted = false AND
                seq < %(seq)s AND
                conversation = %(conversation_id)s
            ORDER BY seq DESC LIMIT 1
        ''', {
            'schema_name': AsIs(_get_schema_name()),
            'seq': message['seq'],
            'conversation_id': message['conversation'].recordID.key
        })
    row = cur.fetchone()
    return None if row is None else row['_id'] 
开发者ID:SkygearIO,项目名称:chat,代码行数:18,代码来源:message_handlers.py

示例11: total_unread

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def total_unread(user_id=None):
    if user_id is None:
        user_id = current_user_id()
    with db.conn() as conn:
        cur = conn.execute('''
            SELECT COUNT(*), SUM("unread_count")
            FROM %(schema_name)s.user_conversation
            WHERE
                "unread_count" > 0 AND
                "user" = %(user_id)s
            ''', {
                'schema_name': AsIs(_get_schema_name()),
                'user_id': user_id
            }
        )
        r = cur.first()
        conversation_count = r[0]
        message_count = r[1]
    return {
        'conversation': conversation_count,
        'message': message_count
    } 
开发者ID:SkygearIO,项目名称:chat,代码行数:24,代码来源:user_conversation.py

示例12: create_db

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def create_db(hostname='localhost', username=None, password=None, dbname=None, port=None):
    """Create test database.

    :param hostname: string
    :param username: string
    :param password: string
    :param dbname: string
    :param port: int
    :return:

    """
    cn = create_cn(hostname, password, username, 'postgres', port)

    # ISOLATION_LEVEL_AUTOCOMMIT = 0
    # Needed for DB creation.
    cn.set_isolation_level(0)

    with cn.cursor() as cr:
        cr.execute('drop database if exists %s', (AsIs(dbname),))
        cr.execute('create database %s', (AsIs(dbname),))

    cn.close()

    cn = create_cn(hostname, password, username, dbname, port)
    return cn 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:27,代码来源:db_utils.py

示例13: drop_db

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def drop_db(hostname='localhost', username=None, password=None,
            dbname=None, port=None):
    """
    Drop database.
    :param hostname: string
    :param username: string
    :param password: string
    :param dbname: string
    """
    cn = create_cn(hostname, password, username, 'postgres', port)

    # ISOLATION_LEVEL_AUTOCOMMIT = 0
    # Needed for DB drop.
    cn.set_isolation_level(0)

    with cn.cursor() as cr:
        cr.execute('drop database if exists %s', (AsIs(dbname),))

    close_cn(cn) 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:21,代码来源:db_utils.py

示例14: create_db

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def create_db(
    hostname="localhost", username=None, password=None, dbname=None, port=None
):
    """Create test database.

    :param hostname: string
    :param username: string
    :param password: string
    :param dbname: string
    :param port: int
    :return:

    """
    cn = create_cn(hostname, password, username, "postgres", port)

    # ISOLATION_LEVEL_AUTOCOMMIT = 0
    # Needed for DB creation.
    cn.set_isolation_level(0)

    with cn.cursor() as cr:
        cr.execute("drop database if exists %s", (AsIs(dbname),))
        cr.execute("create database %s", (AsIs(dbname),))

    cn.close()

    cn = create_cn(hostname, password, username, dbname, port)
    return cn 
开发者ID:dbcli,项目名称:pgcli,代码行数:29,代码来源:db_utils.py

示例15: adapt_array

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import AsIs [as 别名]
def adapt_array(arr):
    conn = arr.field.model_class._meta.database.get_conn()
    items = adapt(arr.items)
    items.prepare(conn)
    return AsIs('%s::%s%s' % (
        items,
        arr.field.get_column_type(),
        '[]' * arr.field.dimensions)) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:10,代码来源:postgres_ext.py


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