25 lines
379 B
Go
25 lines
379 B
Go
package orm
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type Slice[T any] struct {
|
|
Arr []T
|
|
}
|
|
|
|
func (s Slice[T]) Value() (driver.Value, error) {
|
|
return json.Marshal(s)
|
|
}
|
|
|
|
func (s *Slice[T]) Scan(value any) error {
|
|
switch value := value.(type) {
|
|
case []byte:
|
|
return json.Unmarshal(value, s)
|
|
default:
|
|
return fmt.Errorf("不支持的类型: %T", value)
|
|
}
|
|
}
|