z1mongo

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Add

func Add(model Model) (insertOneResult *mongo.InsertOneResult, err error)

func AddMany

func AddMany(model Model, models []interface{}) (insertManyResult *mongo.InsertManyResult, err error)

func BsonD2Mode

func BsonD2Mode(input interface{}, output Model)

func CheckJoin

func CheckJoin(on_str, mainTable string) (join int, err error)

func Connect

func Connect(uri, name string, timeout time.Duration, num uint64) (*mongo.Database, error)

pool 连接池模式

func Del

func Del(filter Model) (deleteResult *mongo.DeleteResult, err error)

func Disconnect

func Disconnect()

func MakeFindOptions

func MakeFindOptions(page, pageSize int64, sort string) *options.FindOptions

MakeFindOptions(2, 3, `-update_time,+goods_id,created_time`)

func NewZ1mongo

func NewZ1mongo(cnf MongoConfig)

func NewZ1mongo(dbUri string, dbName string, timeout time.Duration, client_max_num uint64) {

func One

func One(model Model) (err error)

func Parse

func Parse(sql string) (string, string, error)

func ParsingDDLSQL

func ParsingDDLSQL(stmt sqlparser.Statement) (ret map[string]string, err error)

func ParsingDeleteSQL

func ParsingDeleteSQL(stmt sqlparser.Statement) (ret map[string]string, err error)

func ParsingInsertSQL

func ParsingInsertSQL(stmt sqlparser.Statement) (ret map[string]string, err error)

func ParsingSQL

func ParsingSQL(sql string) (ret map[string]string, err error)

func ParsingSelectSQL

func ParsingSelectSQL(stmt sqlparser.Statement) (ret map[string]string, err error)

func ParsingUpdateSQL

func ParsingUpdateSQL(stmt sqlparser.Statement) (ret map[string]string, err error)

func Sql2Mongo

func Sql2Mongo(sql string, z1count bool, ret ...interface{}) (result []bson.M, total int64, action string, err error)

https://github.com/shan-chen/sql2mongo/blob/master/parse.go

func Update

func Update(filter, model Model) (updateResult *mongo.UpdateResult, err error)

Types

type Model

type Model interface {
	TableName() string
	DBType() string
}

func Deepcoper

func Deepcoper(m Model) Model

func List

func List(model Model, filter interface{}, page, pageSize int64, sort string, z1count bool) (ret []Model, total int64, err error)

bson.M{"name": primitive.Regex{Pattern: "深入"}} filer bson.M{"username": "myzero1"} filer bson.M{"username": bson.M{"$eq": "myzero1"}} filer bson.M{"username": bson.M{"$regex": "my"}} filer bson.M{"$and": []bson.M{bson.M{"created_at": bson.M{"$gt": 1684448021}}, bson.M{"created_at": bson.M{"$lte": 1684448124}}}},

type MongoConfig added in v0.9.1

type MongoConfig struct {
	Uri          string //mongodb://localhost:27017, mongodb://username:password@localhost:27017
	DBName       string
	Timeout      time.Duration
	ClientMaxNum uint64
}

type Role

type Role struct {
	*Z1Model
	Name      string             `gorm:"column:name" json:"name" bson:"name,omitempty"`                   // 名称
	Des       string             `gorm:"column:des" json:"des" bson:"des,omitempty"`                      // 描述
	Action    string             `gorm:"column:action" json:"action" bson:"action,omitempty"`             // 操作,过个用逗号隔开
	Status    int64              `gorm:"column:status;default:1" json:"status" bson:"status,omitempty"`   // 状态 0为禁用、1为启用
	ID        int64              `gorm:"column:id;primary_key" json:"id" bson:"id,omitempty"`             // sonyflake machineid max 65536 2^16
	CreatedAt int64              `gorm:"column:created_at" json:"created_at" bson:"created_at,omitempty"` // 创建时间戳
	UpdatedAt int64              `gorm:"column:updated_at" json:"updated_at" bson:"updated_at,omitempty"` // 更新时间戳
	DeletedAt time.Time          `gorm:"column:deleted_at" json:"deleted_at" bson:"deleted_at,omitempty"` // 删除时间 // for gorm
	ID_       primitive.ObjectID `gorm:"column:_id" json:"_id" bson:"_id,omitempty"`                      // for mongodb _id
}

func (*Role) TableName

func (m *Role) TableName() string

type User

type User struct {
	*Z1Model
	Username    string             `gorm:"column:username" json:"username" bson:"username,omitempty"`             // 用户名
	Email       string             `gorm:"column:email" json:"email" bson:"email,omitempty"`                      // 邮箱
	MobilePhone string             `gorm:"column:mobile_phone" json:"mobile_phone" bson:"mobile_phone,omitempty"` // 手机号
	Avatar      string             `gorm:"column:avatar" json:"avatar" bson:"avatar,omitempty"`                   // 头像地址
	Password    string             `gorm:"column:password" json:"password" bson:"password,omitempty"`             // 加密后的密码
	ApiToken    string             `gorm:"column:api_token" json:"api_token" bson:"api_token,omitempty"`          // 暂时保留,可能被删除
	Status      int64              `gorm:"column:status;default:1" json:"status" bson:"status,omitempty"`         // 状态 0为禁用、1为启用
	Rid         int64              `gorm:"column:rid;default:1" json:"rid" bson:"rid,omitempty"`                  // 状态 0为禁用、1为启用
	ID          int64              `gorm:"column:id;primary_key" json:"id" bson:"id,omitempty"`                   // sonyflake machineid max 65536 2^16
	CreatedAt   int64              `gorm:"column:created_at" json:"created_at" bson:"created_at,omitempty"`       // 创建时间戳
	UpdatedAt   int64              `gorm:"column:updated_at" json:"updated_at" bson:"updated_at,omitempty"`       // 更新时间戳
	DeletedAt   time.Time          `gorm:"column:deleted_at" json:"deleted_at" bson:"deleted_at,omitempty"`       // 删除时间 // for gorm
	ID_         primitive.ObjectID `gorm:"column:_id" json:"_id" bson:"_id,omitempty"`                            // for mongodb _id
}

func (*User) TableName

func (m *User) TableName() string

type User2

type User2 struct {
	*Z1Model
	Username string `gorm:"column:username" json:"username" bson:"username,omitempty"` // 用户名
	Email    string `gorm:"column:email" json:"email" bson:"email,omitempty"`          // 邮箱
}

func (*User2) TableName

func (m *User2) TableName() string

type UserRole

type UserRole struct {
	*Z1Model
	Uid       int64              `gorm:"column:uid" json:"uid" bson:"uid,omitempty"`                      // 名称
	Rid       int64              `gorm:"column:rid" json:"rid" bson:"rid,omitempty"`                      // 描述
	Status    int64              `gorm:"column:status;default:1" json:"status" bson:"status,omitempty"`   // 状态 0为禁用、1为启用
	ID        int64              `gorm:"column:id;primary_key" json:"id" bson:"id,omitempty"`             // sonyflake machineid max 65536 2^16
	CreatedAt int64              `gorm:"column:created_at" json:"created_at" bson:"created_at,omitempty"` // 创建时间戳
	UpdatedAt int64              `gorm:"column:updated_at" json:"updated_at" bson:"updated_at,omitempty"` // 更新时间戳
	DeletedAt time.Time          `gorm:"column:deleted_at" json:"deleted_at" bson:"deleted_at,omitempty"` // 删除时间 // for gorm
	ID_       primitive.ObjectID `gorm:"column:_id" json:"_id" bson:"_id,omitempty"`                      // for mongodb _id
}

func (*UserRole) TableName

func (m *UserRole) TableName() string

type Z1Model

type Z1Model struct {
}

func (*Z1Model) DBType

func (m *Z1Model) DBType() string

Jump to

Keyboard shortcuts

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