swolf

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

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 8 Imported by: 0

README

Swolf

Travis

Overview

Swolf is a library for managing databases in database-per-tenant architecture.

Contributing

  1. Fork it
  2. Clone develop: git clone -b develop https://github.com/noyako/swolf
  3. Create your feature branch: git checkout -b some-feature
  4. Make changes and add them: git add .
  5. Commit: git commit -m "(feat/fix/change)[what]: Add some feature"
  6. Push: git push origin some-feature
  7. Create pull request

License

Swolf is distributed under MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver         string
	Connection     string         // Connection string with user, password and connection address
	MasterDatabase string         // Name of the master database
	MasterTable    string         // Name of the master table in master database
	Template       string         // Database template, works only for postgresql
	MasterData     MasterResolver // Names of control columns
	Mapper         FMapper        // Mapping functions
}

Config for database manager.

type Dealer

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

Dealer controls databases manipulation.

func Setup

func Setup(cfg Config) *Dealer

Setup creates Dealer by config.

func (*Dealer) Create

func (d *Dealer) Create(id string) (*sql.DB, error)

Create creates new tenant with specified id.

func (*Dealer) Delete

func (d *Dealer) Delete(id string) error

Delete deletes tenant with specified id.

func (*Dealer) Get

func (d *Dealer) Get(id string) (*sql.DB, error)

Get returns tenant with specified id.

type FMapper

type FMapper struct {
	IDToField       func(string) string // Convert tenant ID to key field in master database
	FieldToDatabase func(string) string // Convert dependent field to database name
	KeyToValue      func(string) string // Convert key field to dependent in master database
}

FMapper is used to convert ids to names

type MasterController

type MasterController interface {
	Get(string) (string, error)
	Create(string) (string, error)
	Delete(string) (string, error)
}

MasterController controls tenant data in master database

type MasterResolver

type MasterResolver interface {
	// contains filtered or unexported methods
}

MasterResolver is used to configure key and tenant fields.

func MasterDataResolver

func MasterDataResolver(in interface{}) MasterResolver

MasterDataResolver is used to configure key and tenant fields from given type. Given struct must contain tags: `sw:"key"` for key `sw:"tenant"` for tenant database

func MasterFieldResolver

func MasterFieldResolver(k, t string) MasterResolver

MasterFieldResolver sets key and dependent fields from string.

type Pool

type Pool interface {
	Get(string) (*sql.DB, bool)
	Put(string, *sql.DB)
	SetMaxConn(int)
}

Pool is used to cache database connections

type TenantController

type TenantController interface {
	Get(string) (*sql.DB, error)
	Create(string) (*sql.DB, error)
	Delete(string) error
}

TenantController controls databases for tenants

Directories

Path Synopsis
Package builder provides methods for creating simple SQL queries.
Package builder provides methods for creating simple SQL queries.
Package mock_swolf is a generated GoMock package.
Package mock_swolf is a generated GoMock package.

Jump to

Keyboard shortcuts

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