Skip to content

Commit c8adf69

Browse files
committed
docs: fix typo & update oracledb
1 parent 9e79acc commit c8adf69

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/topics/deduplicate.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,35 @@ PostgreSQL 场景下的 asyncio 的数据库链接操作示例:
268268
Oracle
269269
------
270270

271-
PostgreSQL 场景下的的数据库链接操作示例,这里只提供了普通场景:
271+
Oracle 场景下的 asyncio 的数据库链接操作示例:
272+
273+
.. code-block:: python
274+
275+
from ayugespidertools.utils.database import OracleAsyncPortal
276+
277+
278+
def test_example():
279+
conn = OraclePortal(db_conf=oracle_conf).connect()
280+
cursor = conn.cursor()
281+
cursor.execute("SELECT 42;")
282+
conn.close()
283+
284+
285+
async def test_example():
286+
_sql = 'SELECT * from "_article_info_list"'
287+
pool = OracleAsyncPortal(db_conf=oracle_conf).connect()
288+
async with pool.acquire() as conn:
289+
with conn.cursor() as cursor:
290+
await cursor.execute(_sql)
291+
exists = await cursor.fetchone()
292+
await conn.close()
293+
294+
# 但是更推荐直接使用 conn 操作即可,更简洁,可自行挑选喜欢的方式
295+
async with pool.acquire() as conn:
296+
exists = await connection.fetchone(_sql)
297+
await conn.close()
298+
299+
当然,也可以使用普通的方式来查询:
272300

273301
.. code-block:: python
274302

0 commit comments

Comments
 (0)