mindsdb / mindsdb-js-sdk

Official JavaScript SDK for MindsDB
MIT License
19 stars 23 forks source link

Rewrite Docs (and README) with MindsDB.default? #40

Closed MinuraPunchihewa closed 1 year ago

MinuraPunchihewa commented 1 year ago

When using the SDK, I have always been required to use MindsDB.default. to execute any sort of operation. Anytime I tried running a command by simply using MindsDB., I have run into errors such as the following, TypeError: MindsDB.connect is not a function

Is this the new syntax that works? If so, should the docs be rewritten as such?

tmichaeldb commented 1 year ago

The docs use the ES6 modules syntax import MindsDB from 'mindsdb-js-sdk', which does not require you to use MindsDB.default. If you use CommonJS require... then you will need to use MindsDB.default due to how the SDK is bundled.

It could be helpful to mention in the docs if you're using require... then you need to access the functions MindsDB.default though. I did that here

MinuraPunchihewa commented 1 year ago

Hey @tmichaeldb, Thank you for your response. I am not a JavaScript expert by any means, but I believe this did not work for me using ES6 syntax either.

Can you help me out here?

This is the code I have been working on. I am looking to create a NPM package, https://github.com/MinuraPunchihewa/the-issue-is/tree/feature/github_issue_creator_npm_pkg

This is the project where I came across the other issue we have been discussing as well.

ra-jeev commented 1 year ago

Hey @MinuraPunchihewa, I was trying to use the SDK in a Nuxt3 app (server side) and getting the same error. So how to resolve that?

EDIT: Just now saw the repo you've linked to. It uses MindsDB.default everywhere even though the ES6 import syntax is being used. And guess what, it works for my issue as well. Just now tested it, and was able to connect to my local mindsDB docker instance.

MinuraPunchihewa commented 1 year ago

Hey @ra-jeev, Yes, I had to use MindsDB.default to get it to work.

ra-jeev commented 1 year ago

Moreover, you can't do MindsDB.default if by any chance you're using Typescript as it starts complaining

"Property 'default' does not exist on type '{ connect: (options: ConnectionOptions) => Promise<void>; SQL: SqlRestApiClient; Databases: DatabasesRestApiClient; Models: ModelsRestApiClient; Projects: ProjectsRestApiClient; Tables: TablesRestApiClient; Views: ViewsRestApiClient; }'."