mongodbstorage

package
v2.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColNameInfo     = "info"
	ColNameManifest = "manifest"
	// ColNameOperation = "operation"
	// ColNameStagedOperation = "staged_operation"
	// ColNameProposal     = "proposal"
	// ColNameState        = "state"
	// ColNameVoteproof    = "voteproof"
	ColNameBlockdataMap = "blockdata_map"
)

Variables

View Source
var IndexPrefix = "mitum_"

Functions

func LoadDataFromDoc

func LoadDataFromDoc(b []byte, encs *encoder.Encoders) (bson.Raw, interface{}, error)

func NewLastManifestDoc

func NewLastManifestDoc(height base.Height, enc encoder.Encoder) (lastManifestDoc, error)

Types

type BaseDoc

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

func NewBaseDoc

func NewBaseDoc(id, data interface{}, enc encoder.Encoder) (BaseDoc, error)

func (BaseDoc) ID

func (do BaseDoc) ID() interface{}

func (BaseDoc) M

func (do BaseDoc) M() (bson.M, error)

type BaseDocUnmarshaler

type BaseDocUnmarshaler struct {
	I bson.Raw      `bson:"_id,omitempty"`
	E string        `bson:"_e"`
	D bson.RawValue `bson:"d"`
	H bool          `bson:"_hinted"`
}

type Client

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

func NewClient

func NewClient(uri string, connectTimeout, execTimeout time.Duration) (*Client, error)

func (*Client) Add

func (cl *Client) Add(col string, doc Doc) (interface{}, error)

func (*Client) AddRaw

func (cl *Client) AddRaw(col string, raw bson.Raw) (interface{}, error)

func (*Client) Bulk

func (cl *Client) Bulk(ctx context.Context, col string, models []mongo.WriteModel, order bool) error

func (*Client) Close

func (cl *Client) Close() error

func (*Client) Collection

func (cl *Client) Collection(col string) *mongo.Collection

func (*Client) Collections

func (cl *Client) Collections() ([]string, error)

func (*Client) CopyCollection

func (cl *Client) CopyCollection(source *Client, fromCol, toCol string) error

func (*Client) Count

func (cl *Client) Count(ctx context.Context, col string, filter interface{}, opts ...*options.CountOptions) (int64, error)

func (*Client) Database

func (cl *Client) Database(db string) *mongo.Database

func (*Client) Databases

func (cl *Client) Databases(filter interface{}) ([]string, error)

func (*Client) Delete

func (cl *Client) Delete(col string, filter bson.D, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*Client) DropDatabase

func (cl *Client) DropDatabase() error

func (*Client) Exists

func (cl *Client) Exists(col string, filter bson.D) (bool, error)

func (*Client) Find

func (cl *Client) Find(
	ctx context.Context,
	col string,
	query interface{},
	callback getRecordsCallback,
	opts ...*options.FindOptions,
) error

func (*Client) GetByFilter

func (cl *Client) GetByFilter(
	col string,
	filter bson.D,
	callback getRecordCallback,
	opts ...*options.FindOneOptions,
) error

func (*Client) GetByID

func (cl *Client) GetByID(
	col string,
	id interface{},
	callback getRecordCallback,
	opts ...*options.FindOneOptions,
) error

func (*Client) New

func (cl *Client) New(db string) (*Client, error)

func (*Client) Raw

func (cl *Client) Raw() *mongo.Client

func (*Client) Set

func (cl *Client) Set(col string, doc Doc) (interface{}, error)

func (*Client) WithSession

func (cl *Client) WithSession(
	callback func(mongo.SessionContext, func(string) *mongo.Collection) (interface{}, error),
) (interface{}, error)

type Database

type Database struct {
	sync.RWMutex
	*logging.Logging
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(client *Client, encs *encoder.Encoders, enc encoder.Encoder) (*Database, error)

func NewDatabaseFromURI

func NewDatabaseFromURI(uri string, encs *encoder.Encoders) (*Database, error)

func (*Database) Clean

func (st *Database) Clean() error

Clean will drop the existing collections. To keep safe the another collections by user, drop collections instead of drop database.

func (*Database) Client

func (st *Database) Client() *Client

func (*Database) Close

func (st *Database) Close() error

func (*Database) CreateIndex

func (st *Database) CreateIndex(col string, models []mongo.IndexModel, prefix string) error

func (*Database) Encoder

func (st *Database) Encoder() encoder.Encoder

func (*Database) Encoders

func (st *Database) Encoders() *encoder.Encoders

func (*Database) Info

func (st *Database) Info(key string) ([]byte, bool, error)

func (*Database) Initialize

func (st *Database) Initialize() error

func (*Database) New

func (st *Database) New() (*Database, error)

func (*Database) Readonly

func (st *Database) Readonly() (*Database, error)

func (*Database) SetInfo

func (st *Database) SetInfo(key string, b []byte) error

type Doc

type Doc interface {
	ID() interface{}
}

type InfoDoc

type InfoDoc struct {
	BaseDoc
	// contains filtered or unexported fields
}

func NewInfoDoc

func NewInfoDoc(key string, v []byte, enc encoder.Encoder) (InfoDoc, error)

func (InfoDoc) MarshalBSON

func (do InfoDoc) MarshalBSON() ([]byte, error)

Jump to

Keyboard shortcuts

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