so I have sql that looks like this
SELECT accounts.id, accounts.username, accounts.password,
accounts.created, accounts.last_logged_in, accounts.access,
banned.reason, banned.expires,
player.x, player.y, player.zone
FROM accounts
LEFT JOIN banned
ON accounts.id = banned.account_Id
INNER JOIN player
ON accounts.id = player.account_Id
WHERE accounts.username = username
If I wanted to store this in a struct in go I would normally do this:
type Account struct {
Id int
Username string
Password string
Email string
Created time.Time
LastLoggedIn time.Time
AccessLevel int
Location struct {
Zone string
}
Banned []*Banned
}
type Banned struct {
Reason string
Expires time.Time
}
reply := new(Account)
stmt, err := this.Database.Prepare(("CALL findUser(?)"))
defer stmt.Close()
if err != nil {
logger.ERROR.Println(err)
return err
}
err = stmt.QueryRow(args).Scan(&reply.Id, &reply.Username ... you get the idea)
however this is not going work because scan is going to expect a value for every argument and we have left joined onto banned! As the user could have 0 - N bans what’s the best way to tackle this?
Many thanks Zidsal