BlockingStateSqlDao.sql.stg

69 lines | 1.231 kB Blame History Raw Download
group BlockingStateSqlDao: EntitySqlDao;


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


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

getBlockingStateFor() ::= <<
    select
        id
      , blockable_id
      , state
      , type
      , service
      , block_change
      , block_entitlement
      , block_billing
      , created_date
      , tenant_record_id
    from blocking_states
    where blockable_id = :blockable_id
    <AND_CHECK_TENANT()>
    -- We want the current state, hence the order desc and limit 1
    order by created_date desc, record_id desc
    limit 1
    ;
>>

getBlockingHistoryFor() ::= <<
    select
       id
      , blockable_id
      , state
      , type
      , service
      , block_change
      , block_entitlement
      , block_billing
      , created_date
      , tenant_record_id
    from blocking_states
    where blockable_id = :blockable_id
    <AND_CHECK_TENANT()>
    -- We want the history in order
    order by created_date asc, record_id asc
    ;
>>