Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Ruheni <[email protected]>
  • Loading branch information
jharrell and ruheni authored Nov 7, 2023
1 parent 7edc4f4 commit c7eab15
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ CREATE EXTENSION IF NOT EXISTS "postgis";

```

Make sure that the migration is applied!
Make sure that the migration is applied by running `prisma migrate status`.

## 2. Create a new model that uses a geographic data column

After the migration is applied, you can now add a new model that has a GIS column. For our example we'll be using the following `PointOfInterest` model.
After the migration is applied, you can now add a new model that has a GIS column. For our example, we'll be using a model called `PointOfInterest`.

```prisma
model PointOfInterest {
Expand All @@ -69,7 +69,7 @@ model PointOfInterest {

You'll notice that `location` is marked as `Unsupported`. This means that we lose a lot of the benefits of Prisma when working with `PointOfInterest`. We'll be using [SafeQL](https://safeql.dev/) to fix this.

Create a new migration with `npx prisma migrate dev` and apply it to add the `PointOfInterest` table to our database.
Run the `prisma migrate dev` command to create a migration and the table `PointOfInterest` table in your database.

## 3. Integrate SafeQL

Expand All @@ -85,7 +85,7 @@ Note that for SafeQL to run it will need to have access to your database. We rec

Now let's make a Prisma Client extension in order to query this model. We will be making an extension that finds the closest points of interest to a given longitude and latitude.

```ts file=lib/db.ts
```ts file=lib/prisma.ts
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient().$extends((client) => {
Expand All @@ -109,7 +109,7 @@ const prisma = new PrismaClient().$extends((client) => {
export { prisma }
```

Now we can use our Prisma Client as normal in order to find close points of interest to a given longitude and latitude!
Now, you can use our Prisma Client as normal to find close points of interest to a given longitude and latitude using the custom method created on the `PointOfInterest` model.

```ts file=app.ts
const closestPointOfInterest = await prisma.pointOfInterest.findClosestPoints(
Expand Down

0 comments on commit c7eab15

Please sign in to comment.