Vicente
Vicente
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
That's great news! It may be a too big for a first issue, but it'd be happy to work on it with some guidance.
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
I can try that out yes
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
Ideally I wouldn't want to perform the st_text parsing when querying things - I'd like that to happen transparently for these types
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
I think so. If I understand where to use the sql<Point>....mapWith(table.column) I'm not sure how that gets picked up by the returning()
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
Oh, yes - so that output happens when returning from an insert like the one below. I'm outputting the value of lonlatas it comes from pg:
const station = {
position: {
latitude: 36.054591,
longitude: -5.712635,
},
createdAt: new Date(),
updatedAt: new Date(),
};
const stations = [station];

const newlyCreated = await db
.insert(locations)
.values(stations)
.returning();

const station = {
position: {
latitude: 36.054591,
longitude: -5.712635,
},
createdAt: new Date(),
updatedAt: new Date(),
};
const stations = [station];

const newlyCreated = await db
.insert(locations)
.values(stations)
.returning();

73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
console.log
Query: insert into "locations" ("lonlat", "created_at", "updated_at") values ($1, $2, $3) returning "id", "lonlat", "created_at", "updated_at" -- params: ["POINT(-5.712635 36.054591)", "2023-05-06T12:27:51.203Z", "2023-05-06T12:27:51.203Z"]

at r.write (node_modules/src/logger.ts:19:3)

console.log
010100000099F04BFDBCD916C0F6D37FD6FC064240
console.log
Query: insert into "locations" ("lonlat", "created_at", "updated_at") values ($1, $2, $3) returning "id", "lonlat", "created_at", "updated_at" -- params: ["POINT(-5.712635 36.054591)", "2023-05-06T12:27:51.203Z", "2023-05-06T12:27:51.203Z"]

at r.write (node_modules/src/logger.ts:19:3)

console.log
010100000099F04BFDBCD916C0F6D37FD6FC064240
From my test script when outputting to stdout the contents of value.
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
Exactly. In this case:
fromDriver(value: string): Point {
const matches = value.match(/POINT\((?<longitude>[\d.-]+) (?<latitude>[\d.-]+)\)/);
const { longitude, latitude } = matches.groups;

return {
longitude: parseFloat(longitude),
latitude: parseFloat(latitude),
};
},
fromDriver(value: string): Point {
const matches = value.match(/POINT\((?<longitude>[\d.-]+) (?<latitude>[\d.-]+)\)/);
const { longitude, latitude } = matches.groups;

return {
longitude: parseFloat(longitude),
latitude: parseFloat(latitude),
};
},
value is an actual binary blob representing the geometry - it is missing the set_astext(location) to convert it to the text representation
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
oh woah, that was quick. Ty guys for chiming in. I'm struggling to see where to go. No rush, I'm still debugging/tracing things to understand how everything works first.
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
so changing my toDriver to the one you showed us above, makes my insert successful. However, I'm working now on the returning() and select() scenarios - I'd like to parse the geometry to text at the type level instead of in my queries. I'm still getting acquainted with the drizzle internals. For the returning() scenario, I still don't know where to go to intercept the query builder. I'd like to add that st_astext so the newly created records contain the parsed location instead of the binary piece representing the point. Not sure whether the current custom types API supports that either.
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
Do you mean whether my project uses a tool like lerna to manage a monorepo? If that is case, it doesn't.
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
Oh yes, it does!
73 replies
DTDrizzle Team
Created by volks on 5/6/2023 in #help
Custom Type interpreted as String
Lucky to have found this thread! I tried to build a point type as well to support inserts - haven't tried yours out yet, but I wonder if this set up would support inserts as well. I know realize I posted my thrad in the wrong channel, but there's a bit more context here: https://discord.com/channels/1043890932593987624/1056966312997429278/1104042792918990928
73 replies