prop
prop
Explore posts from servers
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
if interested i ended up with this
const sq = db.$with('sq').as(db.select({
...getTableColumns(apartments),
distance: sql`111.320 * COS(${apartments.long} - 56.17058131394731) * ABS(${apartments.long} - 56.17058131394731) + 110.574 * ABS(${apartments.lat} - 10.18838401351414)`.mapWith(Number).as("distance")
}).from(apartments))
const res = await db.with(sq).select().from(sq).where(lte(sq.distance, 10))
const sq = db.$with('sq').as(db.select({
...getTableColumns(apartments),
distance: sql`111.320 * COS(${apartments.long} - 56.17058131394731) * ABS(${apartments.long} - 56.17058131394731) + 110.574 * ABS(${apartments.lat} - 10.18838401351414)`.mapWith(Number).as("distance")
}).from(apartments))
const res = await db.with(sq).select().from(sq).where(lte(sq.distance, 10))
i mean not perfect but I'll take it
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
Guess I'll have to look into $with
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
which is the same as the very first try
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
it just adds the as calculation at the end
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
same thing
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
select "id", "name", "lat", "long", 111.320 * COS("long" - 56.17058131394731) * ABS("long" - 56.17058131394731) + 110.574 * ABS("lat" - 10.18838401351414) from "apartments" where distance < 10
select "id", "name", "lat", "long", 111.320 * COS("long" - 56.17058131394731) * ABS("long" - 56.17058131394731) + 110.574 * ABS("lat" - 10.18838401351414) from "apartments" where distance < 10
gives this query, same issue though
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
The query that was built looks right
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
Keep in mind I actually called the column distance and so on
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
Heres the error:
PostgresError: column "distance" does not exist
PostgresError: column "distance" does not exist
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
select "id", "name", "lat", "long", 111.320 * COS("long" - 56.17058131394731) * ABS("long" - 56.17058131394731) + 110.574 * ABS("lat" - 10.18838401351414) as "distance" from "apartments" where distance < 10
select "id", "name", "lat", "long", 111.320 * COS("long" - 56.17058131394731) * ABS("long" - 56.17058131394731) + 110.574 * ABS("lat" - 10.18838401351414) as "distance" from "apartments" where distance < 10
I got the query now
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
I do the query with this
const res = await db.select({.....
const res = await db.select({.....
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
correct
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
sure thing
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
export const db = drizzle(queryClient, { schema, logger: true });
export const db = drizzle(queryClient, { schema, logger: true });
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
@Angelelz hmm I passed the logger: true but it doesn't do much
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
Where can I see that?
73 replies
DTDrizzle Team
Created by prop on 11/9/2023 in #help
Access values in "where" query
fair
73 replies