Collection.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { ChildrenStatusType, StatusEnum } from '../components/status/Types';
  2. import { CollectionView } from '../pages/collections/Types';
  3. import { IndexState } from '../types/Milvus';
  4. import BaseModel from './BaseModel';
  5. export class CollectionHttp extends BaseModel implements CollectionView {
  6. private autoID!: string;
  7. private collection_name!: string;
  8. private description!: string;
  9. private rowCount!: string;
  10. private index_status!: string;
  11. static COLLECTIONS_URL = '/collections';
  12. static COLLECTIONS_INDEX_STATUS_URL = '/collections/indexes/status';
  13. static CHECK_URL = '/milvus/check';
  14. constructor(props: CollectionView) {
  15. super(props);
  16. Object.assign(this, props);
  17. }
  18. static getCollections(): Promise<CollectionHttp[]> {
  19. return super.findAll({ path: this.COLLECTIONS_URL, params: {} });
  20. }
  21. static createCollection(data: any) {
  22. return super.create({ path: this.COLLECTIONS_URL, data });
  23. }
  24. static getCollectionsIndexState(): Promise<CollectionHttp[]> {
  25. return super.findAll({
  26. path: this.COLLECTIONS_INDEX_STATUS_URL,
  27. params: {},
  28. });
  29. }
  30. static deleteCollection(collectionName: string) {
  31. return super.delete({ path: `${this.COLLECTIONS_URL}/${collectionName}` });
  32. }
  33. static loadCollection(collectionName: string) {
  34. return super.update({
  35. path: `${this.COLLECTIONS_URL}/${collectionName}/load`,
  36. });
  37. }
  38. static releaseCollection(collectionName: string) {
  39. return super.update({
  40. path: `${this.COLLECTIONS_URL}/${collectionName}/release`,
  41. });
  42. }
  43. get _autoId() {
  44. return this.autoID;
  45. }
  46. get _desc() {
  47. return this.description;
  48. }
  49. get _id() {
  50. return '12';
  51. }
  52. get _name() {
  53. return this.collection_name;
  54. }
  55. get _rowCount() {
  56. return this.rowCount;
  57. }
  58. get _status() {
  59. return StatusEnum.loaded;
  60. }
  61. get _indexState() {
  62. switch (this.index_status) {
  63. case IndexState.InProgress:
  64. return ChildrenStatusType.CREATING;
  65. case IndexState.Failed:
  66. return ChildrenStatusType.ERROR;
  67. default:
  68. return ChildrenStatusType.FINISH;
  69. }
  70. }
  71. }