Documentation ¶
Overview ¶
定义数据库操作接口
Index ¶
- Variables
- func Decode(cursor Cursor, result interface{}) error
- func Drivers() []string
- func Register(name string, driver Driver)
- type BinaryCond
- type Column
- type Cond
- type Cursor
- type Database
- type DeleteOptions
- type DeleteResult
- type Driver
- type ExprCond
- type FieldType
- type Index
- type IndexKey
- type InsertOptions
- type InsertResult
- type ListCond
- type Model
- type OpenOptions
- type Order
- type QueryOptions
- type QueryResult
- type Token
- type UnaryCond
- type UpdateOptions
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidIndexName = errors.New("invalid index name")
)
View Source
var (
ErrNoDocument = errors.New("no document found")
)
Functions ¶
Types ¶
type BinaryCond ¶
type Column ¶
type Column struct { Name string // 字段名 Type string // 类型 Default string // 默认值, 不需要双引号 NotNull bool // 是否非空 AutoIncrement bool // 是否自增 PrimaryKey bool // 是否是主键 Size int // 类型大小 }
列信息,用于CreateTable
func ParseModel ¶
ParseModel 解析Model,获得Column信息
type Cursor ¶
type Cursor interface { //ID() int64 Close() error Next() bool Scan(dest ...interface{}) error Decode(model interface{}) error }
Scan和Decode的区别是,Scan对应原生sql中的Scan,而Decode则是反射解析到struct中
type Database ¶
type Database interface { Indexes(table string) ([]*Index, error) CreateIndex(table string, index *Index) error DropIndex(table string, name string) error CreateTable(table string, columns []Column) error DropTable(table string) error Insert(table string, doc interface{}, opts *InsertOptions) (*InsertResult, error) Delete(table string, filter Cond, opts *DeleteOptions) (*DeleteResult, error) Update(table string, filter Cond, update interface{}, opts *UpdateOptions) (*UpdateResult, error) Query(table string, filter Cond, opts *QueryOptions) (QueryResult, error) }
Database 用于对某个特定数据库进行增删改查
type DeleteOptions ¶
type DeleteOptions struct {
One bool
}
type DeleteResult ¶
type DeleteResult struct {
DeletedCount int64
}
type Driver ¶
type Driver interface { Name() string Open(opts *OpenOptions) error Close() error Ping() error Database(name string) (Database, error) Drop(name string) error }
Driver 数据库驱动,支持同时连接多个数据库
type Index ¶
TODO:Partial Index https://blog.huoding.com/2016/04/28/510
func (*Index) GenerateName ¶
func (i *Index) GenerateName()
type InsertOptions ¶
type OpenOptions ¶
type OpenOptions struct {
URI string
}
type QueryOptions ¶
type QueryResult ¶
查询结果,可以调用Decode自动反射结果,也可以调用Cursor,手动遍历结果
type Token ¶
type Token int
https://docs.mongodb.com/manual/reference/operator/query-comparison/ Query embedded document: $elemMatch vs. Dot Notation
type UpdateOptions ¶
type UpdateResult ¶
type UpdateResult struct { // The number of documents that matched the filter. MatchedCount int64 // The number of documents that were modified. ModifiedCount int64 // The number of documents that were upserted. UpsertedCount int64 // The identifier of the inserted document if an upsert took place. UpsertedID interface{} }
UpdateResult is a result of an update operation.
UpsertedID will be a Go type that corresponds to a BSON type.
Click to show internal directories.
Click to hide internal directories.