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 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 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 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 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
Index ¶
- Constants
- Variables
- func DNSNotSupportedError(dns string) error
- func Scheme(t uint8) string
- 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) (*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)
- type Postgres
- func (pg *Postgres) Close()
- func (pg *Postgres) IsNoSQL() bool
- func (pg *Postgres) ListColumns(ctx context.Context) (*proto.ListColumnsResponse, error)
- func (pg *Postgres) ListPrimaryKeys(ctx context.Context) (*proto.ListPrimaryKeysResponse, error)
- func (pg *Postgres) ListTables(ctx context.Context) (*proto.ListTablesResponse, error)
- func (pg *Postgres) StartTx(ctx context.Context) (*Txn, error)
- func (pg *Postgres) Truncate(ctx context.Context, req *proto.TruncateRequest) (*proto.TruncateResponse, error)
- func (pg *Postgres) Type() uint8
- func (pg *Postgres) Upsert(ctx context.Context, req *proto.UpsertRequest) (*proto.UpsertResponse, error)
- type Service
- type Storage
- type Transactor
- type Txn
- type TxnChanFn
Constants ¶
const ( // MongoType is the byte representation of a mongo database. MongoType uint8 = iota // PostgresType is the byte representation of a postgres database. PostgresType )
Variables ¶
Functions ¶
func DNSNotSupportedError ¶
DNSNotSupported wraps an error with ErrDNSNotSupported.
Types ¶
type Mongo ¶
Mongo is a wrapper for *mongo.Client, use to perform CRUD operations on a mongo DB instance.
func NewMongo ¶
NewMongo 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
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.
type Postgres ¶
Postgres is a wrapper around the sql.DB object.
func NewPostgres ¶
NewPostgres will return a new Postgres option for querying data through a Postgres DB.
func (*Postgres) Close ¶
func (pg *Postgres) Close()
Close will close the underlying database / transaction.
func (*Postgres) IsNoSQL ¶
IsNoSQL returns "false" to indicate that "Postgres" is not a NoSQL database.
func (*Postgres) ListColumns ¶
ListColumns will set a complete list of available columns per table on the response.
func (*Postgres) ListPrimaryKeys ¶
ListPrimaryKeys will list all primary keys for all of the tables in the database defined by the DNS used to create the postgres instance.
func (*Postgres) ListTables ¶
ListTables will set a complete list of available tables on the response.
func (*Postgres) StartTx ¶
StartTx will start a transaction on the Postgres connection. The transaction ID is returned and should be used to commit or rollback the transaction.
func (*Postgres) Truncate ¶
func (pg *Postgres) Truncate(ctx context.Context, req *proto.TruncateRequest) (*proto.TruncateResponse, error)
Truncate will truncate a table.
func (*Postgres) Upsert ¶
func (pg *Postgres) Upsert(ctx context.Context, req *proto.UpsertRequest) (*proto.UpsertResponse, error)
Upsert will insert the records on the request if they do not exist in the database. On conflict, it will use the PK on the request record to update the data in the database. An upsert request will update the entire table for a given record, include fields that have not been set directly.
type Storage ¶
type Storage interface { // Close will disconnect the storage device. Close() // ListPrimaryKeys will return a list of primary keys for all tables in the database. ListPrimaryKeys(ctx context.Context) (*proto.ListPrimaryKeysResponse, error) // ListTables will return a list of all tables in the database. ListTables(ctx context.Context) (*proto.ListTablesResponse, error) // IsNoSQL will return true if the storage device is a NoSQL database. IsNoSQL() bool // StartTx will start a transaction and return a "Tx" object that can be used to put operations on a channel, // commit the result of all operations sent to the transaction, or rollback the result of all operations sent // to the transaction. StartTx(context.Context) (*Txn, error) // Truncate will delete all data from the storage device for ast list of tables. Truncate(context.Context, *proto.TruncateRequest) (*proto.TruncateResponse, error) // Type returns the type of storage device. Type() uint8 // Upsert will insert or update a batch of records in the storage device. Upsert(context.Context, *proto.UpsertRequest) (*proto.UpsertResponse, error) }
Storage is an interface that defines the methods that a storage device should implement.
type Transactor ¶
Transactor is an interface that can be used to perform CRUD operations within the context of a database transaction.