Skip to content

v0.6.0 — luima runs on bun, and resolver errors are redacted

Latest

Choose a tag to compare

@ulas96 ulas96 released this 16 Sep 15:27

luima now runs on bun v1.2.18 with pgdriver, where every release through v0.5.0 ran on go-pg v10. luima's signatures named go-pg's types, so this release breaks the public API. The break is kept to what the switch forces: every function keeps its name, its parameters' meaning and its absence contract, and server/ is unchanged.

It also closes a gap that was open in every earlier release: luimaerr.PresentError did not redact what resolvers report.

Upgrading

The compiler finds most of the migration, and the changelog maps each break in one line:

  • *pg.DB → *bun.DB, and orm.DB → bun.IDB in the five CRUD helpers.
  • One option-closure type per statement (*bun.SelectQuery for Get/List, *bun.InsertQuery, *bun.UpdateQuery, *bun.DeleteQuery) in place of func(*orm.Query) *orm.Query.
  • pg:"…" tags → bun:"…", pg.ErrNoRows → sql.ErrNoRows, HealthCheck: db.Ping → db.PingContext.
  • ConnectWith's tune func and StatementTimeout now take a *pgdriver.Config.

Two changes compile and then misbehave. Read both before deploying against a table that already holds rows:

  • The table name comes only from an embedded bun.BaseModel. bun silently skips go-pg's tableName struct{} field. A model that keeps it still compiles, and every query then goes to the pluralized type name: users, not app_users.
  • A zero-valued field is stored as its zero value. go-pg sent DEFAULT or NULL; bun sends '', 0, FALSE or the zero time. This affects DEFAULT now() columns, identity and generated columns, and nil ,array slices. docs/gotchas.md #27 lists the tag each one needs (,nullzero, ,autoincrement, ,scanonly).

Runtime differences worth knowing:

  • A cancelled context no longer stops the query on the server. pgdriver sends no CancelRequest, so StatementTimeout is the only bound Postgres enforces.
  • pgdriver's socket timeouts cap every statement: 10s read, 5s write. Keep statement_timeout below both.
  • Unknown DSN parameters become SET statements on each connection. A misspelled one fails at connect time instead of while parsing.
  • db.Connect refuses a DSN whose credentials an unescaped /, ? or # cuts short. Percent-encode / ? # % in the user and password.

Security

  • PresentError now redacts resolver errors. gqlgen wraps a resolver's error in a *gqlerror.Error before the presenter sees it, and luima passed that wrapper through. Raw driver text, such as a constraint name or relation … does not exist, reached clients with no extensions.code. Now any error that is neither a *luimaerr.CustomError nor one of gqlgen's own errors about the request is logged. The client gets internal server error with INTERNAL_SERVER_ERROR. To send a message to a client, return a *luimaerr.CustomError.
  • DisableIntrospection refuses the whole operation before any field runs. The client gets INTROSPECTION_DISABLED, and no log line is written.
  • db.Connect errors no longer quote part of the password. In every earlier release, an unescaped /, ? or # in the password could leak its opening characters into the parse error.

Fixed

  • A negative StatementTimeout now disables the bound, as documented. It used to make every new connection fail.

See the changelog for the details behind every line here, and docs/gotchas.md #38–#40 for the new failure modes.

⌂ 换网址