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