group TenantDaoSql;

tenantFields(prefix) ::= <<
    <prefix>record_id,
    <prefix>id,
    <prefix>external_key,
    <prefix>api_key,
    <prefix>created_date,
    <prefix>created_by,
    <prefix>updated_date,
    <prefix>updated_by
>>

create() ::= <<
    INSERT INTO tenants (
        id
      , external_key
      , api_key
      , api_secret
      , api_salt
      , created_date
      , created_by
      , updated_date
      , updated_by
    ) VALUES (
        :id
      , :externalKey
      , :apiKey
      , :apiSecret
      , :apiSalt
      , :createdDate
      , :userName
      , :updatedDate
      , :userName
    );
>>

get() ::= <<
    SELECT <tenantFields()>
    FROM tenants;
>>

getById() ::= <<
    SELECT <tenantFields()>
    FROM tenants
    WHERE id = :id;
>>

getByApiKey() ::= <<
    SELECT <tenantFields()>
    FROM tenants
    WHERE api_key = :apiKey;
>>

getSecrets() ::= <<
    SELECT api_key, api_secret, api_salt
    FROM tenants
    WHERE id = :id;
>>

test() ::= <<
    SELECT 1 FROM tenants;
>>
