Elixir Ecto Best Practices for Data Insertion

150
clicks
Elixir Ecto Best Practices for Data Insertion

Source: reddit.com

Type: Discussion

The author ForgettablePersona is working on learning how to effectively parse and insert OpenSky Network data into a database using Elixir's Ecto. They have successfully written code to map the JSON data to their Ecto schema but are not satisfied with the readability and efficiency of their solution. Using transactions for each record insertion instead of `insert_all` for batch processing seems to be suboptimal. Additionally, there is a duplication issue, since each field is repeated multiple times within the schema definition and associated functions. A suggestion from commenter ProfessionalPlant330 indicates using `apply_changes` to transform a changeset into a struct, which could then be used with `insert_all`, potentially helping with the first issue.

© HashMerge 2024