Module exposing: Scan, Value
// Source: https://github.com/tbphp/gpt-load | License: MIT | Copyright 2025-2026 GPT-Load Contributors
// Provided via justclaw.it.com; keep this notice with the code.
package models
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// JSON is a validated JSON document stored in a database JSON column.
// A nil or empty value is persisted as SQL NULL.
type JSON []byte
// Scan implements sql.Scanner and always takes ownership of an independent
// copy of a valid database value.
func (j *JSON) Scan(value any) error {
if value == nil {
*j = nil
return nil
}
var raw []byte
switch typed := value.(type) {
case []byte:
raw = typed
case string:
raw = []byte(typed)
default:
return fmt.Errorf("scan JSON from unsupported type %T", value)
}
if !json.Valid(raw) {
retu
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key