Slonik: A PostgreSQL client with strict types, detailed logging, and assertions

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • slonik

    A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.

  • I like the idea and project goals, but the execution...

    https://github.com/gajus/slonik/blob/master/src/routines/exe...

    There may be an explanation for this horrifying code, but it should probably be right above in the form of:

         /*

  • node-sql-template-strings

    ES6 tagged template strings for prepared SQL statements 📋

  • Any pitfalls that you encountered?

    I'm trying to decide between this, or writing my own helpers around https://github.com/felixfbecker/node-sql-template-strings.

    Also, have you found anything the solves typechecking of embedded expressions inside the SQL template?

    For example, Webstorm will help you autocomplete your SQL, but you can still type:

       SELECT * FROM foo WHERE barInt = ${bazStr}

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • PostgreSQL

    PostgreSQL client for node.js.

  • Great to see this package here. We have been using slonik for over a year now with few regrets. I am not a fan of query builders. Query builders work for simple inserts or updates. For really complex queries, nothing beats writing SQL inside of the sql template tag.

    Another nice thing about slonik is that it is built on top of https://github.com/brianc/node-postgres. One gets all the benefit of node-pg with the nicer dev experience of slonik.

  • pg-extra

    Discontinued 🐘 some helpful extensions for node-postgres

  • The template tag solution is cute but really dangerous if you can accidentally leave off the `SQL` tag and the query still works.

    Here's a solution that goes the long route of wrapping node-postgres' classes to ensure that you can never accidentally pass a basic string into query(): https://github.com/danneu/pg-extra/blob/be0e1a9fd513296e9bed...

  • pgtyped

    pgTyped - Typesafe SQL in TypeScript

  • slonik has no knowledge of the pg schema, so it cannot help with this.

    You may want to look at something like https://github.com/adelsz/pgtyped. The downside is that dynamic queries are more challenging.

    We have been looking at moving over to pgtyped, but it will be a hard transition because we do a fair amount of building up queries at runtime.

  • TypeORM

    ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

  • Have to say I'm pretty happy with TypeORM[0], this is going to have to be really good to pry that from my hands.

    Slonik does have a wonderfully smaller API surface and I sure do like writing SQL manually and getting to take advantage of various lower level benefits (ex. postgres JSON operations) without too much fuss/work arounds, but TypeORM also lets you drop to raw (but parametrized) SQL fairly quickly, and it's query builder is actually pretty good...

    [0]: https://typeorm.io/

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts