-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependencies on services package in common (#11321)
* Removed dependencies on services package in common * Marked json data type as deprecated and cleaned up test vars * Replaced json data type with alias
- Loading branch information
1 parent
4c6d0fe
commit aca537d
Showing
18 changed files
with
49 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,9 @@ | ||
package datatypes | ||
|
||
import ( | ||
"database/sql/driver" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil" | ||
) | ||
|
||
// JSON defined JSON data type, need to implements driver.Valuer, sql.Scanner interface | ||
type JSON json.RawMessage | ||
|
||
// Value return json value, implement driver.Valuer interface | ||
func (j JSON) Value() (driver.Value, error) { | ||
if len(j) == 0 { | ||
return nil, nil | ||
} | ||
bytes, err := json.RawMessage(j).MarshalJSON() | ||
return string(bytes), err | ||
} | ||
|
||
// Scan scan value into Jsonb, implements sql.Scanner interface | ||
func (j *JSON) Scan(value interface{}) error { | ||
if value == nil { | ||
*j = JSON("null") | ||
return nil | ||
} | ||
var bytes []byte | ||
switch v := value.(type) { | ||
case []byte: | ||
bytes = v | ||
case string: | ||
bytes = []byte(v) | ||
default: | ||
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value)) | ||
} | ||
|
||
result := json.RawMessage{} | ||
err := json.Unmarshal(bytes, &result) | ||
*j = JSON(result) | ||
return err | ||
} | ||
|
||
// MarshalJSON to output non base64 encoded []byte | ||
func (j JSON) MarshalJSON() ([]byte, error) { | ||
return json.RawMessage(j).MarshalJSON() | ||
} | ||
|
||
// UnmarshalJSON to deserialize []byte | ||
func (j *JSON) UnmarshalJSON(b []byte) error { | ||
result := json.RawMessage{} | ||
err := result.UnmarshalJSON(b) | ||
*j = JSON(result) | ||
return err | ||
} | ||
|
||
func (j JSON) String() string { | ||
return string(j) | ||
} | ||
// Deprecated: Use sqlutil.JSON instead | ||
type JSON = sqlutil.JSON |
Oops, something went wrong.