alex
alex
Explore posts from servers
DTDrizzle Team
Created by alex on 10/17/2024 in #help
sql operator automatically inserts wrong json quotes around expression
const sqlString = sql`select * from ${workflows} w where JSON_CONTAINS(w.definition, '{ "data": { "formId": "${formId}", "type": "form_submission" }}', '$.nodes')`;
const sqlString = sql`select * from ${workflows} w where JSON_CONTAINS(w.definition, '{ "data": { "formId": "${formId}", "type": "form_submission" }}', '$.nodes')`;
With this I get the following error
"sql": "select * from `workflows` w where JSON_CONTAINS(w.definition, '{ \"data\": { \"formId\": \"'HUkAEH1LUD'\", \"type\": \"form_submission\" }}', '$.nodes')",
"sqlState": "42000",
"sqlMessage": "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\", \"type\": \"form_submission\" }}', '$.nodes')' at line 1"
"sql": "select * from `workflows` w where JSON_CONTAINS(w.definition, '{ \"data\": { \"formId\": \"'HUkAEH1LUD'\", \"type\": \"form_submission\" }}', '$.nodes')",
"sqlState": "42000",
"sqlMessage": "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\", \"type\": \"form_submission\" }}', '$.nodes')' at line 1"
When I try the same without the expression it works as expected and I get some rows as a result.
const sqlString = sql`select * from ${workflows} w where JSON_CONTAINS(w.definition, '{ "data": { "formId": "ASADA7898ASD", "type": "form_submission" }}', '$.nodes')`;
const sqlString = sql`select * from ${workflows} w where JSON_CONTAINS(w.definition, '{ "data": { "formId": "ASADA7898ASD", "type": "form_submission" }}', '$.nodes')`;
1 replies
TtRPC
Created by alex on 6/7/2024 in #❓-help
nodeHTTPHandler with Nitro
I'm trying to setup trpc with nitro.unjs.io using the node-httpadapter.
import { nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http";
import { appRouter } from "~/lib/trpc/router";

export default defineEventHandler(async (event) => {
console.log('trpc route handler');
const res = await nodeHTTPRequestHandler({
req: event.node.req,
res: event.node.res,
router: appRouter,
path: '/api/trpc',
});
console.log(res) // returns undefined
});
import { nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http";
import { appRouter } from "~/lib/trpc/router";

export default defineEventHandler(async (event) => {
console.log('trpc route handler');
const res = await nodeHTTPRequestHandler({
req: event.node.req,
res: event.node.res,
router: appRouter,
path: '/api/trpc',
});
console.log(res) // returns undefined
});
Frontend setup:
const [queryClient] = useState(() => new QueryClient());
const [trpcClient] = useState(() => trpc.createClient({
links: [
httpBatchLink({
url: 'http://localhost:3000/api/trpc',
}),
],
}));
const [queryClient] = useState(() => new QueryClient());
const [trpcClient] = useState(() => trpc.createClient({
links: [
httpBatchLink({
url: 'http://localhost:3000/api/trpc',
}),
],
}));
const { data, isLoading } = trpc.formList.useQuery();
const { data, isLoading } = trpc.formList.useQuery();
There are no TS errors anywhere so the router setup should be correct. However the nodeHTTPRequestHandler function always returns undefined. I've also tried the trpc-nuxt package because apparently that's supposed to work with Nitro but I couldn't get it to work because I'm using trpc v11.
3 replies
TtRPC
Created by alex on 12/21/2022 in #❓-help
Type safety with enabled option
https://tkdodo.eu/blog/react-query-and-type-script#type-safety-with-the-enabled-option What is the best way to solve this with trpc?
function useSessions(userId: number | null) {
trpc.sessions.useQuery({ userId }, { enabled: userId !== null });
...
}
function useSessions(userId: number | null) {
trpc.sessions.useQuery({ userId }, { enabled: userId !== null });
...
}
typescript: Type 'number | null' is not assignable to type 'number'.
19 replies