You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add fetch* method aliases to both sync and async driver base classes,
providing an alternative naming convention for users familiar with
asyncpg's API. Both select* (primary) and fetch* (alias) conventions
are fully supported with complete type safety.
Copy file name to clipboardExpand all lines: docs/usage/drivers_and_querying.rst
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -388,6 +388,52 @@ Execute a SELECT query returning a single scalar value.
388
388
:dedent: 4
389
389
:caption: `select_value`
390
390
391
+
asyncpg-Compatible Method Aliases (fetch*)
392
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
393
+
394
+
For users transitioning from asyncpg or preferring its naming convention, SQLSpec provides ``fetch*`` aliases for all ``select*`` methods. Both naming styles are fully supported and produce identical results.
395
+
396
+
.. list-table:: Method Aliases
397
+
:header-rows: 1
398
+
:widths: 40 60
399
+
400
+
* - Primary Method
401
+
- asyncpg-Compatible Alias
402
+
* - ``select()``
403
+
- ``fetch()``
404
+
* - ``select_one()``
405
+
- ``fetch_one()``
406
+
* - ``select_one_or_none()``
407
+
- ``fetch_one_or_none()``
408
+
* - ``select_value()``
409
+
- ``fetch_value()``
410
+
* - ``select_value_or_none()``
411
+
- ``fetch_value_or_none()``
412
+
* - ``select_to_arrow()``
413
+
- ``fetch_to_arrow()``
414
+
* - ``select_with_total()``
415
+
- ``fetch_with_total()``
416
+
417
+
**Example using fetch() instead of select():**
418
+
419
+
.. code-block:: python
420
+
421
+
# Both styles work identically
422
+
asyncwith spec.provide_session(config) as session:
423
+
# Primary naming (recommended in docs)
424
+
users =await session.select("SELECT * FROM users WHERE age > ?", 18)
425
+
426
+
# asyncpg-compatible naming (identical behavior)
427
+
users =await session.fetch("SELECT * FROM users WHERE age > ?", 18)
428
+
429
+
# fetch_one() is equivalent to select_one()
430
+
user =await session.fetch_one("SELECT * FROM users WHERE id = ?", 1)
431
+
432
+
# fetch_value() is equivalent to select_value()
433
+
count =await session.fetch_value("SELECT COUNT(*) FROM users")
434
+
435
+
**Note:** Both naming conventions are fully supported and will not be deprecated. Choose the style that feels most natural for your codebase. The SQLSpec documentation primarily uses ``select*`` methods, but ``fetch*`` aliases are equally valid.
0 commit comments