group BusinessAccount;
getAccountsCreatedOverTime() ::= <<
select
date(from_unixtime(created_date / 1000)) day
-- TODO: use account_record_id, once populated
, count(record_id) count
from bac
group by 1
order by 1
;
>>
getSubscriptionsCreatedOverTime(product_type, slug) ::= <<
select
date(from_unixtime(requested_timestamp / 1000)) day
, count(record_id) count
from bst
where event in ('ADD_ADD_ON', 'ADD_BASE', 'ADD_STANDALONE')
and next_product_type = :product_type
and next_slug = :slug
group by 1
order by 1
;
>>
getAccount(account_id) ::= <<
select
account_id
, account_key
, created_date
, updated_date
, balance
, name
, last_invoice_date
, total_invoice_balance
, last_payment_status
, payment_method
, credit_card_type
, billing_address_country
, currency
from bac
where account_id=:account_id
limit 1
;
>>
getAccountByKey(account_key) ::= <<
select
account_id
, account_key
, created_date
, updated_date
, balance
, name
, last_invoice_date
, total_invoice_balance
, last_payment_status
, payment_method
, credit_card_type
, billing_address_country
, currency
from bac
where account_key=:account_key
limit 1
;
>>
createAccount() ::= <<
insert into bac(
account_id
, account_key
, created_date
, updated_date
, balance
, name
, last_invoice_date
, total_invoice_balance
, last_payment_status
, payment_method
, credit_card_type
, billing_address_country
, currency
) values (
:account_id
, :account_key
, :created_date
, :updated_date
, :balance
, :name
, :last_invoice_date
, :total_invoice_balance
, :last_payment_status
, :payment_method
, :credit_card_type
, :billing_address_country
, :currency
);
>>
saveAccount() ::= <<
update bac set
updated_date=:updated_date
, balance=:balance
, name=:name
, last_invoice_date=:last_invoice_date
, total_invoice_balance=:total_invoice_balance
, last_payment_status=:last_payment_status
, payment_method=:payment_method
, credit_card_type=:credit_card_type
, billing_address_country=:billing_address_country
, currency=:currency
where account_id=:account_id
;
>>
test() ::= <<
select 1 from bac;
>>