From 38bb01e1dc0107b7acecfad94df50d27a239eb71 Mon Sep 17 00:00:00 2001 From: Nelson-He Date: Fri, 24 Jun 2022 17:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgs=5Fdump=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=BC=82=E5=B8=B8=EF=BC=8C=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/client/client.go | 30 ++++++++++++++---------------- pkg/client/dump.go | 25 ++++++++++++++++++++----- pkg/client/result.go | 1 + pkg/command/version.go | 2 +- static/index.html | 6 +++++- static/js/app.js | 25 ++++++++++++++++++------- 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index b4b5b10..7ab53cb 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -381,6 +381,7 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) Rows: []Row{ Row{affected}, }, + Action: action, } return &result, nil @@ -404,10 +405,19 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) if cols == nil { cols = []string{} } - - result := Result{ - Columns: cols, - Rows: []Row{}, + var result Result + if action == "select" { + result = Result{ + Columns: cols, + Rows: []Row{}, + Action: "select", + } + } else { + result = Result{ + Columns: cols, + Rows: []Row{}, + Action: "dcl", + } } for rows.Next() { @@ -431,18 +441,6 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) } result.PostProcess() - - if len(result.Rows) == 0 { - result := Result{ - Columns: []string{"Rows Returned"}, - Rows: []Row{ - Row{0}, - }, - } - - return &result, nil - } - return &result, nil } diff --git a/pkg/client/dump.go b/pkg/client/dump.go index 34093b1..f309c4f 100644 --- a/pkg/client/dump.go +++ b/pkg/client/dump.go @@ -2,10 +2,12 @@ package client import ( "bytes" + "errors" "fmt" "io" "net/url" "os/exec" + "regexp" "strings" ) @@ -33,12 +35,17 @@ func (d *Dump) Export(connstr string, writer io.Writer) error { connstr = str } + username, password, err := parse_user_info(connstr) + if err != nil { + return err + } + errOutput := bytes.NewBuffer(nil) opts := []string{ - "openGauss", // the database of which the table belongs - "-U", "openGauss", // the username gs_dump used to connect - "-W", "openGauss2022", // the password. CAUSION: password is set in initdb.sql + "openGauss", // the database of which the table belongs + "-U", username, // the username gs_dump used to connect + "-W", password, // the password. CAUSION: password is set in initdb.sql "--no-owner", "--clean", // clean (drop) database objects before recreating } @@ -47,8 +54,6 @@ func (d *Dump) Export(connstr string, writer io.Writer) error { opts = append(opts, []string{"--table", d.Table}...) } - opts = append(opts, connstr) - cmd := exec.Command("gs_dump", opts...) cmd.Stdout = writer cmd.Stderr = errOutput @@ -59,6 +64,16 @@ func (d *Dump) Export(connstr string, writer io.Writer) error { return nil } +func parse_user_info(input string) (string, string, error) { + reg := regexp.MustCompile(`(\w+)://(\w+):(\w+)`) + match := reg.FindStringSubmatch(input) + if len(match) < 4 { + return "", "", errors.New("can not parse user name and password") + } + + return match[2], match[3], nil +} + // removeUnsupportedOptions removes any options unsupported for making a db dump func removeUnsupportedOptions(input string) (string, error) { uri, err := url.Parse(input) diff --git a/pkg/client/result.go b/pkg/client/result.go index 5f78c72..26aace6 100644 --- a/pkg/client/result.go +++ b/pkg/client/result.go @@ -25,6 +25,7 @@ type Result struct { Pagination *Pagination `json:"pagination,omitempty"` Columns []string `json:"columns"` Rows []Row `json:"rows"` + Action string `json:"action"` } type Objects struct { diff --git a/pkg/command/version.go b/pkg/command/version.go index 34a1a70..832ee17 100644 --- a/pkg/command/version.go +++ b/pkg/command/version.go @@ -2,7 +2,7 @@ package command const ( // Version is the current openGauss-webclient application version - Version = "0.8.0" + Version = "0.9.0" ) var ( diff --git a/static/index.html b/static/index.html index ec77e88..7447bbc 100644 --- a/static/index.html +++ b/static/index.html @@ -32,7 +32,11 @@
  • 操作历史
  • 会话
  • - +