storage

package module
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

Gidari Mongo

Build Status Go Report Card

Gidari Mongo is the MongoDB implmentation of the Gidari Storage interface. To install run

go get github.com/alpstable/gidari-mongo@v0.0.1-alpha

Documentation

Overview

Copyright 2022 The Gidari Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Copyright 2022 The Gidari PG Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0\n

Index

Constants

View Source
const Version = "0.0.0-alpha"

Variables

View Source
var (
	ErrFailedToMarshalBSON   = fmt.Errorf("failed to marshal bson")
	ErrFailedToUnmarshalBSON = fmt.Errorf("failed to unmarshal bson")
	ErrTransactionNotFound   = fmt.Errorf("transaction not found")
	ErrNoTables              = fmt.Errorf("no tables found")
	ErrUnsupportedDataType   = fmt.Errorf("unsupported data type")
	ErrDNSNotSupported       = fmt.Errorf("dns is not supported")
	ErrTransactionAborted    = fmt.Errorf("transaction aborted")
)

Functions

func New

func New(ctx context.Context, uri string) (proto.Storage, error)

New will return a new mongo client that can be used to perform CRUD operations on a mongo DB instance. This constructor uses a URI to make the client connection, and the URI is of the form Mongo://username:password@host:port

Types

type Mongo

type Mongo struct {
	*mongo.Client
	// contains filtered or unexported fields
}

Mongo is a wrapper for *mongo.Client, use to perform CRUD operations on a mongo DB instance.

func (*Mongo) Close

func (m *Mongo) Close()

Close will close the mongo client.

func (*Mongo) IsNoSQL

func (m *Mongo) IsNoSQL() bool

IsNoSQL returns "true" indicating that the "MongoDB" database is NoSQL.

func (*Mongo) ListPrimaryKeys

func (m *Mongo) ListPrimaryKeys(ctx context.Context) (*proto.ListPrimaryKeysResponse, error)

ListPrimaryKeys will return a "proto.ListPrimaryKeysResponse" containing a list of primary keys data for all tables in a database. MongoDB does not have a concept of primary keys, so we will return the "_id" field as the primary key for all collections in the database associated with the underlying connection string.

func (*Mongo) ListTables

func (m *Mongo) ListTables(ctx context.Context) (*proto.ListTablesResponse, error)

ListTables will return a list of all tables in the MongoDB database.

func (*Mongo) StartTx

func (m *Mongo) StartTx(ctx context.Context) (*proto.Txn, error)

StartTx will start a mongodb session where all data from write methods can be rolled back.

MongoDB best practice is to "abort any multi-document transactions that runs for more than 60 seconds". The resulting error for exceeding this time constraint is "TransactionExceededLifetimeLimitSeconds". To maintain agnostism at the repository layer, we implement the logic to handle these transactions errors in the storage layer. Therefore, every 60 seconds, the transacting data will be committed commit the transaction and start a new one.

func (*Mongo) Truncate

Truncate will delete all records in a collection.

func (*Mongo) Type

func (m *Mongo) Type() uint8

Type returns the type of storage.

func (*Mongo) Upsert

func (m *Mongo) Upsert(ctx context.Context, req *proto.UpsertRequest) (*proto.UpsertResponse, error)

Upsert will insert or update a record in a collection.

Jump to

Keyboard shortcuts

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