Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

andrew222651/sqlafunccodegen

Open more actions menu

Repository files navigation

sqlafunccodegen

Generate type-annotated Python functions that wrap PostgreSQL functions, using asyncpg and, optionally, SQLAlchemy. Like sqlacodegen but for functions instead of tables.

Usage:

sqlafunccodegen --help
  • all modes:
    • many basic types
    • arrays
    • comments as docstrings
    • casts on inputs are added for convenience
  • "sqlalchemy" mode: functions behave like sqlalchemy.func.<function_name>
    • functions can be used inside SQLAlchemy query expressions
    • note: if a function call cannot return null, you can wrap the call with sqlalchemy.NotNullable and None will be removed as a possible Python type for the expression
  • "asyncpg_only" mode: functions execute a select statement and return results
  • not supported:
    • functions with overloads
    • polymorphic pseudo-types
    • IN, INOUT, and VARIADIC params
    • default values

Generated code dependencies:

  • asyncpg
  • Pydantic 2 (for "asyncpg_only" mode)
  • SQLAlchemy 2 (for "sqlalchemy" mode)

Examples

Releases

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.