tableName() ::= "user_roles"

tableFields(prefix) ::= <<
  <prefix>username
, <prefix>role_name
, <prefix>is_active
, <prefix>created_date
, <prefix>created_by
, <prefix>updated_date
, <prefix>updated_by
>>

allTableFields(prefix) ::= <<
  <prefix>record_id
, <tableFields(prefix)>
>>


tableValues() ::= <<
  :username
, :roleName
, :isActive
, :createdDate
, :createdBy
, :updatedDate
, :updatedBy
>>


allTableValues() ::= <<
  :recordId
, <tableValues()>
>>

create() ::= <<
insert into <tableName()> (
<tableFields("")>
)
values (
<tableValues()>
)
;
>>

getByRecordId() ::= <<
select <allTableFields("")>
from <tableName()>
where record_id = :recordId
and is_active
;
>>

getByUsername() ::= <<
select <allTableFields("")>
from <tableName()>
where username = :username
and is_active
;
>>

invalidate() ::= <<
update <tableName()>
set is_active = false
where
username = :username
and role_name = :roleName
;
>>
