Field.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { DataTypeStringEnum } 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!: DataTypeStringEnum;
  6. fieldID!: string;
  7. type_params!: { key: string; value: string }[];
  8. is_primary_key!: true;
  9. name!: string;
  10. description!: string;
  11. autoID!: boolean;
  12. constructor(props: {}) {
  13. super(props);
  14. Object.assign(this, props);
  15. }
  16. static async getFields(collectionName: string): Promise<FieldHttp[]> {
  17. const path = `/collections/${collectionName}`;
  18. const res = await super.findAll({
  19. path,
  20. params: {},
  21. });
  22. return res.schema.fields.map((f: any) => new this(f));
  23. }
  24. get _fieldId() {
  25. return this.fieldID;
  26. }
  27. get _isPrimaryKey() {
  28. return this.is_primary_key;
  29. }
  30. get _isAutoId() {
  31. return this.autoID;
  32. }
  33. get _fieldName() {
  34. return this.name;
  35. }
  36. get _fieldType() {
  37. return this.data_type;
  38. }
  39. get _desc() {
  40. return this.description || '--';
  41. }
  42. get _dimension() {
  43. return this.type_params.find(item => item.key === 'dim')?.value || '--';
  44. }
  45. }