fix account upsert

This commit is contained in:
Andre Medeiros 2021-07-12 15:09:40 -04:00
parent d0cf4e74d0
commit 33b3af6584

View file

@ -27,10 +27,15 @@ type AccountModel struct {
func (am *AccountModel) Upsert(a *Account) error { func (am *AccountModel) Upsert(a *Account) error {
query := ` query := `
INSERT INTO accounts (username, account_id, access_token, refresh_token, expires_at, last_message_id, device_count, last_checked_at) INSERT INTO accounts (username, account_id, access_token, refresh_token, expires_at, last_message_id, device_count, last_checked_at)
VALUES ($1, $2, $3, $4, '', 0, 0) VALUES ($1, $2, $3, $4, $5, '', 0, 0)
ON CONFLICT(username) ON CONFLICT(username)
DO DO
UPDATE SET access_token = $2, refresh_token = $3, expires_at = $4, last_message_id = $5, last_checked_at = $6 UPDATE SET
access_token = $3,
refresh_token = $4,
expires_at = $5,
last_message_id = $6,
last_checked_at = $7
RETURNING id` RETURNING id`
args := []interface{}{a.NormalizedUsername(), a.AccountID, a.AccessToken, a.RefreshToken, a.ExpiresAt, a.LastMessageID, a.LastCheckedAt} args := []interface{}{a.NormalizedUsername(), a.AccountID, a.AccessToken, a.RefreshToken, a.ExpiresAt, a.LastMessageID, a.LastCheckedAt}