fix: TO_CHAR query fails on sqlite
All checks were successful
Deploy / build-and-deploy (push) Successful in 2m38s
All checks were successful
Deploy / build-and-deploy (push) Successful in 2m38s
This commit is contained in:
parent
e1ad197624
commit
13774eec7d
1 changed files with 16 additions and 7 deletions
|
|
@ -273,13 +273,22 @@ func (r *expenseRepository) GetDailySpending(spaceID string, from, to time.Time)
|
||||||
|
|
||||||
func (r *expenseRepository) GetMonthlySpending(spaceID string, from, to time.Time) ([]*model.MonthlySpending, error) {
|
func (r *expenseRepository) GetMonthlySpending(spaceID string, from, to time.Time) ([]*model.MonthlySpending, error) {
|
||||||
var results []*model.MonthlySpending
|
var results []*model.MonthlySpending
|
||||||
query := `
|
var query string
|
||||||
SELECT TO_CHAR(date, 'YYYY-MM') as month, SUM(amount_cents) as total_cents
|
if r.db.DriverName() == "sqlite" {
|
||||||
FROM expenses
|
query = `
|
||||||
WHERE space_id = $1 AND type = 'expense' AND date >= $2 AND date <= $3
|
SELECT strftime('%Y-%m', date) as month, SUM(amount_cents) as total_cents
|
||||||
GROUP BY TO_CHAR(date, 'YYYY-MM')
|
FROM expenses
|
||||||
ORDER BY month ASC;
|
WHERE space_id = $1 AND type = 'expense' AND date >= $2 AND date <= $3
|
||||||
`
|
GROUP BY strftime('%Y-%m', date)
|
||||||
|
ORDER BY month ASC;`
|
||||||
|
} else {
|
||||||
|
query = `
|
||||||
|
SELECT TO_CHAR(date, 'YYYY-MM') as month, SUM(amount_cents) as total_cents
|
||||||
|
FROM expenses
|
||||||
|
WHERE space_id = $1 AND type = 'expense' AND date >= $2 AND date <= $3
|
||||||
|
GROUP BY TO_CHAR(date, 'YYYY-MM')
|
||||||
|
ORDER BY month ASC;`
|
||||||
|
}
|
||||||
err := r.db.Select(&results, query, spaceID, from, to)
|
err := r.db.Select(&results, query, spaceID, from, to)
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue