v0.0.355 sq.Json
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m27s

This commit is contained in:
Mike Schwörer 2024-01-05 10:25:05 +01:00
parent 1497c013f9
commit 2a0471fb3d
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
4 changed files with 38 additions and 2 deletions

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.354" const GoextVersion = "0.0.355"
const GoextVersionTimestamp = "2024-01-05T07:21:43+0100" const GoextVersionTimestamp = "2024-01-05T10:25:05+0100"

View File

@ -1,6 +1,7 @@
package sq package sq
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
@ -76,6 +77,34 @@ var ConverterRFC339NanoTimeToString = NewDBTypeConverter[rfctime.RFC3339NanoTime
return rfctime.NewRFC3339Nano(t), nil return rfctime.NewRFC3339Nano(t), nil
}) })
var ConverterJsonObjToString = NewDBTypeConverter[JsonObj, string](func(v JsonObj) (string, error) {
mrsh, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(mrsh), nil
}, func(v string) (JsonObj, error) {
var mrsh JsonObj
if err := json.Unmarshal([]byte(v), &mrsh); err != nil {
return JsonObj{}, err
}
return mrsh, nil
})
var ConverterJsonArrToString = NewDBTypeConverter[JsonArr, string](func(v JsonArr) (string, error) {
mrsh, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(mrsh), nil
}, func(v string) (JsonArr, error) {
var mrsh JsonArr
if err := json.Unmarshal([]byte(v), &mrsh); err != nil {
return JsonArr{}, err
}
return mrsh, nil
})
type dbTypeConverterImpl[TModelData any, TDBData any] struct { type dbTypeConverterImpl[TModelData any, TDBData any] struct {
dbTypeString string dbTypeString string
modelTypeString string modelTypeString string

View File

@ -148,4 +148,6 @@ func (db *database) RegisterDefaultConverter() {
db.RegisterConverter(ConverterRFCUnixTimeToUnixSeconds) db.RegisterConverter(ConverterRFCUnixTimeToUnixSeconds)
db.RegisterConverter(ConverterRFC339TimeToString) db.RegisterConverter(ConverterRFC339TimeToString)
db.RegisterConverter(ConverterRFC339NanoTimeToString) db.RegisterConverter(ConverterRFC339NanoTimeToString)
db.RegisterConverter(ConverterJsonObjToString)
db.RegisterConverter(ConverterJsonArrToString)
} }

5
sq/json.go Normal file
View File

@ -0,0 +1,5 @@
package sq
type JsonObj map[string]any
type JsonArr []any