38 lines
749 B
Go
38 lines
749 B
Go
package account
|
|
|
|
import (
|
|
"nos-comptes/internal/storage/dao/postgresql"
|
|
)
|
|
|
|
type Database struct {
|
|
*postgresql.DatabasePostgreSQL
|
|
}
|
|
|
|
func (db *Database) GetAllAccountOfUser(id string) ([]*Account, error) {
|
|
q := `
|
|
SELECT a.id, a.user_id, a.name, a.provider, a.created_at, a.updated_at
|
|
FROM public.account a
|
|
WHERE a.id = $1
|
|
`
|
|
rows, err := db.Session.Query(q)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
as := make([]*Account, 0)
|
|
for rows.Next() {
|
|
a := Account{}
|
|
err := rows.Scan(&a.ID, &a.userId, &a.name, &a.provider, &a.CreatedAt, &a.UpdatedAt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
as = append(as, &a)
|
|
}
|
|
return as, nil
|
|
}
|
|
|
|
func NewDatabase(db *postgresql.DatabasePostgreSQL) *Database {
|
|
return &Database{db}
|
|
}
|