-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.go
64 lines (50 loc) · 1.29 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"fmt"
_ "embed"
"github.com/tidwall/gjson"
)
//go:embed wails.json
var wailsJSON string
// App struct
type App struct {
ctx context.Context
}
type QueryResult struct {
Result []map[string]interface{} `json:"result" ts_type:"{[key: string]: string}[]"`
Columns []string `json:"columns"`
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// Get app version from wails.json file
func (a *App) GetAppVersion() string {
version := gjson.Get(wailsJSON, "info.productVersion")
return version.String()
}
// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
}
func (a *App) MssqlQuery(server string, user string, password string, database string, query string) (*QueryResult, error) {
db, err := getDBConnection(server, user, password, database)
if err != nil {
return nil, err
}
result, columns, err := execQuery(db, query)
if err != nil {
return nil, err
}
println("query executed!")
return &QueryResult{
Result: result,
Columns: columns,
}, nil
}