Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/leifniem/pgtyped
Browse files Browse the repository at this point in the history
  • Loading branch information
Leif Niemczik committed May 16, 2023
2 parents ce29af2 + 8c4cab3 commit 21a317f
Show file tree
Hide file tree
Showing 5 changed files with 6,388 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions packages/cli/config.json
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/"
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"access": "public"
},
"scripts": {
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
"test": "set NODE_OPTIONS='--experimental-vm-modules'; jest",
"build": "tsc",
"check": "tsc --noEmit",
"watch": "tsc --watch --preserveWatchOutput"
Expand Down
67 changes: 67 additions & 0 deletions packages/cli/rawsql/tours.sql
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.*;
Loading

0 comments on commit 21a317f

Please sign in to comment.