#Postgres DB notification listener

1 messages · Page 1 of 1 (latest)

blissful pewter
#

https://github.com/jmatth11/db_listener

I’ve created a simple prototype of a dev tooling idea to automatically setup listeners on all tables within a Postgres DB and listen for insert/update triggers to display those notifications on a front-end. Hopefully to help track live changes in your db when you’re testing.

I’m still new to zig so would love some feedback on best practices and idiomatic zig designs that I might not be doing.
But mainly putting this here for other people to enjoy as well if they find it useful.

GitHub

experiment with listening to table updates in postgres - jmatth11/db_listener

blissful pewter
#

Postgres DB notification listener

tacit minnow
#

FixedBufferAllocator isn't thread safe.

You could wrap it in a std.heap.ThreadSafeAllocator, but this is the type of thing the res.arena of httpz.Response is designed to help you with.

It would let you avoid the explicit call to res.write() and the hard-coded use of std.heap.page_allocator

You can also get a micro perf boost by using res.content_type = .JSON; and res.content_type = .HTML; vs res.reader(...)

#

in db.zig, again, non thread-safe allocator usage.

errdefer self.alloc.free(md.columns.?); will crash if md.columns isn't null (which it can be if the alloc is what fails)

sanitize_name - that if statement should be reversed...negations are always harder to follow. And the name param should be a []const u8

viscid ruin
#

not sure if its the best option but fyi FBA actually has a threadSafeAllocator function thats lock free, ThreadSafeAllocator uses a mutex

#

though it loses the ability to free/resize the latest allocation, not sure how much that comes up