dsl

package
v1.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

service/base_service.go

Index

Constants

This section is empty.

Variables

View Source
var ZincClientObj = NewZincClient("http://192.168.1.200:4080", "admin", "admin")

Functions

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake 将驼峰命名转换为下划线命名

Types

type DslBaseService

type DslBaseService[T IDslBaseEntity] struct {
	DB    *ZincClient // GORM 数据库连接实例
	Model T           // 模型引用
}

DslBaseService 定义了一个通用的基础服务,提供了一些通用的字段和方法。

func NewDslBaseService

func NewDslBaseService[T IDslBaseEntity](db *ZincClient, model T) *DslBaseService[T]

NewDslBaseService 创建一个新的 DslBaseService 实例。

func (*DslBaseService[T]) BulkCreate

func (bs *DslBaseService[T]) BulkCreate(models []T) (int, error)

BulkCreate 实现批量创建

func (*DslBaseService[T]) BulkDelete

func (bs *DslBaseService[T]) BulkDelete(ids []string) (int, error)

Create 实现基础服务接口中的创建方法

func (*DslBaseService[T]) Create

func (bs *DslBaseService[T]) Create(model T) (*T, error)

Create 实现基础服务接口中的创建方法

func (*DslBaseService[T]) Delete

func (bs *DslBaseService[T]) Delete(id string) error

Delete 实现基础服务接口中的删除方法

func (*DslBaseService[T]) GetById

func (bs *DslBaseService[T]) GetById(id string) (*T, error)

Read 实现基础服务接口中的读取方法

func (*DslBaseService[T]) PageByDTO

func (bs *DslBaseService[T]) PageByDTO(queryDto interface{}, queryPage *QueryPage) ([]T, int, error)

func (*DslBaseService[T]) Update

func (bs *DslBaseService[T]) Update(id string, model T) (*T, error)

Update 实现基础服务接口中的更新方法

type ESResponse

type ESResponse struct {
	Hits Hits `json:"hits"`
}

type HitElement

type HitElement struct {
	Index  string                 `json:"_index"`
	Id     string                 `json:"_id"`
	Score  float64                `json:"_score"`
	Source map[string]interface{} `json:"_source"`
}

type Hits

type Hits struct {
	Total    TotalHits    `json:"total"`
	MaxScore float64      `json:"max_score"`
	Hits     []HitElement `json:"hits"`
}

type IDSLDao

type IDSLDao interface {
	BulkCreate(indexName string, docs []map[string]interface{}) error
	BulkDelete(indexName string, ids []string) error
	Create(indexName string, doc interface{}) error
	Search(indexName string, query interface{}) ([]byte, error)
	Update(indexName, id string, update interface{}) error
	Delete(indexName, id string) error
	// PageByDTO(indexName string, dto map[string]string, pageNum, pageSize int) (*ESResponse, int, error)
	PageByDTO(queryDto interface{}, queryPage *QueryPage) (*ESResponse, int, error)
}

type IDslBaseEntity

type IDslBaseEntity interface {
	TableName() string
	BeforeCreate(id int64) any
}

type QueryPage

type QueryPage struct {
	Current int      `json:"current" form:"current"`
	Size    int      `json:"size" form:"size"`
	Ascs    []string `json:"ascs" form:"ascs"`
	Descs   []string `json:"descs" form:"descs"`
}

type TotalHits

type TotalHits struct {
	Value    int    `json:"value"`
	Relation string `json:"relation,omitempty"` // 可选,用于区分是否确切计数(如"eq"表示等于)
}

type ZincClient

type ZincClient struct {
	Host     string
	Username string
	Password string
}

ZincClient 代表与ZincSearch交互的客户端

func NewZincClient

func NewZincClient(host, username, password string) *ZincClient

NewZincClient 创建一个新的ZincSearch客户端实例

func (*ZincClient) BulkCreate

func (zc *ZincClient) BulkCreate(indexName string, docs []map[string]interface{}) error

修改后的 BulkCreateDocuments 方法直接接受 []map[string]interface{}

func (*ZincClient) BulkDelete

func (zc *ZincClient) BulkDelete(indexName string, ids []string) error

BulkDeleteDocuments 批量删除指定索引中的文档

func (*ZincClient) Create

func (zc *ZincClient) Create(indexName string, doc interface{}) error

CreateDocument 向指定索引添加文档

func (*ZincClient) CreateWithId

func (zc *ZincClient) CreateWithId(indexName string, doc interface{}, id int64) error

CreateDocument 向指定索引添加文档

func (*ZincClient) Delete

func (zc *ZincClient) Delete(indexName, id string) error

DeleteDocument 删除指定索引中的文档

func (*ZincClient) PageByDTO

func (zc *ZincClient) PageByDTO(indexName string, dto any, queryPage QueryPage) (*ESResponse, int, error)

func (*ZincClient) Search

func (zc *ZincClient) Search(indexName string, query interface{}) ([]byte, error)

SearchDocuments 在指定索引中搜索文档

func (*ZincClient) Update

func (zc *ZincClient) Update(indexName, id string, update interface{}) error

UpdateDocument 更新指定索引中的文档

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL