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
- Variables
- func New(ctx context.Context, uri string) (proto.Storage, error)
- type Mongo
- func (m *Mongo) Close()
- func (m *Mongo) IsNoSQL() bool
- func (m *Mongo) ListPrimaryKeys(ctx context.Context) (*proto.ListPrimaryKeysResponse, error)
- func (m *Mongo) ListTables(ctx context.Context) (*proto.ListTablesResponse, error)
- func (m *Mongo) StartTx(ctx context.Context) (*proto.Txn, error)
- func (m *Mongo) Truncate(ctx context.Context, req *proto.TruncateRequest) (*proto.TruncateResponse, error)
- func (m *Mongo) Type() uint8
- func (m *Mongo) Upsert(ctx context.Context, req *proto.UpsertRequest) (*proto.UpsertResponse, error)
Constants ¶
const Version = "0.0.0-alpha"
Variables ¶
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 ¶
Types ¶
type Mongo ¶
Mongo is a wrapper for *mongo.Client, use to perform CRUD operations on a mongo DB instance.
func (*Mongo) ListPrimaryKeys ¶
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 ¶
ListTables will return a list of all tables in the MongoDB database.
func (*Mongo) StartTx ¶
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 ¶
func (m *Mongo) Truncate(ctx context.Context, req *proto.TruncateRequest) (*proto.TruncateResponse, error)
Truncate will delete all records in a collection.
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.