I'm trying to insert 800 changesets using a multirow INSERT query with Ecto. I'm using postgres. I see that postgrex supports this now. Is it possible yet with Ecto?
I'm also open to doing this via prepared statement if that's possible.
8.4) Changesets allow filtering, casting, validation and definition of constraints when manipulating structs. There is an example of working with changesets in the introductory documentation in the Ecto module. The functions cast/4 and change/2 are the usual entry points for creating changesets.
An Ecto schema maps external data into Elixir structs. The definition of the schema is possible through two main APIs: schema/2 and embedded_schema/1 . schema/2 is typically used to map data from a persisted source, usually a database table, into Elixir structs and vice-versa.
Unlike ActiveRecord, Ecto is not an ORM, but a library that enables the use of Elixir to write queries and interact with the database. Ecto is a domain specific language for writing queries and interacting with databases in Elixir.
Ecto 2.0 will support Repo.insert_all/3
(current latest version is 2.0.0-rc.4 which supports this), but it doesn't support inserting changesets, only raw Maps or Keyword lists, so you'll have to filter all valid changesets and extract the fields from them yourself like you would have needed to if you used the Postgrex bulk insert feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With