Cleaned up Application - Inserts every Itteration
This commit is contained in:
parent
d4d892f6f2
commit
b270a45ece
26
main.go
26
main.go
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
@ -15,23 +16,32 @@ func main() {
|
||||
|
||||
jsonString, _ := os.ReadFile("./waypoints.json")
|
||||
data := []Waypoint{}
|
||||
x := json.Unmarshal(jsonString, &data)
|
||||
|
||||
fmt.Println(string(jsonString), x)
|
||||
json.Unmarshal(jsonString, &data)
|
||||
|
||||
//Open a connection to the database
|
||||
db, err := sql.Open("mysql", "root:@tcp(:3306)/EFB")
|
||||
db, err := sql.Open("mysql", "root:XXXX@tcp(XXX.XXX.XXX.XXX:3306)/EFB")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer db.Close()
|
||||
//Make a Query to the database
|
||||
insert, err := db.Query("INSERT INTO waypoints (name, type, frequency, longitude, latitude) VALUES ('WILLO', 'NDB', 12000, 'test', 'test')")
|
||||
|
||||
currentTime := time.Now()
|
||||
|
||||
//Make a Query to the database for each item
|
||||
for _, waypoint := range data {
|
||||
insert, err := db.Query("INSERT INTO waypoints (name, type, latitude, longitude) VALUES (?, ?, ?, ?)",
|
||||
waypoint.Name,
|
||||
waypoint.NavType,
|
||||
waypoint.Coords[0],
|
||||
waypoint.Coords[1],
|
||||
)
|
||||
|
||||
//Close the connection
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if insert != nil {
|
||||
fmt.Println("Success")
|
||||
insert.Close()
|
||||
}
|
||||
|
||||
fmt.Println("Total Execution Time:", time.Since(currentTime))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user