Skip to content

Commit

Permalink
Fixed SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Aug 31, 2023
1 parent 0c1c5da commit 682d24c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/app/data-provider/db-data-provider/db-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ export class DbDataProvider implements DataProvider {
async getFeaturesByBBox(bounds: Bounds, limit: number, page: number = 1): Promise<FeaturesAnswer> {
const db = DB.getInstance();
const query = (fields: string) =>
`select ${fields} from public.points where ST_MakeEnvelope($1, $2, $3, $4) ~ coordinates`;
`select ${fields} from points where coordinates && ST_MakeEnvelope($1, $2, $3, $4)`;

const [total] = (await db.query(`${query('count(uuid) as cnt')} limit $5`, bounds.flat())).rows;
const [total] = (await db.query(query('count(uid) as cnt'), bounds.flat())).rows;

const points = await db.query(`${query('feature')} limit $5 $6`, [...bounds.flat(), limit, limit * (page - 1)]);
const points = await db.query(`${query('feature')} limit $5 offset $6`, [
...bounds.flat(),
limit,
limit * (page - 1)
]);

return {
total: total.cnt,
Expand Down

0 comments on commit 682d24c

Please sign in to comment.