maxfi
maxfi
XXata
Created by maxfi on 7/3/2024 in #help
Reverse links typescript
Hi there. I'm wondering if it's possible to read a ShoppingCart by it's id and also get all it's ShoppingCartLineItems in one query. I'm trying to avoid making multiple queries to the database. I've had a look at https://xata.io/blog/navigating-many-to-one and https://xata.io/docs/concepts/data-model#links-and-relationships but I'm still not sure how to do this. Schema:
{
"tables": [
{
"name": "ShoppingCarts",
"columns": [
{
"name": "customerId",
"type": "string"
}
],
"revLinks": [
{
"column": "shoppingCart",
"table": "Users"
},
{
"column": "shoppingCart",
"table": "ShoppingCartLineItems"
}
]
},
{
"name": "ShoppingCartLineItems",
"columns": [
{
"name": "shoppingCart",
"type": "link",
"link": {
"table": "ShoppingCarts"
}
},
{
"name": "productId",
"type": "string"
},
{
"name": "quantity",
"type": "int"
},
{
"name": "type",
"type": "string",
"defaultValue": "product"
}
]
}
]
}
{
"tables": [
{
"name": "ShoppingCarts",
"columns": [
{
"name": "customerId",
"type": "string"
}
],
"revLinks": [
{
"column": "shoppingCart",
"table": "Users"
},
{
"column": "shoppingCart",
"table": "ShoppingCartLineItems"
}
]
},
{
"name": "ShoppingCartLineItems",
"columns": [
{
"name": "shoppingCart",
"type": "link",
"link": {
"table": "ShoppingCarts"
}
},
{
"name": "productId",
"type": "string"
},
{
"name": "quantity",
"type": "int"
},
{
"name": "type",
"type": "string",
"defaultValue": "product"
}
]
}
]
}
What seems to work is:
const record = await xata.db.ShoppingCarts.select([{
name: "<-ShoppingCartLineItems.shoppingCart",
columns: ["productId", "quantity", "type"],
as: "lineItems"
}]).filter({ id: "rec_cno400v3e8os6tplq4jg"}).getFirstOrThrow()
const record = await xata.db.ShoppingCarts.select([{
name: "<-ShoppingCartLineItems.shoppingCart",
columns: ["productId", "quantity", "type"],
as: "lineItems"
}]).filter({ id: "rec_cno400v3e8os6tplq4jg"}).getFirstOrThrow()
However, record doesn't have a lineItems prop. 🤔
7 replies
XXata
Created by maxfi on 3/20/2024 in #help
Remix v2.8.1 (vite) on Vercel serverless function timeout when making xata db calls
The app is deploying properly and I can't see any issues in the runtime logs on Vercel. The serverless function (Node.js 20x) just timeouts after 60 seconds. Via console.logs I'm pretty sure it's related to a xata query. In the build logs I see the following warnings (not sure if this is related):
WARN: Failed to resolve dependency "kerberos"
WARN: Failed to resolve dependency "gcp-metadata"
WARN: Failed to resolve dependency "socks"
WARN: Failed to resolve dependency "snappy"
WARN: Failed to resolve dependency "aws4"
WARN: Failed to resolve dependency "mongodb-client-encryption"
WARN: Failed to resolve dependency "@mongodb-js/zstd"
WARN: Failed to resolve dependency "@aws-sdk/credential-providers"
WARN: Failed to resolve dependency "kerberos"
WARN: Failed to resolve dependency "gcp-metadata"
WARN: Failed to resolve dependency "socks"
WARN: Failed to resolve dependency "snappy"
WARN: Failed to resolve dependency "aws4"
WARN: Failed to resolve dependency "mongodb-client-encryption"
WARN: Failed to resolve dependency "@mongodb-js/zstd"
WARN: Failed to resolve dependency "@aws-sdk/credential-providers"
I've checked that process.env.XATA_API_KEY and process.env.XATA_BRANCH are defined in the serverless function (via console.log) and they are. I get the xata client like so: export const xata = getXataClient(); Potentiall other relavant parts of the Vercel build logs:
Vercel CLI 33.6.1
vite v5.1.6 building for production...
Vercel CLI 33.6.1
vite v5.1.6 building for production...
I'm using "@xata.io/client": "^0.29.3", in package.json. Any ideas how to further troubleshoot this? Thanks in advance!
27 replies
XXata
Created by maxfi on 2/19/2024 in #help
`toSerializable()` makes column types {orginal_type} | undefined
No description
14 replies