helicon

helicon

Hello!
For example i have an schema Photo.

{
  "filename": "photo123.jpg",
  "content_type": "image/jpeg",
  "versions": {
     "original": {...},
     "thumbnail": {...}
     "facebook_version": {...}, 
     # ...
     # and some more versions
     # ...
  }
}

And there is a list of versions that should be present, but some other versions are optional.

After i took a look at this video - https://www.youtube.com/watch?v=sPmHP9ZPOWc, i see 2 cases to define data structure:

  1. Schema-less data (Map → JSON → Map)

    • Set versions field to :map type in Ecto and that will be interpreted as JSONB in Postgres;
    • Implement nested versions data validations on Photo changeset level.
  2. Embedded schema (Schema → JSON → schema)

    • define embedded Versions schema with full list of versions
    • all data validations functions are invoking at Versions changeset level

Objective
I am developing API application. And there is what i need from my data structure:

  • secure and trusted data saving
  • Convenient and understandable structure for querying and sending to frontend client

The second way looks more secure. But embedded schema it’s not dynamic data. I don’t want to store empty version fields in my DB, if some optional versions are absent(actually I do not know if this is a good idea). As i understood, the dynamic fields can’t be in Ecto embedded schema. Am i wrong?

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

williamthome
Hi all o/ I’d like to introduce Roadrunner, an HTTP server written in Erlang and built for low tail latency under sustained load. It ser...
New
dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews