updated structs in qrz
This commit is contained in:
parent
f87f436891
commit
6e1edf9e1c
@ -36,27 +36,29 @@ 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.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
|
||||
}
|
||||
|
||||
// Config is the global config of g2g
|
||||
type Config struct {
|
||||
DbHostname string
|
||||
DbName string
|
||||
DbUsername string
|
||||
DbPassword string
|
||||
DbSchema string
|
||||
DbTable string
|
||||
DbInsertStatement string
|
||||
DbGetQrzStatement string
|
||||
DbCheckStatement string
|
||||
FrsConfig struct {
|
||||
DbHostname string
|
||||
DbName string
|
||||
DbUsername string
|
||||
DbPassword string
|
||||
DbSchema string
|
||||
DbTable string
|
||||
Statements struct {
|
||||
DbInsert string
|
||||
DbGetQrz string
|
||||
DbCheck string
|
||||
}
|
||||
FrsConfig struct {
|
||||
URL string
|
||||
XPath string
|
||||
Regex string
|
||||
|
@ -57,12 +57,13 @@ func GetFrsEntries(config config.Config, body string) (frsentries map[string]Frs
|
||||
frsentries[frs.QRZ] = frs
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetCurrentEntries fetch existing entries from database
|
||||
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)
|
||||
|
||||
for rows.Next() {
|
||||
@ -79,6 +80,7 @@ func DiscardExistingEntries(config config.Config, frsPeople *map[string]FrsEntry
|
||||
for _, entry := range existingQRZ {
|
||||
delete(*frsPeople, entry)
|
||||
}
|
||||
|
||||
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)))
|
||||
|
||||
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)
|
||||
qrzNum++
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user