Uh oh!
There was an error while loading. Please reload this page.
feat: add isClient guard - #183
Conversation
ayrton
commented
Sep 6, 2024
@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. |
ayrton
commented
Oct 14, 2024
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 exportclassMySqlDrizzleextendsContext.Tag("@uploadthing/db/Client")<MySqlDrizzle,DatabaseClient>(){staticaffectedRows=(result: QueryResult["type"]): number=>{constrow=Array.isArray(result) ? result[0] : result;constcount="rowsAffected"inrow
? row.rowsAffected// pscale
: row.affectedRows;// mysql2returncount;};staticmake=(client: mysql2.Pool|mysql2.Connection|PlanetScale.Client,): DatabaseClient=>{if(isPlanetScaleClient(client)){returndrizzlePlanetscale(client);}else{returndrizzleMysql2(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 :)