반응형
func (a *Account) Insert(db *sql.DB) {
now := time.Now()
sql_statement := "INSERT INTO account (account_id, device_model, memory_size, created_at) VALUES ($1, $2, $3, $4);"
_, err := db.Exec(sql_statement, a.AccountId, a.DeviecModel, a.MemorySize, now)
if err != nil {
sql_statement = "UPDATE account SET device_model = $1, memory_size = $2, created_at = $3 WHERE account_id = $4;"
result, _ := db.Exec(sql_statement, a.DeviecModel, a.MemorySize, now, a.AccountId)
row, err := result.RowsAffected()
if row == 0 || err != nil {
log.Panic().Stack().Err(err).Msg("Insert")
}
}
}
'프로그래밍' 카테고리의 다른 글
golang 공유 자원 사용하기 (0) | 2022.11.03 |
---|---|
golang 간단한 pg 라이브러리 (0) | 2022.11.02 |
postgresql wsl2에 설치 (0) | 2022.10.26 |
vscode perfoce 플러그인 연동 (0) | 2022.10.21 |
Set the P4CLIENT environment variable to desired workspace name. (0) | 2022.10.21 |