weaviate / typescript-client

Official Weaviate TypeScript Client
https://www.npmjs.com/package/weaviate-client
BSD 3-Clause "New" or "Revised" License
65 stars 23 forks source link

Add method to check if class exists #70

Closed tsmith023 closed 1 year ago

tsmith023 commented 1 year ago

This PR introduces a method to the schema property of client that checks for the existence of a class within the database by its className.

In an effort to keep the implementation decoupled but logical, the ClassExists builder class is introduced that conforms to the logic of other builder classes within the src/schema/ directory. The do() method of this class is, however, abstracted away from the end user such that they only access:

const exists: boolean = await client
  .schema
  .exists('MyClass')

without the added overhead and complexity of making many builder calls to achieve the result. This was done to conform with the previously raised issue: https://github.com/weaviate/typescript-client/issues/16.

The implementation simply calls the /schema endpoint of the Weaviate REST API and uses the .some() Array.prototype method to compare the returned classes property with the provided className.

@dirkkul :grin:

weaviate-git-bot commented 1 year ago

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Slack channel?

tsmith023 commented 1 year ago

@weaviate-git-bot I agree with the Weaviate CLA