// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: permissions.sql package repository import ( "context" "github.com/google/uuid" ) const createPermission = `-- name: CreatePermission :one INSERT into permissions ( name, scope, description ) VALUES ( $1, $2, $3 ) RETURNING id, name, scope, description ` type CreatePermissionParams struct { Name string `json:"name"` Scope string `json:"scope"` Description *string `json:"description"` } func (q *Queries) CreatePermission(ctx context.Context, arg CreatePermissionParams) (Permission, error) { row := q.db.QueryRow(ctx, createPermission, arg.Name, arg.Scope, arg.Description) var i Permission err := row.Scan( &i.ID, &i.Name, &i.Scope, &i.Description, ) return i, err } const findPermission = `-- name: FindPermission :one SELECT id, name, scope, description FROM permissions WHERE name = $1 AND scope = $2 ` type FindPermissionParams struct { Name string `json:"name"` Scope string `json:"scope"` } func (q *Queries) FindPermission(ctx context.Context, arg FindPermissionParams) (Permission, error) { row := q.db.QueryRow(ctx, findPermission, arg.Name, arg.Scope) var i Permission err := row.Scan( &i.ID, &i.Name, &i.Scope, &i.Description, ) return i, err } const getAllPermissions = `-- name: GetAllPermissions :many SELECT id, name, scope, description FROM permissions p ORDER BY p.scope ` func (q *Queries) GetAllPermissions(ctx context.Context) ([]Permission, error) { rows, err := q.db.Query(ctx, getAllPermissions) if err != nil { return nil, err } defer rows.Close() var items []Permission for rows.Next() { var i Permission if err := rows.Scan( &i.ID, &i.Name, &i.Scope, &i.Description, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getGroupedPermissions = `-- name: GetGroupedPermissions :many SELECT scope, json_agg(to_jsonb(permissions.*) ORDER BY name) as permissions FROM permissions GROUP BY scope ` type GetGroupedPermissionsRow struct { Scope string `json:"scope"` Permissions []byte `json:"permissions"` } func (q *Queries) GetGroupedPermissions(ctx context.Context) ([]GetGroupedPermissionsRow, error) { rows, err := q.db.Query(ctx, getGroupedPermissions) if err != nil { return nil, err } defer rows.Close() var items []GetGroupedPermissionsRow for rows.Next() { var i GetGroupedPermissionsRow if err := rows.Scan(&i.Scope, &i.Permissions); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getUserPermissions = `-- name: GetUserPermissions :many SELECT DISTINCT p.id,p.name,p.scope,p.description FROM user_roles ur JOIN role_permissions rp ON ur.role_id = rp.role_id JOIN permissions p ON rp.permission_id = p.id WHERE ur.user_id = $1 ORDER BY p.scope ` func (q *Queries) GetUserPermissions(ctx context.Context, userID uuid.UUID) ([]Permission, error) { rows, err := q.db.Query(ctx, getUserPermissions, userID) if err != nil { return nil, err } defer rows.Close() var items []Permission for rows.Next() { var i Permission if err := rows.Scan( &i.ID, &i.Name, &i.Scope, &i.Description, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil }