build get set null value
This commit is contained in:
parent
d6ac97d15b
commit
244a7b9e2a
2
go.mod
2
go.mod
|
@ -7,7 +7,9 @@ require (
|
||||||
github.com/Selly-Modules/logger v0.0.2-0.20220824032830-595811dd1f20
|
github.com/Selly-Modules/logger v0.0.2-0.20220824032830-595811dd1f20
|
||||||
github.com/golang-migrate/migrate/v4 v4.15.2
|
github.com/golang-migrate/migrate/v4 v4.15.2
|
||||||
github.com/jackc/pgx/v4 v4.17.0
|
github.com/jackc/pgx/v4 v4.17.0
|
||||||
|
github.com/volatiletech/null/v8 v8.1.2
|
||||||
github.com/volatiletech/sqlboiler/v4 v4.12.0
|
github.com/volatiletech/sqlboiler/v4 v4.12.0
|
||||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
|
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
|
||||||
|
golang.org/x/text v0.3.7
|
||||||
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
|
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1147,7 +1147,9 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1
|
||||||
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
|
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
|
||||||
github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU=
|
github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU=
|
||||||
github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA=
|
github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA=
|
||||||
|
github.com/volatiletech/null/v8 v8.1.2 h1:kiTiX1PpwvuugKwfvUNX/SU/5A2KGZMXfGD0DUHdKEI=
|
||||||
github.com/volatiletech/null/v8 v8.1.2/go.mod h1:98DbwNoKEpRrYtGjWFctievIfm4n4MxG0A6EBUcoS5g=
|
github.com/volatiletech/null/v8 v8.1.2/go.mod h1:98DbwNoKEpRrYtGjWFctievIfm4n4MxG0A6EBUcoS5g=
|
||||||
|
github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5sbWC4nMk=
|
||||||
github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY=
|
github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY=
|
||||||
github.com/volatiletech/sqlboiler/v4 v4.12.0 h1:Z8QWf6HlwsYW9/ZNYq+ALksQ/OLH3ccOOZUDHJv9nF8=
|
github.com/volatiletech/sqlboiler/v4 v4.12.0 h1:Z8QWf6HlwsYW9/ZNYq+ALksQ/OLH3ccOOZUDHJv9nF8=
|
||||||
github.com/volatiletech/sqlboiler/v4 v4.12.0/go.mod h1:AAaQj77uX6nyU+Q5q6OcVCFFEs/gs+qsthM18/NVemo=
|
github.com/volatiletech/sqlboiler/v4 v4.12.0/go.mod h1:AAaQj77uX6nyU+Q5q6OcVCFFEs/gs+qsthM18/NVemo=
|
||||||
|
|
10
null.go
10
null.go
|
@ -1,10 +0,0 @@
|
||||||
package postgresql
|
|
||||||
|
|
||||||
import "github.com/volatiletech/null/v8"
|
|
||||||
|
|
||||||
func NewValidNullString(val string) null.String {
|
|
||||||
return null.String{
|
|
||||||
String: val,
|
|
||||||
Valid: true,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package null
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/volatiletech/null/v8"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetString(val null.String) string {
|
||||||
|
if !val.Valid {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return val.String
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetInt(val null.Int) int {
|
||||||
|
if !val.Valid {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return val.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetBool(val null.Bool) bool {
|
||||||
|
if !val.Valid {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return val.Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTime(val null.Time) (res time.Time) {
|
||||||
|
if !val.Valid {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return val.Time
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package null
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/volatiletech/null/v8"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetString(val string) null.String {
|
||||||
|
return null.String{
|
||||||
|
String: val,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetInt(val int) null.Int {
|
||||||
|
return null.Int{
|
||||||
|
Int: val,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetBool(val bool) null.Bool {
|
||||||
|
return null.Bool{
|
||||||
|
Bool: val,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetTime(val time.Time) null.Time {
|
||||||
|
return null.Time{
|
||||||
|
Time: val,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue