datasource

package module
v0.0.0-...-acb4919 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 14 Imported by: 0

README

datasource

Convenience package for organising multiple data source connections.

Overview

This package allows you to create a bunch of data source connections and hang them off your server for much convenience.

Currently, includes connectors for:

  • MongoDB
  • PostgreSQL
  • Pulsar
  • SOLR

Todo:

  • Redis
  • MySQL

Usage

A quick example:

// A service...
srvc := struct {
	Connections datasource.Connections
}

// Add connections...
srvc.Connections.AddPostgresConnection("pg1", "postgres://.....")
srvc.Connections.AddPostgresConnection("pg2", "postgres://.....")
srvc.Connections.AddMongoConnection("mg1", "mongodb://.....")

Documentation

Overview

Package datasource provides a structure within which to store connections to multiple data sources and services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connections

type Connections struct {
	Mongo    map[string]*mongoConnection
	Postgres map[string]*postgresConnection
	Pulsar   map[string]*pulsarConnection
	Solr     map[string]*solrConnection
}

Connections represents connections to various platform services, most likely databases.

func New

func New() *Connections

New returns a pointer to a Connections value no connections attached.

func (*Connections) AddMongoConnection

func (mc *Connections) AddMongoConnection(key, dsn, db string) error

AddMongoConnection adds a connection to a mongo database identified by the specified key.

func (*Connections) AddPostgresConnection

func (mc *Connections) AddPostgresConnection(key, dsn string) error

AddPostgresConnection adds a connection to a potsgres database identified by the specified key.

func (*Connections) AddPulsarConnection

func (mc *Connections) AddPulsarConnection(key, dsn string, timeoutSeconds time.Duration) error

AddPulsarConnection adds a connection to a Pulsar server identified by the specified key.

func (*Connections) AddSolrConnection

func (mc *Connections) AddSolrConnection(key, dsn, core string, timeoutSeconds time.Duration) error

AddSolrConnection adds a connection to a Solr server identified by the specified key.

func (*Connections) MongoConnByKey

func (mc *Connections) MongoConnByKey(key string) (*mongoConnection, error)

MongoConnByKey returns the mongodb connection value at the specified key.

func (*Connections) OnlyMongoConnection

func (mc *Connections) OnlyMongoConnection() (*mongoConnection, error)

OnlyMongoConnection is a convenience function that returns the Mongo connection if there is only one.

func (*Connections) OnlyPostgresConnection

func (mc *Connections) OnlyPostgresConnection() (*postgresConnection, error)

OnlyPostgresConnection is a convenience function that returns the Postgres connection if there is only one.

func (*Connections) OnlyPulsarConnection

func (mc *Connections) OnlyPulsarConnection() (*pulsarConnection, error)

OnlyPulsarConnection is a convenience function that returns the Pulsar connection if there is only one.

func (*Connections) OnlySolrConnection

func (mc *Connections) OnlySolrConnection() (*solrConnection, error)

OnlySolrConnection is a convenience function that returns the Solr connection if there is only one.

func (*Connections) PostgresConnByKey

func (mc *Connections) PostgresConnByKey(key string) (*postgresConnection, error)

PostgresConnByKey returns the postgres connection value at the specified key.

func (*Connections) PulsarConnByKey

func (mc *Connections) PulsarConnByKey(key string) (*pulsarConnection, error)

PulsarConnByKey returns the Pulsar connection value at the specified key.

func (*Connections) SolrConnByKey

func (mc *Connections) SolrConnByKey(key string) (*solrConnection, error)

SolrConnByKey returns the Solr connection value at the specified key.

Jump to

Keyboard shortcuts

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