File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,35 @@ PostgreSQL 场景下的 asyncio 的数据库链接操作示例:
268
268
Oracle
269
269
------
270
270
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
+ 当然,也可以使用普通的方式来查询:
272
300
273
301
.. code-block :: python
274
302
You can’t perform that action at this time.
0 commit comments