I have two different database servers, one is a mysql database server and the other is postgresql database server , both have a table called users so I have to insert from the users postgresql table to the users mysql table and check if there is already something inserted (if not exist), how can I do one Database query with postgresql and mysql in the same time
//MYSQL CONNECTION
var err1 error
db, err1 = sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/dbusers?parseTime=true")
if err1 != nil {
log.Fatal(err1)
}
//POSTGRESQL CONNECTION
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+"password=%s dbname=%s sslmode=disable", HOST, PORT, USER, PASSWORD, DBNAME)
db1, err2 = sql.Open("postgres", psqlInfo)
if err2 != nil {
log.Fatal(err2)
}
//Here is what i have tried
func GetUsersApiPostgres(c *gin.Context) {
var p Users
Users, err := p.GetUsers() //GetUsers will return all fields in users table
if err != nil {
log.Fatalln(err)
}
c.JSON(http.StatusOK, gin.H{
"Users": Users,
})
}
func AddUsersApiMysql(c *gin.Context) {
firstName := c.Request.FormValue("firstname")
lastName := c.Request.FormValue("lastname")
p := Users{FirstName: firstName, LastName: lastName}
ra, err := p.AddUsers()//AddUsers will insert fields defined in users table
if err != nil {
log.Fatalln(err)
}
msg := fmt.Sprintf("insert successful %d", ra)
c.JSON(http.StatusOK, gin.H{
"msg": msg,
})
}
func (u *Users) GetMysqlUsersFromPostgresql{
}
I don't know how to use both function (Add & Get) in the last function