orm

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

README

database orm

用于抽象database操作,数据库需要支持常见sql和mongodb,以及常见的kv数据库,功能上需要支持CRUD,索引操作 api接口上跟mongodb更相似,该库并不能取代原生的db驱动,不能操作复杂命令(如Aggregate),不能连表操作, 但是能满足大部分常见单表操作

状态

很多功能尚未实现,勿用

参考

注意

  • 尚未仔细实现测试细节

Documentation

Index

Constants

View Source
const (
	Asc  = driver.Asc  // 升序,默认
	Desc = driver.Desc // 降序
)

Variables

View Source
var (
	ErrInvalidIndexKey = errors.New("invalid index key")
	ErrNotSupport      = errors.New("not support")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(driverName string, opts ...OpenOption) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Database

func (c *Client) Database(name string) (*Database, error)

func (*Client) Drop

func (c *Client) Drop(name string) error

func (*Client) Open

func (c *Client) Open(opts ...OpenOption) error

func (*Client) Ping

func (c *Client) Ping() error

type Cond

type Cond = driver.Cond

func And

func And(conds ...Cond) Cond

func Eq

func Eq(key string, value interface{}) Cond

func Gt

func Gt(key string, value interface{}) Cond

func Gte

func Gte(key string, value interface{}) Cond

func In

func In(key string, value interface{}) Cond

func Lt

func Lt(key string, value interface{}) Cond

func Lte

func Lte(key string, value interface{}) Cond

func Ne

func Ne(key string, value interface{}) Cond

func Nin

func Nin(key string, value interface{}) Cond

func Nor

func Nor(conds ...Cond) Cond

func Not

func Not(cond Cond) Cond

func Or

func Or(conds ...Cond) Cond

type Database

type Database struct {
	// contains filtered or unexported fields
}

func (*Database) CreateIndex

func (d *Database) CreateIndex(table string, keys interface{}, opts ...IndexOption) error

创建索引,简单情况只需要传入列名即可,支持以下形式 d.CreateIndex("test", "uid") d.CreateIndex("test", []string{"uid", "create_time"}) d.CreateIndex("test", []orm.IndexKey{{Name:"uid", Order:orm.Desc}})

func (*Database) CreateTable

func (d *Database) CreateTable(model interface{}) error

CreateTable 会自动创建缺失的表,列,和索引,但不会删除和改变列类型

func (*Database) Delete

func (d *Database) Delete(table string, filter Cond, opts ...DeleteOption) (*DeleteResult, error)

func (*Database) DeleteOne

func (d *Database) DeleteOne(table string, filter Cond, opts ...DeleteOption) (*DeleteResult, error)

func (*Database) DropIndex

func (d *Database) DropIndex(table string, name string) error

func (*Database) DropTable

func (d *Database) DropTable(name string) error

func (*Database) Indexes

func (d *Database) Indexes(table string) ([]*Index, error)

func (*Database) Insert

func (d *Database) Insert(table string, doc interface{}, opts ...InsertOption) (*InsertResult, error)

func (*Database) Query

func (d *Database) Query(table string, filter Cond, opts ...QueryOption) error

func (*Database) QueryOne

func (d *Database) QueryOne(table string, filter Cond, opts ...QueryOption) (QueryResult, error)

func (*Database) Update

func (d *Database) Update(table string, filter Cond, update interface{}, opts ...UpdateOption) (*UpdateResult, error)

func (*Database) UpdateOne

func (d *Database) UpdateOne(table string, filter Cond, update interface{}, opts ...UpdateOption) (*UpdateResult, error)

type DeleteOption

type DeleteOption func(options *driver.DeleteOptions)

type DeleteResult

type DeleteResult = driver.DeleteResult

type Index

type Index = driver.Index

type IndexKey

type IndexKey = driver.IndexKey

type IndexOption

type IndexOption func(options *driver.Index)

type InsertOption

type InsertOption func(options *driver.InsertOptions)

type InsertResult

type InsertResult = driver.InsertResult

type OpenOption

type OpenOption func(options *driver.OpenOptions)

type Order

type Order = driver.Order

type QueryOption

type QueryOption func(options *driver.QueryOptions)

type QueryResult

type QueryResult = driver.QueryResult

type Token

type Token = driver.Token

type UpdateOption

type UpdateOption func(options *driver.UpdateOptions)

type UpdateResult

type UpdateResult = driver.UpdateResult

Directories

Path Synopsis
定义数据库操作接口
定义数据库操作接口

Jump to

Keyboard shortcuts

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