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) {
|
||||
var results []*model.MonthlySpending
|
||||
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;
|
||||
`
|
||||
var query string
|
||||
if r.db.DriverName() == "sqlite" {
|
||||
query = `
|
||||
SELECT strftime('%Y-%m', date) 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 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)
|
||||
return results, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue