@@ -34,6 +34,7 @@ import (
3434type SQCloudConfig struct {
3535 Host string
3636 Port int
37+ ProjectID string // ProjectID to identify the user's node
3738 Username string
3839 Password string
3940 Database string
@@ -49,10 +50,11 @@ type SQCloudConfig struct {
4950 TlsInsecureSkipVerify bool // Accept invalid TLS certificates (no_verify_certificate)
5051 Pem string
5152 ApiKey string
52- NoBlob bool // flag to tell the server to not send BLOB columns
53- MaxData int // value to tell the server to not send columns with more than max_data bytes
54- MaxRows int // value to control rowset chunks based on the number of rows
55- MaxRowset int // value to control the maximum allowed size for a rowset
53+ Token string // Access Token for authentication
54+ NoBlob bool // flag to tell the server to not send BLOB columns
55+ MaxData int // value to tell the server to not send columns with more than max_data bytes
56+ MaxRows int // value to control rowset chunks based on the number of rows
57+ MaxRowset int // value to control the maximum allowed size for a rowset
5658}
5759
5860type SQCloud struct {
@@ -131,6 +133,7 @@ func ParseConnectionString(ConnectionString string) (config *SQCloudConfig, err
131133 config .MaxRows = 0
132134 config .MaxRowset = 0
133135 config .ApiKey = ""
136+ config .Token = ""
134137
135138 sPort := strings .TrimSpace (u .Port ())
136139 if len (sPort ) > 0 {
@@ -139,6 +142,12 @@ func ParseConnectionString(ConnectionString string) (config *SQCloudConfig, err
139142 }
140143 }
141144
145+ // eg: project ID "abvqqetyhq" in "abvqqetyhq.global3.ryujaz.sqlite.cloud"
146+ config .ProjectID = strings .Split (config .Host , "." )[0 ]
147+ if config .ProjectID == "" {
148+ return nil , fmt .Errorf ("invalid connection string: missing project ID in host" )
149+ }
150+
142151 for key , values := range u .Query () {
143152 lastLiteral := strings .TrimSpace (values [len (values )- 1 ])
144153 switch strings .ToLower (strings .TrimSpace (key )) {
@@ -195,6 +204,8 @@ func ParseConnectionString(ConnectionString string) (config *SQCloudConfig, err
195204 config .Secure , config .TlsInsecureSkipVerify , config .Pem = ParseTlsString (lastLiteral )
196205 case "apikey" :
197206 config .ApiKey = lastLiteral
207+ case "token" :
208+ config .Token = lastLiteral
198209 case "noblob" :
199210 if b , err := parseBool (lastLiteral , config .NoBlob ); err == nil {
200211 config .NoBlob = b
@@ -434,12 +445,14 @@ func connectionCommands(config SQCloudConfig) (string, []interface{}) {
434445 }
435446
436447 if config .ApiKey != "" {
437- c , a := authWithKeyCommand (config .ApiKey )
448+ c , a := authWithApiKeyCommand (config .ApiKey )
438449 buffer += c
439450 args = append (args , a ... )
440- }
441-
442- if config .Username != "" && config .Password != "" {
451+ } else if config .Token != "" {
452+ c , a := authWithTokenCommand (config .Token )
453+ buffer += c
454+ args = append (args , a ... )
455+ } else if config .Username != "" && config .Password != "" {
443456 c , a := authCommand (config .Username , config .Password , config .PasswordHashed )
444457 buffer += c
445458 args = append (args , a ... )
0 commit comments