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

pietrofxq
I’ve bought the following books: Programming Elixir 1.6 Programming Phoenix 1.4 Programming Ecto Functional Web Development with Elixir...
New
lc0815
hello from a real frustrated newbe… I’m reading this article Full-Stack React With Phoenix (Chapter 3 | Introduction to Phoenix) by mich...
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
KSingh1980
How to run the random query and get the result in JSON format and send it as a response. The query will be in the following form DB Name...
New
Nopp
Hello there, i have a lot to read and to learn, but are there some books, that are focussing on how i “should” plan the architecture of ...
New
shansiddiqui94
Hello, I have an interview coming up and I seem to have forgotten important concepts of Elixir. So I was wondering if you guys know of a...
New
phykos
In Ruby, which is very similar to Elixir I do this: def test yield end test do puts("sup there") end Here, the yield keyword will be...
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
Fl4m3Ph03n1x
Background I am trying to do the typical Ceaser cypher exercise in Elixir. The description of the exercise is as follows: Create an impl...
New
shansiddiqui94
Greetings Elixir Developers, My name is Daniel, and I am taking my first step to learn all about the Elixir language. Currently I have a...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement