From 244a7b9e2af272fb403305d040d7cb13c0247ed0 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 4 Oct 2022 11:19:25 +0700 Subject: [PATCH] build get set null value --- go.mod | 2 ++ go.sum | 2 ++ null.go | 10 ---------- null/get.go | 34 ++++++++++++++++++++++++++++++++++ null/set.go | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 10 deletions(-) delete mode 100644 null.go create mode 100644 null/get.go create mode 100644 null/set.go diff --git a/go.mod b/go.mod index af751e1..061095b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,9 @@ require ( github.com/Selly-Modules/logger v0.0.2-0.20220824032830-595811dd1f20 github.com/golang-migrate/migrate/v4 v4.15.2 github.com/jackc/pgx/v4 v4.17.0 + github.com/volatiletech/null/v8 v8.1.2 github.com/volatiletech/sqlboiler/v4 v4.12.0 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 ) diff --git a/go.sum b/go.sum index 2b81dba..9d9d0bd 100644 --- a/go.sum +++ b/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/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU= 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/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5sbWC4nMk= 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/go.mod h1:AAaQj77uX6nyU+Q5q6OcVCFFEs/gs+qsthM18/NVemo= diff --git a/null.go b/null.go deleted file mode 100644 index 322d396..0000000 --- a/null.go +++ /dev/null @@ -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, - } -} diff --git a/null/get.go b/null/get.go new file mode 100644 index 0000000..9419dcf --- /dev/null +++ b/null/get.go @@ -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 +} diff --git a/null/set.go b/null/set.go new file mode 100644 index 0000000..242acc2 --- /dev/null +++ b/null/set.go @@ -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, + } +} -- 2.34.1