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