Field.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { DataType } from '../pages/collections/Types';
  2. import { FieldData } from '../pages/schema/Types';
  3. import BaseModel from './BaseModel';
  4. export class FieldHttp extends BaseModel implements FieldData {
  5. data_type!: DataType;
  6. fieldID!: string;
  7. type_params!: { key: string; value: string }[];
  8. is_primary_key!: true;
  9. name!: string;
  10. description!: string;
  11. constructor(props: {}) {
  12. super(props);
  13. Object.assign(this, props);
  14. }
  15. static async getFields(collectionName: string): Promise<FieldHttp[]> {
  16. const path = `/collections/${collectionName}`;
  17. const res = await super.findAll({
  18. path,
  19. params: {},
  20. });
  21. return res.schema.fields.map((f: any) => new this(f));
  22. }
  23. get _fieldId() {
  24. return this.fieldID;
  25. }
  26. get _isPrimaryKey() {
  27. return this.is_primary_key;
  28. }
  29. get _fieldName() {
  30. return this.name;
  31. }
  32. get _fieldType() {
  33. return this.data_type;
  34. }
  35. get _desc() {
  36. return this.description || '--';
  37. }
  38. get _dimension() {
  39. return this.type_params.find(item => item.key === 'dim')?.value || '--';
  40. }
  41. }