29 lines
531 B
Go
29 lines
531 B
Go
package database
|
|
|
|
import "encoding/json"
|
|
|
|
// marshalJSON marshals a value to JSON, returning "{}" or "[]" on failure.
|
|
func marshalJSON(v any) string {
|
|
data, err := json.Marshal(v)
|
|
if err != nil {
|
|
return "null"
|
|
}
|
|
return string(data)
|
|
}
|
|
|
|
// boolToInt converts a bool to 1/0 for SQLite.
|
|
func boolToInt(b bool) int {
|
|
if b {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// jsonUnmarshal safely unmarshals JSON, tolerating empty/invalid input.
|
|
func jsonUnmarshal(data string, v any) {
|
|
if data == "" {
|
|
return
|
|
}
|
|
json.Unmarshal([]byte(data), v)
|
|
}
|