feat: user_rework (todo -> GetAll)

This commit is contained in:
2025-06-11 12:30:22 +01:00
parent 6aa3870a5c
commit 189534031b
24 changed files with 647 additions and 142 deletions
+16 -4
View File
@@ -14,21 +14,33 @@ type Role struct {
type RoleStore struct {
db *sql.DB
getByNameStmt *sql.Stmt
}
func (s *RoleStore) GetByName(ctx context.Context, name string) (*Role, error) {
query := `
func NewRoleStore(db *sql.DB) (*RoleStore, error) {
getByNameStmt, err := db.PrepareContext(context.Background(), `
SELECT id, name, level, description
FROM roles
WHERE name = $1
`
`)
if err != nil {
return nil, err
}
return &RoleStore{
db: db,
getByNameStmt: getByNameStmt,
}, nil
}
func (s *RoleStore) GetByName(ctx context.Context, name string) (*Role, error) {
ctx, cancel := context.WithTimeout(ctx, QueryTimeout)
defer cancel()
role := &Role{}
err := s.db.QueryRowContext(ctx, query, name).Scan(
err := s.getByNameStmt.QueryRowContext(ctx, name).Scan(
&role.ID,
&role.Name,
&role.Level,