Hi! This is a fun little library I wrote a few years back to make a minimal PostgreSQL client. It's around 400 lines of commented code
( <a href="https://github.com/kig/quickgres/blob/master/index.js" rel="nofollow">https://github.com/kig/quickgres/blob/master/index.js</a> ), so a good hobby project if you want to roll your own.<p>Performance is quite good too since it's pipelined, stays close to the raw network buffers, tries to get away with minimal syscalls and defaults to prepared statements. It doesn'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/parse overheads. (And it's 400 LoC, type casting would bloat it to 500 LoC.) But have a look at <a href="https://github.com/kig/quickgres/blob/master/quickgres-frontend.js" rel="nofollow">https://github.com/kig/quickgres/blob/master/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 "protocol buffer -> parse to JS object -> stringify to JSON -> write to response socket -> parse JSON"-process of sending DB responses to HTTP clients, you can do "protocol buffer -> write to response socket -> parse protocol" 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't be a security hole as long as your DB query is not retrieving columns it shouldn'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's fun to read.