TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Quickgres.js, 430 LoC pipelined PostgreSQL client library

6 pointsby kigabout 3 years ago

1 comment

kigabout 3 years ago
Hi! This is a fun little library I wrote a few years back to make a minimal PostgreSQL client. It&#x27;s around 400 lines of commented code ( <a href="https:&#x2F;&#x2F;github.com&#x2F;kig&#x2F;quickgres&#x2F;blob&#x2F;master&#x2F;index.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kig&#x2F;quickgres&#x2F;blob&#x2F;master&#x2F;index.js</a> ), so a good hobby project if you want to roll your own.<p>Performance is quite good too since it&#x27;s pipelined, stays close to the raw network buffers, tries to get away with minimal syscalls and defaults to prepared statements. It doesn&#x27;t do typecasting - you give it strings or buffers, it gives you back strings or buffers. This is to stay close to the raw buffers and keep you cognizant of the toString&#x2F;parse overheads. (And it&#x27;s 400 LoC, type casting would bloat it to 500 LoC.) But have a look at <a href="https:&#x2F;&#x2F;github.com&#x2F;kig&#x2F;quickgres&#x2F;blob&#x2F;master&#x2F;quickgres-frontend.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kig&#x2F;quickgres&#x2F;blob&#x2F;master&#x2F;quickgres-front...</a> for a TypeParser that turns PostgreSQL protocol values to JS objects.<p>A special feature of quickgres is streaming out raw PostgreSQL protocol. So instead of the usual &quot;protocol buffer -&gt; parse to JS object -&gt; stringify to JSON -&gt; write to response socket -&gt; parse JSON&quot;-process of sending DB responses to HTTP clients, you can do &quot;protocol buffer -&gt; write to response socket -&gt; parse protocol&quot; and save a bunch of CPU on the web server. The protocol streamed in this way is sanitized (possible non-response segments are not included in the streamed buffer), so it shouldn&#x27;t be a security hole as long as your DB query is not retrieving columns it shouldn&#x27;t pass to the client.<p>Anyway, if you need something tiny for talking to Postgres, have a look. It was fun to write, hope it&#x27;s fun to read.