updated structs in qrz
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing

This commit is contained in:
Paul 2020-04-07 23:04:12 +02:00
parent f87f436891
commit 6e1edf9e1c
2 changed files with 19 additions and 15 deletions

View File

@ -36,11 +36,11 @@ func (config *Config) GetConfig() error {
config.DbSchema = fmt.Sprintf("CREATE TABLE IF NOT EXISTS `%s` (`id` int(8) NOT NULL AUTO_INCREMENT, `qrz` varchar(25) NOT NULL, `name` varchar(25) DEFAULT NULL, `address` varchar(50) DEFAULT NULL, `city` varchar(50) DEFAULT NULL, `zipcode` varchar(5) DEFAULT NULL, `dept` varchar(50) DEFAULT NULL, `country` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `qrz` (`qrz`,`name`,`city`,`dept`) USING BTREE, KEY `test` (`country`), FULLTEXT KEY `city` (`city`), FULLTEXT KEY `dept` (`dept`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;", config.DbTable) config.DbSchema = fmt.Sprintf("CREATE TABLE IF NOT EXISTS `%s` (`id` int(8) NOT NULL AUTO_INCREMENT, `qrz` varchar(25) NOT NULL, `name` varchar(25) DEFAULT NULL, `address` varchar(50) DEFAULT NULL, `city` varchar(50) DEFAULT NULL, `zipcode` varchar(5) DEFAULT NULL, `dept` varchar(50) DEFAULT NULL, `country` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `qrz` (`qrz`,`name`,`city`,`dept`) USING BTREE, KEY `test` (`country`), FULLTEXT KEY `city` (`city`), FULLTEXT KEY `dept` (`dept`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;", config.DbTable)
config.DbInsertStatement = "INSERT IGNORE INTO %s (qrz,name,city,dept,country) VALUES ('%s','%s','%s','%s','%s');" config.Statements.DbInsert = "INSERT IGNORE INTO %s (qrz,name,city,dept,country) VALUES ('%s','%s','%s','%s','%s');"
config.DbGetQrzStatement = "SELECT qrz FROM %s;" config.Statements.DbGetQrz = "SELECT qrz FROM %s;"
config.DbCheckStatement = "SELECT COUNT(*) FROM %s WHERE qrz = '%s';" config.Statements.DbCheck = "SELECT COUNT(*) FROM %s WHERE qrz = '%s';"
return nil return nil
} }
@ -53,9 +53,11 @@ type Config struct {
DbPassword string DbPassword string
DbSchema string DbSchema string
DbTable string DbTable string
DbInsertStatement string Statements struct {
DbGetQrzStatement string DbInsert string
DbCheckStatement string DbGetQrz string
DbCheck string
}
FrsConfig struct { FrsConfig struct {
URL string URL string
XPath string XPath string

View File

@ -57,12 +57,13 @@ func GetFrsEntries(config config.Config, body string) (frsentries map[string]Frs
frsentries[frs.QRZ] = frs frsentries[frs.QRZ] = frs
} }
} }
return return
} }
// GetCurrentEntries fetch existing entries from database // GetCurrentEntries fetch existing entries from database
func GetCurrentEntries(config config.Config, db sqlx.DB) (existingQRZ []string, err error) { func GetCurrentEntries(config config.Config, db sqlx.DB) (existingQRZ []string, err error) {
q := fmt.Sprintf(config.DbGetQrzStatement, config.DbTable) q := fmt.Sprintf(config.Statements.DbGetQrz, config.DbTable)
rows, err := db.Query(q) rows, err := db.Query(q)
for rows.Next() { for rows.Next() {
@ -79,6 +80,7 @@ func DiscardExistingEntries(config config.Config, frsPeople *map[string]FrsEntry
for _, entry := range existingQRZ { for _, entry := range existingQRZ {
delete(*frsPeople, entry) delete(*frsPeople, entry)
} }
return return
} }
@ -90,7 +92,7 @@ func InsertFrsEntryToDB(config config.Config, db sqlx.DB, frsPeople map[string]F
fmt.Println(fmt.Sprintf("Starting inserts of %d entries", len(frsPeople))) fmt.Println(fmt.Sprintf("Starting inserts of %d entries", len(frsPeople)))
for _, j := range frsPeople { for _, j := range frsPeople {
query := fmt.Sprintf(config.DbInsertStatement, config.DbTable, j.QRZ, j.Name, j.City, j.Dept, j.Country) query := fmt.Sprintf(config.Statements.DbInsert, config.DbTable, j.QRZ, j.Name, j.City, j.Dept, j.Country)
tx.MustExec(query) tx.MustExec(query)
qrzNum++ qrzNum++
} }