upleveled / next-js-example-spring-2022-atvie

Home Page:https://next-js-example-spring-2022.fly.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Postgres.js internal transform options

Eprince-hub opened this issue · comments

Postgres.js provides a way to normalize database data from snake_case to camelCase, and also convert any undefined values to null

docs here: https://github.com/porsager/postgres#data-transformation

  • We should delete camelcase-keys and use Postgres.js internal camelcase options
  • Use undefined: null to set all incoming undefined values to null instead (which is a big source of confusion for students, see porsager/postgres#380 )

Code example

    globalThis.postgresSqlClient = postgres({
      transform: {
        ...postgres.toCamel,
        undefined: null,
      },
    });

Sounds like a good idea! Let's do it for the next example.