123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import { ChildrenStatusType, StatusEnum } from '../components/status/Types';
- import { CollectionView, InsertDataParam } from '../pages/collections/Types';
- import { Field } from '../pages/schema/Types';
- import { VectorSearchParam } from '../pages/seach/Types';
- import { IndexState, ShowCollectionsType } from '../types/Milvus';
- import { formatNumber } from '../utils/Common';
- import BaseModel from './BaseModel';
- import { FieldHttp } from './Field';
- import dayjs from 'dayjs';
- export class CollectionHttp extends BaseModel implements CollectionView {
- private autoID!: string;
- private collection_name!: string;
- private description!: string;
- private rowCount!: string;
- private index_status!: string;
- private id!: string;
- private isLoaded!: boolean;
- private createdTime!: string;
- private schema!: {
- fields: Field[];
- };
- static COLLECTIONS_URL = '/collections';
- static COLLECTIONS_INDEX_STATUS_URL = '/collections/indexes/status';
- static COLLECTIONS_STATISTICS_URL = '/collections/statistics';
- static CHECK_URL = '/milvus/check';
- constructor(props: CollectionView) {
- super(props);
- Object.assign(this, props);
- }
- static getCollections(data?: {
- type: ShowCollectionsType;
- }): Promise<CollectionHttp[]> {
- return super.findAll({ path: this.COLLECTIONS_URL, params: data || {} });
- }
- static getCollection(name: string) {
- return super.search({
- path: `${this.COLLECTIONS_URL}/${name}`,
- params: {},
- });
- }
- static createCollection(data: any) {
- return super.create({ path: this.COLLECTIONS_URL, data });
- }
- static getCollectionsIndexState(): Promise<CollectionHttp[]> {
- return super.findAll({
- path: this.COLLECTIONS_INDEX_STATUS_URL,
- params: {},
- });
- }
- static deleteCollection(collectionName: string) {
- return super.delete({ path: `${this.COLLECTIONS_URL}/${collectionName}` });
- }
- static loadCollection(collectionName: string) {
- return super.update({
- path: `${this.COLLECTIONS_URL}/${collectionName}/load`,
- });
- }
- static releaseCollection(collectionName: string) {
- return super.update({
- path: `${this.COLLECTIONS_URL}/${collectionName}/release`,
- });
- }
- static getStatistics() {
- return super.search({ path: this.COLLECTIONS_STATISTICS_URL, params: {} });
- }
- static insertData(collectionName: string, param: InsertDataParam) {
- return super.create({
- path: `${this.COLLECTIONS_URL}/${collectionName}/insert`,
- data: param,
- });
- }
- static vectorSearchData(collectionName: string, params: VectorSearchParam) {
- return super.vectorSearch({
- path: `${this.COLLECTIONS_URL}/${collectionName}/search`,
- data: params,
- });
- }
- get _autoId() {
- return this.autoID;
- }
- get _desc() {
- return this.description || '--';
- }
- get _id() {
- return this.id;
- }
- get _name() {
- return this.collection_name;
- }
- get _rowCount() {
- return formatNumber(Number(this.rowCount));
- }
- get _isLoaded() {
- return this.isLoaded;
- }
- get _status() {
- return this.isLoaded === true ? StatusEnum.loaded : StatusEnum.unloaded;
- }
- get _fields() {
- return this.schema.fields.map(f => new FieldHttp(f));
- }
- get _indexState() {
- switch (this.index_status) {
- case IndexState.InProgress:
- return ChildrenStatusType.CREATING;
- case IndexState.Failed:
- return ChildrenStatusType.ERROR;
- default:
- return ChildrenStatusType.FINISH;
- }
- }
- // Befor milvus-2.0-rc3 will return '0'.
- // If milvus is stable, we can remote this condition/
- get _createdTime(): string {
- return this.createdTime && this.createdTime !== '0'
- ? dayjs(Number(this.createdTime)).format('YYYY-MM-DD HH:mm:ss')
- : '';
- }
- }
|