-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/leifniem/pgtyped
- Loading branch information
Showing
5 changed files
with
6,388 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"transforms": [ | ||
{ | ||
"mode": "sql", | ||
"include": "**/*.sql", | ||
"emitTemplate": "_queries/{{name}}.queries.ts" | ||
} | ||
], | ||
"camelCaseColumnNames": true, | ||
"dbUrl": "postgres://postgres:postgres@localhost:5432/postgres", | ||
"srcDir": "./rawsql/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
@name GetSingleTour | ||
*/ | ||
select | ||
t.id, | ||
started_at, | ||
jsonb_agg(p) as points, | ||
row_to_json(u) as user | ||
from tours t | ||
left join ( | ||
select | ||
tour_id, | ||
time_bucket(:timespanSegment, time) as timestamp, | ||
avg(lat) as lat, | ||
avg(lon) as lon, | ||
avg(altitude) as altitude | ||
from gpx_track_points | ||
group by tour_id, timestamp | ||
) p on p.tour_id = t.id | ||
left join ( | ||
select | ||
users.id, | ||
first_name, | ||
left(last_name, 1) as last_name_initial | ||
from users | ||
) u on u.id = t.user_id | ||
where t.id = :id | ||
group by t.id, t.started_at, u.* | ||
limit 1; | ||
|
||
/* | ||
@name getAllTours | ||
@param ids -> (...) | ||
*/ | ||
select | ||
t.id, | ||
started_at, | ||
jsonb_agg(p) as points, | ||
row_to_json(u) as user | ||
from tours t | ||
left join ( | ||
select | ||
tour_id, | ||
time_bucket('10 minutes', time) as timestamp, | ||
avg(lat) as lat, | ||
avg(lon) as lon, | ||
avg(altitude) as altitude | ||
from gpx_track_points | ||
group by tour_id, timestamp | ||
) p on p.tour_id = t.id | ||
left join ( | ||
select | ||
users.id, | ||
first_name, | ||
left(last_name, 1) as last_name_initial | ||
from users | ||
) u on u.id = t.user_id | ||
where (:ids :: bigint[] is null or t.id = ANY(:ids)) | ||
and (:startMin :: timestamp is null or t.started_at >= :startMin) | ||
and (:startMax :: timestamp is null or t.started_at <= :startMax) | ||
and (:latMin :: double precision is null or p.lat >= :latMin) | ||
and (:latMax :: double precision is null or p.lat <= :latMax) | ||
and (:lonMin :: double precision is null or p.lon >= :lonMin) | ||
and (:lonMax :: double precision is null or p.lon <= :lonMax) | ||
and (:altitudeMin :: double precision is null or p.altitude >= :altitudeMin) | ||
and (:altitudeMax :: double precision is null or p.altitude <= :altitudeMax) | ||
group by t.id, t.started_at, u.*; |
Oops, something went wrong.