@@ -6,7 +6,10 @@ package dbtest
6
6
7
7
import (
8
8
"context"
9
+ "database/sql/driver"
10
+ "errors"
9
11
"fmt"
12
+ "strings"
10
13
"time"
11
14
12
15
"github.com/google/uuid"
@@ -21,7 +24,7 @@ type PersonalAccessToken struct {
21
24
Hash string `gorm:"column:hash;type:varchar;size:255;" json:"hash"`
22
25
Name string `gorm:"column:name;type:varchar;size:255;" json:"name"`
23
26
Description string `gorm:"column:description;type:varchar;size:255;" json:"description"`
24
- Scopes [] string `gorm:"column:scopes;type:text;size:65535;" json:"scopes"`
27
+ Scopes Scopes `gorm:"column:scopes;type:text;size:65535;" json:"scopes"`
25
28
ExpirationTime time.Time `gorm:"column:expirationTime;type:timestamp;" json:"expirationTime"`
26
29
CreatedAt time.Time `gorm:"column:createdAt;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"createdAt"`
27
30
LastModified time.Time `gorm:"column:_lastModified;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"_lastModified"`
@@ -30,6 +33,8 @@ type PersonalAccessToken struct {
30
33
_ bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
31
34
}
32
35
36
+ type Scopes []string
37
+
33
38
// TableName sets the insert table name for this struct type
34
39
func (d * PersonalAccessToken ) TableName () string {
35
40
return "d_b_personal_access_token"
@@ -73,3 +78,18 @@ func CreateToken(ctx context.Context, conn *gorm.DB, req PersonalAccessToken) (P
73
78
74
79
return token , nil
75
80
}
81
+
82
+ func (s * Scopes ) Scan (src any ) error {
83
+ bytes , ok := src .([]byte )
84
+ if ! ok {
85
+ return errors .New ("src value cannot cast to []byte" )
86
+ }
87
+ * s = strings .Split (string (bytes ), "," )
88
+ return nil
89
+ }
90
+ func (s Scopes ) Value () (driver.Value , error ) {
91
+ if len (s ) == 0 {
92
+ return nil , nil
93
+ }
94
+ return strings .Join (s , "," ), nil
95
+ }
0 commit comments