Add support for configuring the JSON unmarshal function used when querying SELECT_JSON statements.

This commit is contained in:
go-jet 2025-03-11 13:33:39 +01:00
parent 7ab44bc61c
commit 1db6b12074
6 changed files with 74 additions and 3 deletions

View file

@ -3,6 +3,7 @@ package postgres
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"github.com/go-jet/jet/v2/qrm"
"github.com/go-jet/jet/v2/stmtcache"
@ -108,6 +109,16 @@ func allowUnusedColumns(f func()) {
f()
}
func useJsonUnmarshalFunc(unmarshalJson func(data []byte, v any) error, f func()) {
defer func() {
qrm.GlobalConfig.JsonUnmarshalFunc = json.Unmarshal
}()
qrm.GlobalConfig.JsonUnmarshalFunc = unmarshalJson
f()
}
var loggedSQL string
var loggedSQLArgs []interface{}
var loggedDebugSQL string