Bryan3
Bryan3
Explore posts from servers
DTDrizzle Team
Created by Bryan3 on 9/29/2023 in #help
Delete operation in transaction sometimes not deleting row in database
Hi, I'm calling a delete operation in a transaction that deletes an organization row in a Supabase Postgres database:
let data: unknown[] = [];
await db.transaction(async (tx) => {
// Update the organizationId of all related contacts to new id
await tx
.update(contact)
.set({ organizationId: input.newId })
.where(eq(contact.organizationId, input.id));
// Delete the organization with old id
data = await tx
.delete(organization)
.where(eq(organization.id, input.id))
.returning();
});
console.log("deleting organiation with id: ", input.id);
console.log("organization deleted: ", data);
let data: unknown[] = [];
await db.transaction(async (tx) => {
// Update the organizationId of all related contacts to new id
await tx
.update(contact)
.set({ organizationId: input.newId })
.where(eq(contact.organizationId, input.id));
// Delete the organization with old id
data = await tx
.delete(organization)
.where(eq(organization.id, input.id))
.returning();
});
console.log("deleting organiation with id: ", input.id);
console.log("organization deleted: ", data);
But sometimes if I delete the row immediately after creation, the console log says the row is deleted but it remains in the database. I need to call delete again for the row to be deleted. (Two deletions console logged below where only after the second delete log row is deleted from the database).
organization created: [
{
id: '9e0d585b-8284-4181-b7bf-6ec879700c6e',
name: '121',
createdAt: 2023-09-30T00:19:26.979Z,
updatedAt: 2023-09-30T00:19:26.979Z
}
]
organization deleted: [
{
id: '9e0d585b-8284-4181-b7bf-6ec879700c6e',
name: '121',
createdAt: 2023-09-30T00:19:26.979Z,
updatedAt: 2023-09-30T00:19:26.979Z
}
]
organization deleted: [
{
id: '9e0d585b-8284-4181-b7bf-6ec879700c6e',
name: '121',
createdAt: 2023-09-30T00:19:26.979Z,
updatedAt: 2023-09-30T00:19:26.979Z
}
]
organization created: [
{
id: '9e0d585b-8284-4181-b7bf-6ec879700c6e',
name: '121',
createdAt: 2023-09-30T00:19:26.979Z,
updatedAt: 2023-09-30T00:19:26.979Z
}
]
organization deleted: [
{
id: '9e0d585b-8284-4181-b7bf-6ec879700c6e',
name: '121',
createdAt: 2023-09-30T00:19:26.979Z,
updatedAt: 2023-09-30T00:19:26.979Z
}
]
organization deleted: [
{
id: '9e0d585b-8284-4181-b7bf-6ec879700c6e',
name: '121',
createdAt: 2023-09-30T00:19:26.979Z,
updatedAt: 2023-09-30T00:19:26.979Z
}
]
Is there an issue with how the transaction is written that is causing the problem? It seems that if I'm getting a console log back drizzle is telling me the object should be deleted. Thank you very much.
6 replies
DTDrizzle Team
Created by Bryan3 on 9/28/2023 in #help
How to include all fields in partial select syntax
Hi, I'm trying to append the organization field using a leftjoin to the existing fields in contact like this:
const response = (await db
.select({
...contact,
organization: {
name: organization.name,
},
})
.from(contact)
.leftJoin(
organization,
eq(contact.organizationId, organization.id),
))
const response = (await db
.select({
...contact,
organization: {
name: organization.name,
},
})
.from(contact)
.leftJoin(
organization,
eq(contact.organizationId, organization.id),
))
The query works but the IDE is giving me the error:
Argument of type '{ organization: { name: PgColumn<{ name: "name"; tableName: "Organization"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>; }; ... 11 more ...; updatedAt: PgColumn<...>; }' is not assignable to parameter of type 'SelectedFields'.
Property '_' is incompatible with index signature.
Argument of type '{ organization: { name: PgColumn<{ name: "name"; tableName: "Organization"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>; }; ... 11 more ...; updatedAt: PgColumn<...>; }' is not assignable to parameter of type 'SelectedFields'.
Property '_' is incompatible with index signature.
for the ...contact part. What would be the correct syntax to do this? Thanks.
10 replies
TtRPC
Created by Bryan3 on 8/25/2023 in #❓-help
TRPC vanilla client load failed when called on mobile browser
Hi, I have created a vanilla client to use TRPC without hooks in a NextJS project:
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "~/server/api/root";
import SuperJSON from "superjson";

export const trpcClient = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: "http://localhost:3000/api/trpc",
}),
],
transformer: SuperJSON,
});
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "~/server/api/root";
import SuperJSON from "superjson";

export const trpcClient = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: "http://localhost:3000/api/trpc",
}),
],
transformer: SuperJSON,
});
When I call const res = await trpcClient.example.hello.query({ text: "123" }); It works on desktop, but when using a mobile browser (tested on iOS safari and chrome), the following error is returned with no additional information being logged:
Unhandled Runtime Error
TRPCClientError: Load failed
Unhandled Runtime Error
TRPCClientError: Load failed
Is the error an issue with how the vanilla client is created and how might I be able to fix it? Thanks for your help!
2 replies
TTCTheo's Typesafe Cult
Created by Bryan3 on 8/25/2023 in #questions
TRPC vanilla client load failed when called on mobile browser
Hi, I have created a vanilla client to use TRPC without hooks in a create-t3-app project:
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "~/server/api/root";
import SuperJSON from "superjson";

export const trpcClient = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: "http://localhost:3000/api/trpc",
}),
],
transformer: SuperJSON,
});
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "~/server/api/root";
import SuperJSON from "superjson";

export const trpcClient = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: "http://localhost:3000/api/trpc",
}),
],
transformer: SuperJSON,
});
When I call const res = await trpcClient.example.hello.query({ text: "123" }); It works on desktop, but when using a mobile browser (tested on iOS safari and chrome), the following error is returned with no additional information being logged:
Unhandled Runtime Error
TRPCClientError: Load failed
Unhandled Runtime Error
TRPCClientError: Load failed
Is the error an issue with how the vanilla client is created and how might I be able to fix it? Thanks.
6 replies
TTCTheo's Typesafe Cult
Created by Bryan3 on 7/21/2023 in #questions
Backend equivalent to Create T3 App
Hi everyone, is there a backend equivalent to create T3 app for example with express/typescript/eslint installed? Thanks.
16 replies
TTCTheo's Typesafe Cult
Created by Bryan3 on 11/25/2022 in #questions
How to display two divs in exact same position using tailwind
Hi everyone, what's the best way display two divs on top of each other in the exact same position using tailwind? I've found some tutorials that mention using grid-area: https://css-tricks.com/positioning-overlay-content-with-css-grid/#aa-the-overlay-grid-area But tailwind doesn't seem to support grid-area (found a library that extends it but not sure if there's a simpler way). Thanks for your help!
3 replies
TTCTheo's Typesafe Cult
Created by Bryan3 on 11/19/2022 in #questions
How to trigger NextJS Image fetch again if not loaded in 3 seconds
Hi, I'm fetching images from an unreliable gateway that sometimes require multiple tries (same URL) to load the image. Is there a way using Next Image/Future Image to trigger a fetch from the same src link again if it is still loading after 3 seconds or if the load has failed? Thanks for your help!
15 replies