一键导入
pgh-px
Guidelines for using `github.com/n-r-w/pgh/v2/px` package.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guidelines for using `github.com/n-r-w/pgh/v2/px` package.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | pgh-px |
| description | Guidelines for using `github.com/n-r-w/pgh/v2/px` package. |
| metadata | {"author":"Roman Nikulenkov"} |
<query_helper_selection>
1. Use Squirrel helpers when the query is built with github.com/n-r-w/squirrel:
1) px.Exec for write queries.
2) px.Select for many rows scanned into *[]T.
3) px.SelectOne for one row scanned into *T.
4) px.SelectFunc for row-by-row processing.
2. Use plain SQL helpers when SQL text is already built:
1) px.ExecPlain for write queries.
2) px.SelectPlain for many rows scanned into *[]T.
3) px.SelectOnePlain for one row scanned into *T.
4) px.SelectFuncPlain for row-by-row processing.
3. Use pgh.Builder() for new Squirrel queries passed to px helpers. It configures dollar placeholders.
4. Pass query parameters as pgh.Args when calling plain helpers.
5. Do not pass a slice destination to SelectOne or SelectOnePlain; pass a pointer to one value.
6. Treat pgx.ErrNoRows from SelectOne and SelectOnePlain as a normal not-found signal when the caller expects optional data.
</query_helper_selection>
<batch_and_split_helpers>
1. Use px.ExecBatch for multiple Squirrel write queries.
2. Use px.SelectBatch for multiple Squirrel select queries whose rows should be appended into one destination slice.
3. Use px.ExecSplit or px.ExecSplitPlain when a list of independent queries must be executed in groups.
4. For px.ExecSplitPlain, queries and args must have the same length. args[i] belongs to queries[i].
5. Use px.InsertSplit when inserting many rows with a Squirrel InsertBuilder and no returned rows are needed.
6. Use px.InsertSplitQuery when inserting many rows with a Squirrel InsertBuilder and RETURNING rows must be scanned.
7. Use px.InsertSplitPlain only when SQL matches its argument shape. It queues each group as one argument, values[idx:idxTo], not expanded row placeholders.
8. Use px.InsertValuesPlain when SQL has the form INSERT INTO table (col1, col2) without VALUES; the helper appends VALUES and placeholders.
9. splitSize must be greater than zero for split helpers. Validate or choose it before calling the helper.
10. Empty batches are no-ops in SendBatch and SendBatchQuery.
11. Keep row value lengths consistent for InsertValuesPlain; mixed lengths return an error.
</batch_and_split_helpers>
<direct_data_access>
Use github.com/georgysavva/scany/v2/pgxscan when code must work directly with query results instead of using px.Select, px.SelectOne, px.SelectPlain, or px.SelectOnePlain.
</direct_data_access>
<error_handling>
1. Use px.IsNoRows to check not-found errors from pgx.ErrNoRows or PostgreSQL NoDataFound.
2. Use px.IsUniqueViolation for PostgreSQL unique constraint violations.
3. Use px.IsForeignKeyViolation for PostgreSQL foreign key constraint violations.
4. Use github.com/jackc/pgerrcode directly when code needs PostgreSQL error classes or codes not wrapped by px.
5. Preserve wrapped SQL errors with %w when adding context, so these helpers and errors.Is or errors.As keep working.
</error_handling>