Skip to content

Instantly share code, notes, and snippets.

@alfiankan
Created April 25, 2022 02:34
Show Gist options
  • Save alfiankan/70873922fe9f26848a156667f6eec146 to your computer and use it in GitHub Desktop.
Save alfiankan/70873922fe9f26848a156667f6eec146 to your computer and use it in GitHub Desktop.
Location repository
import { DatabaseError, Pool, QueryResult } from "pg";
import { Point } from "../entities/Point";
class Locations {
private db: Pool
constructor(pool: Pool) {
this.db = pool
}
getPointsInsideBoundingBox(west: string, south: string, east: string, north: string): Promise<QueryResult<any>> {
return this.db.query({
text: "SELECT id, ST_Y(location) AS y, ST_X(location) as x FROM marker_cluster u WHERE location && ST_MakeEnvelope($1, $2, $3, $4, 4326)",
values: [west, south, east, north]
})
}
}
export { Locations }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment