TanStackT
TanStack5d ago
10 replies
standard-azure

Live Query No data

im using drizzle + neon + tanstack db + electric sql (cloud)
and this as ref: https://github.com/electric-sql/electric/tree/main/examples/tanstack-db-web-starter

// schemax.tsx

export const users = pgTable("users", {
    id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "users_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
    discordUserId: varchar("discord_user_id", { length: 100 }).notNull(),
    createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
    updatedAt: timestamp("updated_at", { mode: 'string' }),
}, (table) => [
    unique("users_discord_user_id_key").on(table.discordUserId),
]);

export const selectUserSchema = createSelectSchema(users);


the i create the collection
export const userCollection = createCollection(
  electricCollectionOptions({
    id: "users",
    schema: selectUserSchema,
    getKey: (user) => {console.log(user); return user.id as number},
    shapeOptions: {
      url: new URL("/api/users", typeof window !== `undefined`
          ? window.location.origin
          : `http://localhost:3000`).toString(),
      columnMapper: snakeCamelMapper(),
      
    },
  })
)


then in my component
const data = useLiveQuery(
    (q) => q.from({users: userCollection}).limit(5).orderBy(data => data.users.createdAt )
  , []);


the data appears to be empty
GitHub
Real-time sync for Postgres. Contribute to electric-sql/electric development by creating an account on GitHub.
electric/examples/tanstack-db-web-starter at main · electric-sql/e...
Was this page helpful?