Hey guys, I made a custom function to sort my shop...
# sql
w
Hey guys, I made a custom function to sort my shops by distance. There are also "premium shops" which should be listed first, no matter of the distance. Each studio has the column
isPremium
which is whether
true
or
false
. How can I do that? nearby_studios function (param:
location
)
Copy code
sql
select *
from studios
order by location <-> st_geogfromtext(nearby_studios.location);
I use it like this
Copy code
js
const { data: studios, error } = await client.rpc('nearby_studios',
    { location: `POINT(${userLocation.longitude} ${userLocation.latitude})` }
)
    .limit(50)
    .not('street', 'is', null)
    .not('city', 'is', null)