Doing weird things with Ecto
summary
Uses Ecto.Schema and Changeset to pre-validate and normalize complex API params, turning nested filter maps into typed structs so core functions get well-formed data and controllers return 422 JSON on errors. Speeds multi-step batch DB work by using Ecto.Multi with temp tables (create temp table, fill via queries, dedupe with window functions, insert_all into target) to avoid shipping large payloads through the app. Shows per-row updates by joining on an interpolated JSONB array, a maybe_join macro to add joins only once, and two approaches for polymorphic embeds (embedded changesets vs custom Ecto.Type) with structured errors.
AI-written summary · about
chapters (14)
- 0:00Intro
- 0:33Nikolas background
- 1:49Database use
- 2:19NonDatabase use
- 2:42Disclaimer
- 3:01Normalization
- 5:26Example
- 13:23Ecto Multi Example
- 18:45Batch Transpose
- 21:02Joins
- 23:06Query
- 24:24Polymorphic embed
- 30:37Custom Ecto type
- 34:42Final thoughts
related talks
37mLeveling Up With Ecto
41mEmbrace the Database With Ecto
35mElixir's Ecto: Functional Relational Data Access Done Right
39mEcto without SQL
41mEcto: A language integrated query for Elixir
26mMultitenant Web Applications with Phoenix
40mExploiting PostgreSQL's power with Elixir / Ecto applications
44mElixir and money
