Skip to content

Commit

Permalink
add sql.Scanner and sql.Value impl for uri
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Sep 5, 2024
1 parent d12aeaa commit 5bdb96a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/uri/uri.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package uri

import (
"database/sql/driver"
"encoding/json"
"errors"
"fmt"

"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp"
Expand Down Expand Up @@ -134,3 +136,19 @@ func (u *Uri) UnmarshalJSON(b []byte) error {
*u, err = Parse(str)
return err
}

// Value implements driver.Valuer.
func (u *Uri) Value() (driver.Value, error) {
return u.String(), nil
}

// Scan implements sql.Scanner.
func (u *Uri) Scan(src any) error {
if str, ok := src.(string); ok {
var err error
*u, err = Parse(str)
return err
}

return fmt.Errorf("cannot scan %T into %T", src, u)
}

0 comments on commit 5bdb96a

Please sign in to comment.