BlockingStateSqlDao.sql.stg

77 lines | 1.157 kB Blame History Raw Download
group BlockingStateSqlDao: EntitySqlDao;


tableName() ::= "blocking_states"

tableFields(prefix) ::= <<
  <prefix>blockable_id
, <prefix>type
, <prefix>state
, <prefix>service
, <prefix>block_change
, <prefix>block_entitlement
, <prefix>block_billing
, <prefix>created_date
>>


tableValues() ::= <<
  :blockableId
, :type
, :state
, :service
, :blockChange
, :blockEntitlement
, :blockBilling
, :createdDate
>>


getBlockingStateForService() ::= <<
select
<allTableFields()>
from
<tableName()>
where blockable_id = :blockableId
and service = :service
<AND_CHECK_TENANT()>
-- We want the current state, hence the order desc and limit 1
order by record_id desc
limit 1
;
>>

getBlockingState() ::= <<
 select
 <allTableFields()>
 from
 <tableName()>
 where blockable_id = :blockableId
 <AND_CHECK_TENANT()>
 order by record_id asc
 ;
 >>

getBlockingHistoryForService() ::= <<
select
<allTableFields()>
from
<tableName()>
where blockable_id = :blockableId
and service = :service
<AND_CHECK_TENANT()>
order by record_id asc
;
>>

getBlockingHistory() ::= <<
select
<allTableFields()>
from
<tableName()>
where blockable_id = :blockableId
<AND_CHECK_TENANT()>
order by record_id asc
;
>>