37 lines
685 B
Go
37 lines
685 B
Go
package profileRepository
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"gitea.cybertalant.ru/VisionCareerMiniapp/MiniappGoService/internal/application/types"
|
|
)
|
|
|
|
func (t *repository) CreateUser(id int64, username *string) (*types.User, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
query := `
|
|
INSERT INTO users (id, username)
|
|
VALUES (:id, :username)
|
|
RETURNING *
|
|
`
|
|
data := &types.User{
|
|
ID: id,
|
|
Username: username,
|
|
}
|
|
|
|
stmt, err := t.pgDB.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer stmt.Close()
|
|
|
|
err = stmt.GetContext(ctx, data, data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return data, nil
|
|
}
|