Merge pull request #86 from Pear-Trading/finn/applegacy
fixed counts for sqlite vs postgres
This commit is contained in:
commit
9851ef5b6f
3 changed files with 31 additions and 4 deletions
|
@ -18,7 +18,10 @@ sub transaction_data {
|
||||||
columns => [
|
columns => [
|
||||||
{
|
{
|
||||||
quantised => $quantised_column,
|
quantised => $quantised_column,
|
||||||
count => \"COUNT(*)",
|
count => $c->pg_or_sqlite(
|
||||||
|
'count',
|
||||||
|
"COUNT(*)",
|
||||||
|
),
|
||||||
sum_distance => $c->pg_or_sqlite(
|
sum_distance => $c->pg_or_sqlite(
|
||||||
'SUM("me"."distance")',
|
'SUM("me"."distance")',
|
||||||
'SUM("me"."distance")',
|
'SUM("me"."distance")',
|
||||||
|
|
|
@ -86,7 +86,10 @@ sub post_customer {
|
||||||
columns => [
|
columns => [
|
||||||
{
|
{
|
||||||
quantised => 'quantised_weeks',
|
quantised => 'quantised_weeks',
|
||||||
count => \"COUNT(*)",
|
count => $c->pg_or_sqlite(
|
||||||
|
'count',
|
||||||
|
"COUNT(*)",
|
||||||
|
),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
group_by => 'quantised_weeks',
|
group_by => 'quantised_weeks',
|
||||||
|
@ -103,7 +106,10 @@ sub post_customer {
|
||||||
join => { 'seller' => 'organisation' },
|
join => { 'seller' => 'organisation' },
|
||||||
columns => {
|
columns => {
|
||||||
sector => "organisation.sector",
|
sector => "organisation.sector",
|
||||||
count => \"COUNT(*)",
|
count => $c->pg_or_sqlite(
|
||||||
|
'count',
|
||||||
|
"COUNT(*)",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
group_by => "organisation.sector",
|
group_by => "organisation.sector",
|
||||||
order_by => { '-desc' => "COUNT(*)" },
|
order_by => { '-desc' => "COUNT(*)" },
|
||||||
|
@ -238,4 +244,19 @@ sub post_leaderboards_paged {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub pg_or_sqlite {
|
||||||
|
my ( $c, $pg_sql, $sqlite_sql ) = @_;
|
||||||
|
|
||||||
|
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||||
|
|
||||||
|
if ( $driver eq 'Pg' ) {
|
||||||
|
return \$pg_sql;
|
||||||
|
} elsif ( $driver eq 'SQLite' ) {
|
||||||
|
return \$sqlite_sql;
|
||||||
|
} else {
|
||||||
|
$c->app->log->warn('Unknown Driver Used');
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -112,7 +112,10 @@ sub _purchases_avg_spend_duration {
|
||||||
columns => [
|
columns => [
|
||||||
{
|
{
|
||||||
quantised => 'quantised_days',
|
quantised => 'quantised_days',
|
||||||
count => \"COUNT(*)",
|
count => $c->pg_or_sqlite(
|
||||||
|
'count',
|
||||||
|
"COUNT(*)",
|
||||||
|
),
|
||||||
sum_value => $c->pg_or_sqlite(
|
sum_value => $c->pg_or_sqlite(
|
||||||
'SUM("me"."value")',
|
'SUM("me"."value")',
|
||||||
'SUM("me"."value")',
|
'SUM("me"."value")',
|
||||||
|
|
Reference in a new issue