146 lines
4.1 KiB
Go
146 lines
4.1 KiB
Go
package types
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// Document 表示一个文档记录
|
|
type Document struct {
|
|
ID string `json:"_id"`
|
|
Data map[string]interface{} `json:"data"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// Filter 查询过滤条件
|
|
type Filter map[string]interface{}
|
|
|
|
// Update 更新操作
|
|
type Update struct {
|
|
Set map[string]interface{} `json:"$set,omitempty"`
|
|
Unset map[string]interface{} `json:"$unset,omitempty"`
|
|
Inc map[string]interface{} `json:"$inc,omitempty"`
|
|
Mul map[string]interface{} `json:"$mul,omitempty"`
|
|
Push map[string]interface{} `json:"$push,omitempty"`
|
|
Pull map[string]interface{} `json:"$pull,omitempty"`
|
|
Min map[string]interface{} `json:"$min,omitempty"`
|
|
Max map[string]interface{} `json:"$max,omitempty"`
|
|
Rename map[string]string `json:"$rename,omitempty"`
|
|
CurrentDate map[string]interface{} `json:"$currentDate,omitempty"`
|
|
AddToSet map[string]interface{} `json:"$addToSet,omitempty"`
|
|
Pop map[string]int `json:"$pop,omitempty"`
|
|
PullAll map[string][]interface{} `json:"$pullAll,omitempty"`
|
|
SetOnInsert map[string]interface{} `json:"$setOnInsert,omitempty"`
|
|
}
|
|
|
|
// Projection 投影配置
|
|
type Projection map[string]interface{}
|
|
|
|
// Sort 排序配置
|
|
type Sort map[string]int
|
|
|
|
// AggregateStage 聚合管道阶段
|
|
type AggregateStage struct {
|
|
Stage string `json:"stage"` // $match, $group, etc.
|
|
Spec interface{} `json:"spec"`
|
|
}
|
|
|
|
// FindRequest 查询请求
|
|
type FindRequest struct {
|
|
Filter Filter `json:"filter,omitempty"`
|
|
Projection Projection `json:"projection,omitempty"`
|
|
Sort Sort `json:"sort,omitempty"`
|
|
Skip int `json:"skip,omitempty"`
|
|
Limit int `json:"limit,omitempty"`
|
|
BatchSize int `json:"batchSize,omitempty"`
|
|
}
|
|
|
|
// InsertRequest 插入请求
|
|
type InsertRequest struct {
|
|
Documents []map[string]interface{} `json:"documents"`
|
|
Ordered bool `json:"ordered,omitempty"`
|
|
}
|
|
|
|
// UpdateRequest 更新请求
|
|
type UpdateRequest struct {
|
|
Updates []UpdateOperation `json:"updates"`
|
|
}
|
|
|
|
// UpdateOperation 单个更新操作
|
|
type UpdateOperation struct {
|
|
Q Filter `json:"q"`
|
|
U Update `json:"u"`
|
|
Upsert bool `json:"upsert,omitempty"`
|
|
Multi bool `json:"multi,omitempty"`
|
|
}
|
|
|
|
// DeleteRequest 删除请求
|
|
type DeleteRequest struct {
|
|
Deletes []DeleteOperation `json:"deletes"`
|
|
}
|
|
|
|
// DeleteOperation 单个删除操作
|
|
type DeleteOperation struct {
|
|
Q Filter `json:"q"`
|
|
Limit int `json:"limit"` // 0 = delete all, 1 = delete one
|
|
}
|
|
|
|
// AggregateRequest 聚合请求
|
|
type AggregateRequest struct {
|
|
Pipeline []AggregateStage `json:"pipeline"`
|
|
}
|
|
|
|
// Response 通用响应
|
|
type Response struct {
|
|
OK int `json:"ok"`
|
|
Cursor *Cursor `json:"cursor,omitempty"`
|
|
N int `json:"n,omitempty"`
|
|
Modified int `json:"nModified,omitempty"`
|
|
Upserted []UpsertID `json:"upserted,omitempty"`
|
|
Error string `json:"errmsg,omitempty"`
|
|
Code int `json:"code,omitempty"`
|
|
}
|
|
|
|
// Cursor 游标响应
|
|
type Cursor struct {
|
|
FirstBatch []Document `json:"firstBatch"`
|
|
ID int64 `json:"id"`
|
|
NS string `json:"ns"`
|
|
NextBatch []Document `json:"nextBatch,omitempty"`
|
|
}
|
|
|
|
// UpsertID 插入或更新的 ID
|
|
type UpsertID struct {
|
|
Index int `json:"index"`
|
|
ID string `json:"_id"`
|
|
}
|
|
|
|
// InsertResult 插入结果
|
|
type InsertResult struct {
|
|
OK int `json:"ok"`
|
|
N int `json:"n"`
|
|
InsertedIDs map[int]string `json:"insertedIds"`
|
|
}
|
|
|
|
// UpdateResult 更新结果
|
|
type UpdateResult struct {
|
|
OK int `json:"ok"`
|
|
N int `json:"n"`
|
|
NModified int `json:"nModified"`
|
|
Upserted []UpsertID `json:"upserted,omitempty"`
|
|
UpsertedN int `json:"upsertedN,omitempty"`
|
|
}
|
|
|
|
// DeleteResult 删除结果
|
|
type DeleteResult struct {
|
|
OK int `json:"ok"`
|
|
N int `json:"n"`
|
|
DeletedCount int `json:"deletedCount"`
|
|
}
|
|
|
|
// AggregateResult 聚合结果
|
|
type AggregateResult struct {
|
|
OK int `json:"ok"`
|
|
Result []Document `json:"result"`
|
|
}
|