Skip to content

Commit

Permalink
fix: select current day search analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Sep 3, 2024
1 parent 524c8d5 commit 8b9ed95
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apps/backend/src/backend/postgres/queries.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ pub fn upsert_search_analytics(db: pgo.Connection, query: String) {
}

pub fn select_last_day_search_analytics(db: pgo.Connection) {
let #(date, _) = birl.to_erlang_universal_datetime(birl.now())
let now = birl.from_erlang_universal_datetime(#(date, #(0, 0, 0)))
"SELECT query, occurences
FROM search_analytics
WHERE updated_at <= now()
AND updated_at >= now() - INTERVAL '1 hour'"
|> pgo.execute(db, [], dynamic.tuple2(dynamic.string, dynamic.int))
WHERE updated_at >= $1"
|> pgo.execute(
db,
[helpers.convert_time(now)],
dynamic.tuple2(dynamic.string, dynamic.int),
)
|> result.map(fn(r) { r.rows })
|> result.map_error(error.DatabaseError)
}
Expand Down

0 comments on commit 8b9ed95

Please sign in to comment.