MCPcopy Create free account
hub / github.com/apecloud/myduckserver / parseRestoreSQL

Function parseRestoreSQL

pgserver/restore_handler.go:46–87  ·  view source on GitHub ↗
(sql string)

Source from the content-addressed store, hash-verified

44}
45
46func parseRestoreSQL(sql string) (*RestoreConfig, error) {
47 matches := restoreRegex.FindStringSubmatch(sql)
48 if matches == nil {
49 // No match means the SQL doesn't follow the expected pattern
50 return nil, nil
51 }
52
53 // matches:
54 // [1] DbName
55 // [2] RemoteUri
56 // [3] Endpoint
57 // [4] AccessKeyId
58 // [5] SecretAccessKey
59 dbName := strings.TrimSpace(matches[1])
60 remoteUri := strings.TrimSpace(matches[2])
61 endpoint := strings.TrimSpace(matches[3])
62 accessKeyId := strings.TrimSpace(matches[4])
63 secretAccessKey := strings.TrimSpace(matches[5])
64
65 if dbName == "" {
66 return nil, fmt.Errorf("missing required restore configuration: DATABASE")
67 }
68 if remoteUri == "" {
69 return nil, fmt.Errorf("missing required restore configuration: TO '<URI>'")
70 }
71 if endpoint == "" {
72 return nil, fmt.Errorf("missing required restore configuration: ENDPOINT")
73 }
74 if accessKeyId == "" {
75 return nil, fmt.Errorf("missing required restore configuration: ACCESS_KEY_ID")
76 }
77 if secretAccessKey == "" {
78 return nil, fmt.Errorf("missing required restore configuration: SECRET_ACCESS_KEY")
79 }
80
81 storageConfig, remotePath, err := storage.ConstructStorageConfig(remoteUri, endpoint, accessKeyId, secretAccessKey)
82 if err != nil {
83 return nil, fmt.Errorf("failed to construct storage configuration for restore: %w", err)
84 }
85
86 return NewRestoreConfig(dbName, remotePath, storageConfig), nil
87}
88
89func (h *ConnectionHandler) executeRestore(restoreConfig *RestoreConfig) (string, error) {
90 provider := h.server.Provider

Callers 1

convertQueryMethod · 0.85

Calls 2

ConstructStorageConfigFunction · 0.92
NewRestoreConfigFunction · 0.85

Tested by

no test coverage detected