Skip to content

Type the tenant hook and drop sonic for encoding/json - #9

Merged
emoss08 merged 1 commit into
masterfrom
typed-tenant-stdlib-json
Nov 25, 2026
Merged

emoss08 merged 1 commit into
masterfrom
typed-tenant-stdlib-json

Conversation

@emoss08

@emoss08 emoss08 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What changes

  • Config.Tenant returns []string instead of []any. Tenant columns hold text keys, and keel already read the values back as strings (scan.go), so the type now says what keel accepts. Applications build their keel config without any.
  • The default JSON codec is the standard library's encoding/json, not sonic. Since Go 1.27, encoding/json runs on the encoding/json/v2 engine with v1's behavior, so the bytes written (HTML escaped, map keys sorted) and the decoding rules are the ones the default always promised. jsonnumber columns decode with a Decoder using UseNumber, which rejects trailing data as Unmarshal does.

Why

keel no longer depends on sonic. Measured on Go 1.27.4:

encode 1 KB doc decode 1 KB doc cold build packages
sonic (ConfigStd) 2.0 us 4.4 us 5.0 s 176
encoding/json 4.9 us 9.0 us 3.2 s 75

Every module that imports keel compiles about 100 fewer packages and 1.8 s less from cold. The per-value cost is a few microseconds against a database round trip of hundreds. Config.JSON still takes any codec, so a path that needs sonic's speed can set it.

Breaking changes

  • A Tenant hook returns []string: return []any{org, bu}, true becomes return []string{string(org), string(bu)}, true.
  • A json or jsonb value now encodes with encoding/json. The output is byte-identical to the old default (sonic's encoding/json-compatible mode); set Config.JSON to keep sonic.

keel's minimum Go stays 1.26: the new default works there too, and Go 1.27 only makes it faster.

Checks

gofmt, go vet (root and bench), keel gen -check, go test -race ./... against Postgres 18, and every benchmark once.

Generated with Claude Code

Config.Tenant returned []any, but tenant columns hold text keys and keel
already read the values back as strings. It now returns []string, so the
call site says what keel accepts and applications build their keel config
without any.

The default JSON codec is the standard library's encoding/json instead of
sonic. Since Go 1.27 encoding/json runs on the encoding/json/v2 engine with
v1's behavior, so the bytes written and the decoding rules are the ones the
default always promised. keel no longer depends on sonic, which removes about
100 packages and 1.8 s from a cold build of anything that imports keel. sonic
encodes a 1 KB document in 2.0 us against 4.9 us and decodes it in 4.4 us
against 9.0 us; Config.JSON still takes any codec for a path that needs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emoss08
emoss08 force-pushed the typed-tenant-stdlib-json branch from d0da0f3 to f633628 Compare November 25, 2026 16:08
@emoss08
emoss08 merged commit 5b14dcc into master Nov 25, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant