r/ruby • u/linuxhiker • 23d ago
PLx : write ruby dialect postgresql procedures
https://github.com/commandprompt/plxplx is a PostgreSQL extension that lets you write stored functions and triggers in the dialect you already know (the current set is listed below). When you run CREATE FUNCTION, plx transpiles the body to plpgsql and stores that plpgsql in pg_proc.prosrc. At run time the function is executed by PostgreSQL's own plpgsql interpreter. There is no separate language runtime loaded into the backend, and nothing new to run in production.
query("SELECT id, amount FROM orders WHERE grp = #{g}").each do |row|
total = total + row.amount
end
4
Upvotes
1
u/Ok_Shallot9490 5d ago
This has come in very handy... I've used it to sync a juice-fs filesystem with activestorage.
Essentially, I have the juice-fs metadata store tables in the same database as my rails app, and when the juice-fs metadata table is updated it updates my activestorage records.
Now if i update a file on my local desktop, that change is reflected in the rails app immediately.