v0.0.355 sq.Json
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m27s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m27s
This commit is contained in:
parent
1497c013f9
commit
2a0471fb3d
@ -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"
|
||||||
|
@ -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
|
||||||
|
@ -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
5
sq/json.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package sq
|
||||||
|
|
||||||
|
type JsonObj map[string]any
|
||||||
|
|
||||||
|
type JsonArr []any
|
Loading…
Reference in New Issue
Block a user