-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (48 loc) · 1.42 KB
/
main.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
package main
import (
ui "benchmarkDB/ui"
"context"
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"database/sql"
_ "github.com/go-sql-driver/mysql"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
fmt.Println("************************************************")
// Connection to MySql
sqldb, err := sql.Open("mysql", "MYMYSQL_USERNAME:SQL_PASS@tcp(localhost:3306)/MYSQL_DATABASE")
if err != nil {
fmt.Println("Error connecting to database:", err)
return
}
err = sqldb.Ping()
if err != nil {
fmt.Println("Error pinging database:", err)
return
}
fmt.Println("Connected to MySQL database!")
// connection to MongoDB
const uri = "mongodb://localhost:27017/MONGODB_DATABASE"
serverAPI := options.ServerAPI(options.ServerAPIVersion1)
opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI)
client, err := mongo.Connect(context.TODO(), opts)
if err != nil {
panic(err)
}
var result bson.M
if err := client.Database("admin").RunCommand(context.TODO(), bson.D{{"ping", 1}}).Decode(&result); err != nil {
panic(err)
}
fmt.Println("Pinged the server. Successfully connected to MongoDB!")
fmt.Println("************************************************")
p := tea.NewProgram(ui.InitialModel())
if _, err := p.Run(); err != nil {
fmt.Printf("Error occured: %v", err)
os.Exit(1)
}
defer sqldb.Close()
}