Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Feature request: typed query artifacts for SQL files

未关闭
#509 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
20/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
冷清
技术栈
python, sql
领域
tooling

调研方向

先阅读 SQLFileLoader、ParameterDeclaration、SQLGlot 的解析接口以及可用的数据字典元数据。在实现之前,定义一个聚焦的工件范围,并解决所列出的输出、推断、注释和放置问题;完成意味着形成一个已达成共识且可测试的设计,而不是一份宽泛的愿望清单。

由索引模型根据 Issue 内容生成。

描述

Summary

Follow-up feature request for brainstorming typed artifacts generated from SQL files. This is a wishlist / design exploration item, not committed implementation scope for PR #497.

Background

PR #497 adds -- param: metadata, runtime validation, optional named parameters, and declared type resolution. The next possible step is generating type-checker and IDE-friendly artifacts from the SQL file loader metadata plus query shape.

Wishlist / Brainstorming Topics

  • Generate typed query artifacts from existing SQLSpec surfaces, especially SQLFileLoader, ParameterDeclaration, SQLGlot parsing, and data dictionary metadata where available.
  • Factor in query shape, not just declared params: selected columns, aliases, expressions, select *, joins, casts, functions, and scalar/count-style queries.
  • Generate parameter artifacts such as TypedDict classes, keyword-only accessor signatures, and shared type aliases for JSON/UUID/Decimal/date/time values.
  • Generate result artifacts in one or more forms:
    • msgspec.Struct
    • Pydantic BaseModel
    • TypedDict
    • potentially dataclass/attrs if there is demand
  • Generate typed runtime accessors, not only .pyi stubs. .pyi may still be useful when runtime code stays dynamic, but should not be assumed to be the only output.
  • Centralize import generation so emitted files include only the imports actually needed by generated parameter/result types.
  • Use explicit SQL annotations as an escape hatch for ambiguous or non-portable query shapes, for example expression result types, JSON paths, driver-specific functions, duplicate column names, and unresolved select * projections.
  • Keep runtime validation separate from generated typing. Generated code should improve IDE/type-checker ergonomics without duplicating the runtime validation contract.

Possible Artifact Shape

A generator might emit files similar to:

generated/
  params.py      # param TypedDicts and aliases
  models.py      # result models, e.g. msgspec/Pydantic/TypedDict
  queries.py     # typed runtime accessors / optional typed execution helpers
  queries.pyi    # optional, if needed for dynamic runtime wrappers
  __init__.py

Open Design Questions

  • Which output families should be supported first: TypedDict, msgspec, Pydantic, or configurable combinations?
  • Should typed execution helpers call driver methods directly, or should generation stop at typed (SQL, params) accessors?
  • How should cardinality be declared or inferred: many, one, one-or-none, scalar, execute?
  • What annotation syntax should be used for result hints when SQL/data dictionary inference is insufficient?
  • How much should this rely on live database data dictionary introspection versus offline SQL-only inference?
  • Where should generated files live, and should the generator be CLI-based, Python API-based, or both?

Non-goals to consider

  • Do not build a separate SQL parser when existing SQLFileLoader / SQLGlot / data dictionary surfaces can be reused.
  • Do not duplicate execute-time runtime validation.
  • Do not infer full ORM-like schema models or relationships.
主要语言
Python
星标
105
派生
9
平均合并
1 天 11 小时
30 天内合并 PR
30

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。