const { data: products } = useLiveQuery((q) => {
let products = q.from({ tried: triedsCollection })
.innerJoin({ product: productsCollection }, ({ product, tried }) => eq(product.id, tried.productId))
.orderBy(({ tried }) => tried.createdAt, "desc")
.select(({ tried, product }) => ({
id: product.id,
name: product.name,
upcId: product.upcId,
note: tried.note,
triedAt: tried.createdAt,
}))
return q.from({ productBrand: productBrandsCollection })
.innerJoin({ product: products }, ({ product, productBrand }) => eq(productBrand.productId, product.id))
.innerJoin({ brand: brandsCollection }, ({ brand, productBrand }) => eq(brand.id, productBrand.brandId))
.fn.select(({ product, brand, productBrand }) => ({
...product,
// brands: productBrand,
brand: [brand?.name]
}))
})
const { data: products } = useLiveQuery((q) => {
let products = q.from({ tried: triedsCollection })
.innerJoin({ product: productsCollection }, ({ product, tried }) => eq(product.id, tried.productId))
.orderBy(({ tried }) => tried.createdAt, "desc")
.select(({ tried, product }) => ({
id: product.id,
name: product.name,
upcId: product.upcId,
note: tried.note,
triedAt: tried.createdAt,
}))
return q.from({ productBrand: productBrandsCollection })
.innerJoin({ product: products }, ({ product, productBrand }) => eq(productBrand.productId, product.id))
.innerJoin({ brand: brandsCollection }, ({ brand, productBrand }) => eq(brand.id, productBrand.brandId))
.fn.select(({ product, brand, productBrand }) => ({
...product,
// brands: productBrand,
brand: [brand?.name]
}))
})