ecto-patterns

仓库创建 2026年2月12日最近提交 5 小时前SkillHot 收录 20 天前
▸ 精选理由

作为编码与审查时的权威模板集合,减少重复错误。

这个 Skill 做什么

Ecto 常见模式与最佳实践参考(schemas、changesets、查询、迁移等)。

把 Ecto 常见模式和最佳实践集中起来,覆盖 schemas、changesets、查询、迁移、Multi、关联与 preload 等场景。在改 Repo 调用、写 Ecto.Query 或调整 schema 字段时参考,能帮你避开常见坑(比如不要用 :float 存钱、changeset 用于外部数据等)。特点是把经验性的“铁律”与示例放在一起,便于查阅和遵循。

▸ 展开 SKILL.md 英文原文

Ecto patterns — schemas, changesets, queries, migrations, Multi, associations, preloads, upserts. Use when editing Repo calls, Ecto.Query, or schema fields. Skip for Ash.

开发编程Ecto模式数据库Claude Code
505
Stars
34
Forks
40
仓库内 Skill
+35
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/oliver-kriska/claude-elixir-phoenix/main/plugins/elixir-phoenix/skills/ecto-patterns/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/oliver-kriska/claude-elixir-phoenix/main/plugins/elixir-phoenix/skills/ecto-patterns/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# Ecto Patterns Reference

Reference for working with Ecto schemas, queries, and migrations.

## Iron Laws — Never Violate These

1. **CHANGESETS ARE FOR EXTERNAL DATA** — Use `cast/4` for user/API input, `change/2` or `put_change/3` for internal trusted data
2. **NEVER USE `:float` FOR MONEY** — Always use `:decimal` or `:integer` (cents)
3. **NO RAILS-STYLE POLYMORPHIC ASSOCIATIONS** — They break foreign key constraints; use multiple nullable FKs or separate join tables
4. **ALWAYS PIN VALUES IN QUERIES** — `u.name == ^user_input` is safe, string interpolation causes SQL injection
5. **PRELOAD COLLECTIONS, NOT INDIVIDUALS** — Preloading in loops = N+1 queries
6. **CONSTRAINTS BEAT VALIDATI
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有