Problems setting up Drizzle ORM with HTTP client via client/cli@ne

Hi, I'm having some trouble setting up the drizzle ORM with http client. In particular following https://xata.io/docs/integrations/drizzle, I'm running yarn add @xata.io/client@next and I also have the following version of the cli installed: @xata.io/cli/0.0.0-next.v64f10283eb9a098c575590d3ea17600e350321c9 However, when I run xata init, one of the steps is overwriting the xata client version in package.json to "@xata.io/client": "^0.30.0", Then the generated xata.ts has an error:
'"@xata.io/client"' has no exported member named 'getDeployPreviewBranch'. Did you mean 'getPreviewBranch'?`
'"@xata.io/client"' has no exported member named 'getDeployPreviewBranch'. Did you mean 'getPreviewBranch'?`
This error gets fixed if then I reinstall the next version of the xata client, however the generated xata.ts file also doesn't export (or even define) getXataClient, which is required by the setup in the guide https://xata.io/docs/integrations/drizzle, ie. it says:
import { drizzle } from 'drizzle-orm/xata-http';
import { getXataClient } from './xata'; // Generated client

const xata = getXataClient();
const db = drizzle(xata);
import { drizzle } from 'drizzle-orm/xata-http';
import { getXataClient } from './xata'; // Generated client

const xata = getXataClient();
const db = drizzle(xata);
Any help getting xata to work with Drizzle orm would be much appreciated.
11 Replies
tsg
tsg3mo ago
hi, thanks for reporting, I think you might have hit a bug mixing @next and @latest installations of the CLI and SDK. We're able to reproduce it and we're working on a fix. In the meantime, could you try the following workaround: * manually edit the package.json and remove the xata dependency. Also remove references to the xata generated files. * double-check that the xata CLI version is cli@next * run xata init again This should hopefully result in having the @next version of the SDK installed and a correctly generated xata.ts
Adam Harris
Adam HarrisOP3mo ago
Hi @tsg thanks very much for your quick response! I followed your steps and this does result in having the correctly installed @next sdk, and the generated xata.ts now has no import errors. However the generated xata.ts still doesn't define getXataClient... Do you have a suggested workaround for this?
tsg
tsg3mo ago
yeah, getXataClient doesn't do that much actually. You can instantiate it directly like this:
new XataClient({
apiKey: 'xx',
databaseURL: 'xx',
branch: 'xx'
}
new XataClient({
apiKey: 'xx',
databaseURL: 'xx',
branch: 'xx'
}
There is an example of doing this here: https://xata.io/docs/sdk/typescript/overview#configuration
TypeScript SDK for Xata
Use the SDK as a schema-based, schema-less, or an API client
Adam Harris
Adam HarrisOP3mo ago
@tsg great - that’s what I resorted to, thanks very much for the clarification!
tsg
tsg3mo ago
great, I'll ping you back when the proper fix is in place.
Adam Harris
Adam HarrisOP3mo ago
Hi @tsg just wondering if there has been any progress with this (or eg do you have a github issue that I can watch) ? We just switched to using pnpm in our monorepo and the issue has come back. We are currently stuck until this is fixed... Our package.json looks like this:
"@xata.io/cli": "^0.0.0-next.veed33633c02b9411aecf8f69d8c94071c9257c12",
"@xata.io/client": "^0.0.0-next.veed33633c02b9411aecf8f69d8c94071c9257c12"
"@xata.io/cli": "^0.0.0-next.veed33633c02b9411aecf8f69d8c94071c9257c12",
"@xata.io/client": "^0.0.0-next.veed33633c02b9411aecf8f69d8c94071c9257c12"
tsg
tsg3mo ago
Checking with the team, I thought it would be fixed
Adam Harris
Adam HarrisOP3mo ago
@tsg basically, even with the @xata/io/client@next version in the package.json, we're still getting errors of the form ts: '"@xata.io/client"' has no exported member named 'getDeployPreviewBranch'. Did you mean 'getPreviewBranch'? in xata.ts
tsg
tsg3mo ago
so if you repeat the steps above you still get the broken xata.ts? I was trying it now with the latest, which is:
"@xata.io/cli": "^0.0.0-next.v00a8db0907874a98615e1ea749c1237e6bbbac42",
"@xata.io/client": "^0.0.0-next.v00a8db0907874a98615e1ea749c1237e6bbbac42",
"@xata.io/cli": "^0.0.0-next.v00a8db0907874a98615e1ea749c1237e6bbbac42",
"@xata.io/client": "^0.0.0-next.v00a8db0907874a98615e1ea749c1237e6bbbac42",
And seemed to work. Basically what I did:
# upgrade to latest CLI
npm i -g @xata.io/cli@next

# version should be 0.0.0-next.v00a8db0907874a98615e1ea749c1237e6bbbac42
xata --version

# edit package.json and remove references to client and cli

# reinstall them and re-create xata.ts
# xata init --force
# upgrade to latest CLI
npm i -g @xata.io/cli@next

# version should be 0.0.0-next.v00a8db0907874a98615e1ea749c1237e6bbbac42
xata --version

# edit package.json and remove references to client and cli

# reinstall them and re-create xata.ts
# xata init --force
The xata.ts seems to compile fine.
Adam Harris
Adam HarrisOP3mo ago
@tsg thanks for the confirmation - it seems that the generated xata.ts was pointing to a previous (next) version of the @Xata.io/client. So when I followed your instructions (in addition to clearing out the node_modules) the type error has gone away. thanks again for your help! 👍
tsg
tsg3mo ago
ah good, thanks for the update! Let us know if it shows up again
Want results from more Discord servers?
Add your server