T
TanStack10h ago
fair-rose

Not getting db updates live?

Trying to get an initial version of this working with Electric - when using their useShape hook I get my reactive updates as I need, however I have been trying to get this working with TanstackDB but while the initial sync does work but I get no live updates. I am happy to tempoarily provide access to a branch for debugging. I am querying across collections:
const jobsWithClientAndLocation = q
.from({ job: scheduleCollections.jobs })
.innerJoin({ client: scheduleCollections.clients }, ({ job, client }) =>
eq(client.id, job.client_id),
)
.leftJoin(
{ location: scheduleCollections.locations },
({ job, location }) => eq(location.id, job.location_id),
)
.select(({ job, client, location }) => ({
job,
client,
location,
}));

return (
q
.from({ placement: placementsCol })
.innerJoin(
{ jobData: jobsWithClientAndLocation },
({ placement, jobData }) => eq(jobData.job.id, placement.job_id),
)
// Placement Relations continued
.innerJoin(
{ jobTitle: scheduleCollections.jobTitles },
({ placement, jobTitle }) => eq(jobTitle.id, placement.job_title_id),
)
.leftJoin(
{ operative: scheduleCollections.operatives },
({ placement, operative }) =>
eq(operative.id, placement.operative_id),
)
.leftJoin(
{ supplier: scheduleCollections.suppliers },
({ placement, supplier }) => eq(supplier.id, placement.supplier_id),
)
.leftJoin(
{ supplierOperative: scheduleCollections.supplierOperatives },
({ placement, supplierOperative }) =>
eq(supplierOperative.id, placement.supplier_operative_id),
)
.orderBy(({ placement }) => placement.id)
const jobsWithClientAndLocation = q
.from({ job: scheduleCollections.jobs })
.innerJoin({ client: scheduleCollections.clients }, ({ job, client }) =>
eq(client.id, job.client_id),
)
.leftJoin(
{ location: scheduleCollections.locations },
({ job, location }) => eq(location.id, job.location_id),
)
.select(({ job, client, location }) => ({
job,
client,
location,
}));

return (
q
.from({ placement: placementsCol })
.innerJoin(
{ jobData: jobsWithClientAndLocation },
({ placement, jobData }) => eq(jobData.job.id, placement.job_id),
)
// Placement Relations continued
.innerJoin(
{ jobTitle: scheduleCollections.jobTitles },
({ placement, jobTitle }) => eq(jobTitle.id, placement.job_title_id),
)
.leftJoin(
{ operative: scheduleCollections.operatives },
({ placement, operative }) =>
eq(operative.id, placement.operative_id),
)
.leftJoin(
{ supplier: scheduleCollections.suppliers },
({ placement, supplier }) => eq(supplier.id, placement.supplier_id),
)
.leftJoin(
{ supplierOperative: scheduleCollections.supplierOperatives },
({ placement, supplierOperative }) =>
eq(supplierOperative.id, placement.supplier_operative_id),
)
.orderBy(({ placement }) => placement.id)
2 Replies
fair-rose
fair-roseOP10h ago
I've created the collections as per the examples:
const placementsCollection = (start: Date, end: Date) =>
createCollection(
electricCollectionOptions({
schema: scheduleSchemas.placement,
id: "placements-collection-sync",
getKey: (r) => r.id,
shapeOptions: {
url: `${SHAPE_URL}/placement`,
params: {
table: "placement",
where: "start_time between $1 and $2",
params: [
formatDate(start, "yyyy-MM-dd HH:mm:ss+00"),
formatDate(end, "yyyy-MM-dd HH:mm:ss+00"),
],
},
parser: {
timestamptz: (date: string) => {
return new Date(date);
},
},
},
}),
);
const placementsCollection = (start: Date, end: Date) =>
createCollection(
electricCollectionOptions({
schema: scheduleSchemas.placement,
id: "placements-collection-sync",
getKey: (r) => r.id,
shapeOptions: {
url: `${SHAPE_URL}/placement`,
params: {
table: "placement",
where: "start_time between $1 and $2",
params: [
formatDate(start, "yyyy-MM-dd HH:mm:ss+00"),
formatDate(end, "yyyy-MM-dd HH:mm:ss+00"),
],
},
parser: {
timestamptz: (date: string) => {
return new Date(date);
},
},
},
}),
);
Basically I am writing a change to the db via SQL - previously this would update ~instantly but I'm not seeing anything. Am I missing an option?
genetic-orange
genetic-orange10h ago
there was a new release today with some bug fixes — could you try upgrading to see if that helps?

Did you find this page helpful?