Field.ts 1.4 KB

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