2022-01-18 12:24:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-01-23 23:26:46 +00:00
|
|
|
"time"
|
2022-01-23 15:23:37 +00:00
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
2022-01-18 12:24:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
//Marshall JSON into Objects
|
|
|
|
|
|
|
|
jsonString, _ := os.ReadFile("./waypoints.json")
|
|
|
|
data := []Waypoint{}
|
2022-01-23 23:26:46 +00:00
|
|
|
json.Unmarshal(jsonString, &data)
|
2022-01-18 12:24:30 +00:00
|
|
|
|
|
|
|
//Open a connection to the database
|
2022-01-23 23:26:46 +00:00
|
|
|
db, err := sql.Open("mysql", "root:XXXX@tcp(XXX.XXX.XXX.XXX:3306)/EFB")
|
2022-01-18 12:24:30 +00:00
|
|
|
if err != nil {
|
2022-01-23 15:23:37 +00:00
|
|
|
fmt.Println(err)
|
2022-01-18 12:24:30 +00:00
|
|
|
}
|
2022-01-23 15:23:37 +00:00
|
|
|
defer db.Close()
|
2022-01-23 23:26:46 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
insert.Close()
|
2022-01-23 16:43:48 +00:00
|
|
|
}
|
2022-01-23 23:26:46 +00:00
|
|
|
|
|
|
|
fmt.Println("Total Execution Time:", time.Since(currentTime))
|
2022-01-18 12:24:30 +00:00
|
|
|
}
|