dsl

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Provides = wire.NewSet(
	wire.Struct(new(Controller), "*"),
	wire.Struct(new(Service), "*"),
)

Functions

This section is empty.

Types

type BulkCreateDto

type BulkCreateDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 批量文档数据
	Data []M `json:"data,required" vd:"len($)>0 && range($,len(#v)>0);msg:'批量文档不能存在空数据'"`
	// Body.data[*] 格式转换
	Format M `json:"format"`
}

type BulkDeleteDto

type BulkDeleteDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 筛选条件
	Data M `json:"data,required" vd:"len($)>0;msg:'筛选条件不能为空'"`
	// Body.data 格式转换
	Format M `json:"format"`
}

type Controller

type Controller struct {
	DSLService *Service
}

func (*Controller) BulkCreate

func (x *Controller) BulkCreate(ctx context.Context, c *app.RequestContext)

BulkCreate 批量新增文档 @router /:collection/bulk-create [POST]

func (*Controller) BulkDelete

func (x *Controller) BulkDelete(ctx context.Context, c *app.RequestContext)

BulkDelete 批量删除匹配文档 @router /:collection/bulk-delete [POST]

func (*Controller) Create

func (x *Controller) Create(ctx context.Context, c *app.RequestContext)

Create 新增文档 @router /:collection [POST]

func (*Controller) Delete

func (x *Controller) Delete(ctx context.Context, c *app.RequestContext)

Delete 删除指定 ID 的文档 @router /:collection/:id [DELETE]

func (*Controller) Find

func (x *Controller) Find(ctx context.Context, c *app.RequestContext)

Find 获取匹配文档 @router /:collection [GET]

func (*Controller) FindById

func (x *Controller) FindById(ctx context.Context, c *app.RequestContext)

FindById 获取指定 ID 的文档 @router /:collection/:id [GET]

func (*Controller) FindOne

func (x *Controller) FindOne(ctx context.Context, c *app.RequestContext)

FindOne 获取单个文档 @router /:collection/_one [GET]

func (*Controller) Replace

func (x *Controller) Replace(ctx context.Context, c *app.RequestContext)

Replace 替换指定 ID 的文档 @router /:collection/:id [PUT]

func (*Controller) Size

func (x *Controller) Size(ctx context.Context, c *app.RequestContext)

Size 获取文档总数 @router /:collection/_size [GET]

func (*Controller) Sort

func (x *Controller) Sort(ctx context.Context, c *app.RequestContext)

Sort 排序文档 @router /:collection/sort [POST]

func (*Controller) Update

func (x *Controller) Update(ctx context.Context, c *app.RequestContext)

Update 局部更新匹配文档 @router /:collection [PATCH]

func (*Controller) UpdateById

func (x *Controller) UpdateById(ctx context.Context, c *app.RequestContext)

UpdateById 局部更新指定 ID 的文档 @router /:collection/:id [PATCH]

type CreateDto

type CreateDto struct {
	// 集合命名
	Collection string `path:"collection" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 文档数据
	Data M `json:"data,required" vd:"len($)>0;msg:'文档不能为空数据'"`
	// Body.data 格式转换
	Format M `json:"format"`
}

type DSL

type DSL struct {
	Namespace     string
	Db            *mongo.Database
	DynamicValues *kv.DynamicValues
	Js            nats.JetStreamContext
}

func New

func New(options ...Option) (x *DSL, err error)

type DeleteDto

type DeleteDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 文档 ID
	Id string `path:"id,required" vd:"mongoId($);msg:'文档 ID 不规范'"`
}

type FindByIdDto

type FindByIdDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 文档 ID
	Id string `path:"id,required" vd:"mongoId($);msg:'文档 ID 不规范'"`
	// 投影规则
	Keys []string `query:"keys" vd:"range($,regexp('^[a-z_]+$',#v));msg:'投影规则不规范'"`
}

type FindDto

type FindDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 分页大小(默认 100 自定义必须在1~1000之间 )
	Pagesize int64 `header:"x-pagesize" vd:"$>=0 && $<=1000;msg:'分页数量必须在 1~1000 之间'"`
	// 分页页码
	Page int64 `header:"x-page" vd:"$>=0;msg:'页码必须大于 0'"`
	// 筛选条件
	Filter M `query:"filter"`
	// Query.filter 格式转换
	Format M `query:"format"`
	// 排序规则
	Sort []string `query:"sort" vd:"range($,regexp('^[a-z_]+:(-1|1)$',#v)));msg:'排序规则不规范'"`
	// 投影规则
	Keys []string `query:"keys" vd:"range($,regexp('^[a-z_]+$',#v));msg:'投影规则不规范'"`
}

type FindOneDto

type FindOneDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 筛选条件
	Filter M `query:"filter,required" vd:"len($)>0;msg:'筛选条件不能为空'"`
	// Query.filter 格式转换
	Format M `query:"format"`
	// 投影规则
	Keys []string `query:"keys" vd:"range($,regexp('^[a-z_]+$',#v));msg:'投影规则不规范'"`
}

type M

type M = map[string]interface{}

type Option

type Option func(x *DSL)

func SetDatabase

func SetDatabase(v *mongo.Database) Option

func SetDynamicValues

func SetDynamicValues(v *kv.DynamicValues) Option

func SetJetStream

func SetJetStream(v nats.JetStreamContext) Option

func SetNamespace

func SetNamespace(v string) Option

type PublishDto

type PublishDto struct {
	Event        string      `json:"event"`
	Id           string      `json:"id,omitempty"`
	Filter       M           `json:"filter,omitempty"`
	FilterFormat M           `json:"filter_format,omitempty"`
	Data         interface{} `json:"data,omitempty"`
	DataFormat   M           `json:"data_format,omitempty"`
	Result       interface{} `json:"result"`
}

type ReplaceDto

type ReplaceDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 文档 ID
	Id string `path:"id,required" vd:"mongoId($);msg:'文档 ID 不规范'"`
	// 文档数据
	Data M `json:"data,required" vd:"len($)>0;msg:'文档数据不能为空'"`
	// Body.data 格式转换
	Format M `json:"format"`
}

type Service

type Service struct {
	*DSL
}

func (*Service) BulkCreate

func (x *Service) BulkCreate(ctx context.Context, name string, docs []interface{}) (_ interface{}, err error)

BulkCreate 批量新增文档

func (*Service) BulkDelete

func (x *Service) BulkDelete(ctx context.Context, name string, filter M) (_ interface{}, err error)

BulkDelete 批量删除匹配文档

func (*Service) Create

func (x *Service) Create(ctx context.Context, name string, doc M) (_ interface{}, err error)

Create 新增文档

func (*Service) Delete

func (x *Service) Delete(ctx context.Context, name string, id primitive.ObjectID) (_ interface{}, err error)

Delete 删除指定 ID 的文档

func (*Service) Find

func (x *Service) Find(ctx context.Context, name string, filter M, option *options.FindOptions) (data []M, err error)

Find 获取匹配文档

func (*Service) FindOne

func (x *Service) FindOne(ctx context.Context, name string, filter M, option *options.FindOneOptions) (data M, err error)

FindOne 获取单个文档

func (*Service) Load

func (x *Service) Load(ctx context.Context) (err error)

Load 加载动态配置

func (*Service) Projection

func (x *Service) Projection(name string, keys []string) (result bson.M)

Projection 字段投影

func (*Service) Publish

func (x *Service) Publish(ctx context.Context, name string, dto PublishDto) (err error)

Publish 事件消息补偿

func (*Service) Replace

func (x *Service) Replace(ctx context.Context, name string, id primitive.ObjectID, doc M) (_ interface{}, err error)

Replace 替换指定 ID 的文档

func (*Service) Size

func (x *Service) Size(ctx context.Context, name string, filter M) (_ int64, err error)

Size 获取文档总数

func (*Service) Sort

func (x *Service) Sort(ctx context.Context, name string, ids []primitive.ObjectID) (_ interface{}, err error)

Sort 排序文档

func (*Service) Transform

func (x *Service) Transform(data M, format M) (err error)

Transform 格式转换

func (*Service) Update

func (x *Service) Update(ctx context.Context, name string, filter M, update M) (_ interface{}, err error)

Update 局部更新匹配文档

func (*Service) UpdateById

func (x *Service) UpdateById(ctx context.Context, name string, id primitive.ObjectID, update M) (_ interface{}, err error)

UpdateById 局部更新指定 ID 的文档

type SizeDto

type SizeDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 筛选条件
	Filter M `query:"filter"`
	// Query.filter 格式转换
	Format M `query:"format"`
}

type SortDto

type SortDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 文档 ID 数组
	Data []primitive.ObjectID `json:"data,required" vd:"len($)>0;msg:'数组必须均为文档 ID'"`
}

type UpdateByIdDto

type UpdateByIdDto struct {
	// 集合命名
	Collection string `path:"collection,required" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 文档 ID
	Id string `path:"id,required" vd:"mongoId($);msg:'文档 ID 不规范'"`
	// 更新操作
	Data M `json:"data,required" vd:"len($)>0;msg:'更新操作不能为空'"`
	// Body.data 格式转换
	Format M `json:"format"`
}

type UpdateDto

type UpdateDto struct {
	// 集合命名
	Collection string `path:"collection" vd:"regexp('^[a-z_]+$');msg:'集合名称必须是小写字母与下划线'"`
	// 筛选条件
	Filter M `query:"filter,required" vd:"len($)>0;msg:'筛选条件不能为空'"`
	// Query.filter 格式转换
	FFormat M `query:"format"`
	// 更新操作
	Data M `json:"data,required" vd:"len($)>0;msg:'更新操作不能为空'"`
	// Body.data 格式转换
	DFormat M `json:"format"`
}

Jump to

Keyboard shortcuts

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