Conversation
|
@juliusmarminge thank you for your contribution. Can you explain a little what the use case is for checking whether the client is a PlanetScale client, and in which instances My best guess is that this is for narrowing, if we accept this patch we'll want to document that this utility is available, what/when it should used for. |
|
For future ref Markdoc does something similar but as a static method on the class |
|
Hey, sorry your other comment must have passed by my inbox. We need to check if a client is a export class MySqlDrizzle extends Context.Tag("@uploadthing/db/Client")<
MySqlDrizzle,
DatabaseClient
>() {
static affectedRows = (result: QueryResult["type"]): number => {
const row = Array.isArray(result) ? result[0] : result;
const count =
"rowsAffected" in row
? row.rowsAffected // pscale
: row.affectedRows; // mysql2
return count;
};
static make = (
client: mysql2.Pool | mysql2.Connection | PlanetScale.Client,
): DatabaseClient => {
if (isPlanetScaleClient(client)) {
return drizzlePlanetscale(client);
} else {
return drizzleMysql2(client);
}
};
}Not sure when
lmk how you wanna move forward |
Hey there,
Small little utility guard for checking if a client is a PlanetScale client. We currently have a helper like this in our codebase
due to some issues with
instanceofcheck unexpectedly returning false.Accept or deny as you wish :)