1.0.9 • Published 2 months ago

@maogo/milvus v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

该组件为midayjs的milvus ORM组件

安装@maogo/milvus

$ npm i @maogo/milvus

启用组件

// src/configuration.ts
import * as milvus from '@maogo/milvus';
@Configuration({
  imports: [
    milvus,
    {
      component: info,
      enabledEnvironment: ['local'],
    },
  ],
  importConfigs: [join(__dirname, './config')],
})

配置组件

// src/config/config.default.ts
import * as milvus from '@maogo/milvus';

export default {
  milvus: {
    dataSource: {
      default: {
        host: 'localhost',
        port: '19530',
        username: 'root',
        password: '',
        ssl: false,
        token: '',
        entities: ['entity'],
        database: 'book',
      },
    },
  },
}

创建实体类

// src/entity/book.ts
import { DataType, Column, PrimaryColumn, Entity } from '@maogo/milvus';

@Entity('Book', {
  indexParams: {
    field_name: 'intro',
    extra_params: {
      index_type: 'AUTOINDEX',
      metric_type: 'L2',
    },
  },
})
export class Book {
  @PrimaryColumn({ dataType: DataType.Int64 })
  id: number;

  @Column({ dataType: DataType.FloatVector, dim: 2 })
  intro: string;

  @Column({ dataType: DataType.VarChar, maxLength: 256 })
  name: string;
}

注入实体类并实现milvus的增删改查

import { Provide } from '@midwayjs/core';
import { InjectEntityModel, Repository } from '@maogo/milvus';
import { Book } from '../entity/book';

@Provide()
export class APiService {
  @InjectEntityModel(Book)
  bookModel: Repository<Book>;

  // 新增数据
  insert() {
    this.bookModel.insert({
      partition_name: '', // 分区名称,不传时默认未defalut
      fields_data: []
    })
  }

  // 插入数据
  insert() {
    this.bookModel.insert({
      partition_name: '', // 分区名称,不传时默认未defalut
      fields_data: []
    })
  }

  // 删除数据
  delete() {
    this.bookModel.delete({
      expr: '',
      partition_name: ''
    })
  }

  // 查询数据
  search() {
    this.bookModel.search({})
  }

  // 检索数据
  query() {
    this.bookModel.query({})
  }

  // 创建分区
  createPartition() {
    this.bookModel.createPartition({
      partition_name: '', // 分区名称
    })
  }
}
1.0.9

2 months ago

1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.2

3 months ago

1.0.3

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago