kamama
kamama
Explore posts from servers
DTDrizzle Team
Created by kamama on 10/14/2023 in #help
one to many same table diff column
export const users = pgTable('users', {
id: bigserial('id', { mode: 'bigint' }).primaryKey()
})

export const usersRelations = relations(users, ({ many, one }) => ({
froms: many(explorers, { relationName: 'froms' }),
tos: many(explorers, { relationName: 'tos' })
}))

export const explorers = pgTable('explorers', {
id: uuid('id')
.primaryKey()
.default(sql`gen_random_uuid()`),
fromId: bigserial('from_id', { mode: 'bigint' }).references(
() => users.id
),
toId: bigserial('to_id', { mode: 'bigint' }).references(() => users.id),
createdAt: timestamp('created_at').defaultNow()
})

export const explorersRelations = relations(explorers, ({ one, many }) => ({
from: one(users, {
references: [users.id],
fields: [explorers.fromId]
}),
to: one(users, {
references: [users.id],
fields: [explorers.toId]
})
}))
export const users = pgTable('users', {
id: bigserial('id', { mode: 'bigint' }).primaryKey()
})

export const usersRelations = relations(users, ({ many, one }) => ({
froms: many(explorers, { relationName: 'froms' }),
tos: many(explorers, { relationName: 'tos' })
}))

export const explorers = pgTable('explorers', {
id: uuid('id')
.primaryKey()
.default(sql`gen_random_uuid()`),
fromId: bigserial('from_id', { mode: 'bigint' }).references(
() => users.id
),
toId: bigserial('to_id', { mode: 'bigint' }).references(() => users.id),
createdAt: timestamp('created_at').defaultNow()
})

export const explorersRelations = relations(explorers, ({ one, many }) => ({
from: one(users, {
references: [users.id],
fields: [explorers.fromId]
}),
to: one(users, {
references: [users.id],
fields: [explorers.toId]
})
}))
db.query.users.findMany({
with: {
froms: true,
tos: true
}
})

// error: There is not enough information to infer relation
db.query.users.findMany({
with: {
froms: true,
tos: true
}
})

// error: There is not enough information to infer relation
is there any possible solution to infer the relation in usersRelations?
1 replies
TtRPC
Created by kamama on 10/8/2023 in #❓-help
How to update query data after mutation
Any idea?
2 replies
TtRPC
Created by kamama on 9/29/2023 in #❓-help
trpc subscription with react-query
TRPCClientError: Subscriptions should use wsLink having error when use subscription with react-query import { createTRPCReact } from "@trpc/react-query"; export const trpc = createTRPCReact<AppRouter>(); const wsClient = createWSClient({ url: ws://localhost:8080/ws, }); const trpcClient = trpc.createClient({ transformer: SuperJSON, links: [ httpLink({ url: /trpc, }), wsLink({ client: wsClient, }), ], }); <trpc.Provider client={trpcClient} queryClient={queryClient}> <QueryClientProvider client={queryClient}> </QueryClientProvider> </trpc.Provider>
3 replies