wallyfoo

wallyfoo

Ecto and postgres triggers -- Any resources for how to pull this off?

Long story short, I have a real world need to create a view for hooking up a shipping terminal to live data, but because of some early architecture decisions, using a view isn’t practical in this case. (The shipping software doesn’t do joins, only single table access, hence a view.)

I populated a lookup table with the data the shipping software needs, but if a customer changes their shipping information on their account, an update trigger to also update the associated lookup table seems smart. I have a solution that updates the data, but I would like the database to deal with itself rather than bolting logic onto the application.

Understanding that this isn’t a terribly common problem to solve, I’m not finding a lot of resources on how to deal with triggers with Ecto. The Little Ecto Cookbook, for instance, doesn’t seem to reference this sort of thing.

Anyone know of a good place to start with triggers and Ecto?

Most Liked

LostKobrakai

LostKobrakai

Besides migrations basically nothing of ecto cares or need to care about triggers. As for migrations there’s no ecto specific API for triggers so your only option is to use execute/2 to run raw sql. Given that context it makes sense that there’s not much documentation, as there’s actually nothing ecto specific to document in the first place. Take whatever resource you can find about the sql side of things and you should be able to put the sql into a migration to execute.

wallyfoo

wallyfoo

I should have been more clear in my explanation. I was looking at it from the migration end, so execute/2 to define the trigger is likely the way to go. This is precisely what I was looking for. Thanks!

Where Next?

Popular in Chat/Questions Top

nur
https://e.planaria.network/stack.png https://e.planaria.network Build a NoSQL DB, Build a Relational SQL Database, Build a Graph Datab...
New
zeroexcuses
Besides Basic types - The Elixir programming language are there any other well recommended “elixir by example” style resources / books ? ...
New
New
loganhelms
A while back, I read a great book by Luis Atencio titled, Functional Programming in JavaScript. In section 7.3, he discusses memoization ...
New
woohaaha
I’m coming from Ruby and Rails. I have read some Elixir and Phoenix books. They shed a lot of light about building applications in Elixir...
New
boddhisattva
Greetings everyone, At my current workplace we're evaluating different ways of building a microservices architecture for some parts rel...
New
Santheepkumar
Hi all, I am a Fullstack JS developer for last 2 years. I need a good guide to learn elixer. Any suggestions please
New
Fl4m3Ph03n1x
GenStage and Flow resources? I have been hearing about GenStage and Flow, a tool built upon it, for quite some time. I understand it allo...
New
Nopp
Hey guys and girls, i am completely “new” to programming, recently played a bit with Python, Ruby and PureBasic, but i want to try somet...
New
logesh
Could someone provide a learning path for functional programming for who came from oops background.? Thanks in advance
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement