Skip to content
Snippets Groups Projects
Select Git revision
  • 3a97d95f9d70f89b90740883f7aca86cfa2f25b2
  • master default protected
  • 1.2.4
  • 1.2.3
  • 1.2.2
  • 1.2.1
  • 1.2.0
  • v1.1.0
8 results

files.go

Blame
  • json-map.go 620 B
    // Copyright 2023 schukai GmbH
    // SPDX-License-Identifier: AGPL-3.0
    
    package jobqueue
    
    import (
    	"database/sql/driver"
    	"encoding/json"
    	"errors"
    )
    
    type JSONMap map[string]interface{}
    
    func (m *JSONMap) Scan(value interface{}) error {
    	bytes, ok := value.([]byte)
    	if !ok {
    		return errors.New("Scan source is not []byte")
    	}
    
    	if err := json.Unmarshal(bytes, m); err != nil {
    		return err
    	}
    	return nil
    }
    
    func (m JSONMap) Value() (driver.Value, error) {
    	if m == nil {
    		// Return NULL if the map is nil
    		return nil, nil
    	}
    
    	bytes, err := json.Marshal(m)
    	if err != nil {
    		return nil, err
    	}
    	return bytes, nil
    }