db

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSchemaNotRegistered error = errors.New("schema not registered")
)

Functions

This section is empty.

Types

type Engine

type Engine struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

Engine 数据库引擎, 该引擎通过解析模型json文件, 生成对应的数据库表,并对表进行增删改查操作

func NewEngine

func NewEngine(driverName, dataSourceName string) (*Engine, error)

func (*Engine) Close

func (engine *Engine) Close()

Close 关闭数据库连接

func (*Engine) Delete

func (engine *Engine) Delete(name string, namedCondition map[string]interface{}) (int64, error)

Delete 删除数据, where中的条件使用命名参数,如:where = "id = :id", namedCondition = map[string]interface{}{"id": 1},注意,delete方法必须有where条件

func (*Engine) DropTable

func (engine *Engine) DropTable(name string) error

DropTable 删除表

func (*Engine) Find

func (engine *Engine) Find(name string, namedCondition map[string]interface{}, selectFields []string) ([]map[string]interface{}, error)

Find 查询数据, where中的条件使用命名参数,如:where = "id = :id", namedCondition = map[string]interface{}{"id": 1}

func (*Engine) GetSchema

func (engine *Engine) GetSchema(name string) *schema.Schema

GetSchema 获取模型

func (*Engine) GetSchemas

func (engine *Engine) GetSchemas() map[string]*schema.Schema

GetSchemas 获取所有模型

func (*Engine) Insert

func (engine *Engine) Insert(name string, data ...map[string]interface{}) (int64, error)

Insert 插入数据

func (*Engine) Migrate

func (engine *Engine) Migrate() error

Migrate 迁移所有注册的模型

func (*Engine) MigrateTable

func (engine *Engine) MigrateTable(name string, tx ...*sqlx.Tx) error

MigrateTable 迁移表

func (*Engine) Register

func (engine *Engine) Register(definition string) (string, error)

Register 注册模型

func (*Engine) SchemaTableExists

func (engine *Engine) SchemaTableExists(name string, tx ...*sqlx.Tx) (bool, error)

SchemaTableExists 检查模型对应的表格是否存在

func (*Engine) Update

func (engine *Engine) Update(name string, data, namedCondition map[string]interface{}) (int64, error)

Update 更新数据, where中的条件使用命名参数,如:where = "id = :id", namedCondition = map[string]interface{}{"id": 1}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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