pipet

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

README

Pipet

GORM wrapper to connect to read and write databases

Install

go get github.com/ekyfauzi/pipet

Usages

Connection
import "github.com/ekyfauzi/pipet"

func main() {
  host := "YOUR_DB_WRITE_HOST"
  hostRead := "YOUR_DB_READ_HOST"
  port := "YOUR_DB_PORT"
  user := "YOUR_DB_USER"
  passwd := "YOUR_DB_PASSWORD"
  dbName := "YOUR_DB_NAME"
  
  // Set default connection
  conn := pipet.Init("mysql")
  conn.SetWrite(host, port, user, passwd, dbName)
  
  // Add read db connection
  // You can skip this if your read and write database in the same host
  // You also can set multiple read connection
  conn.SetRead(hostRead, port, user, passwd, dbName)
  
}
Functions

Because this library is a wrapper of GORM so basically usages of functions are same.

conn.Where()
conn.Save()
conn.Create()
conn.Exec()

If you want to get instance of connection to database, you can use:

// Get write connection
// Return *gorm.DB
conn.Instance("write")

// Get read connection
// Return *gorm.DB
conn.Instance("read")

then you can use as usual GORM

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pipet added in v0.0.4

type Pipet struct {
	Driver        string
	ReadDatabases []*gorm.DB
	WriteDatabase *gorm.DB
}

func Init

func Init(driver string) *Pipet

func (*Pipet) Conn added in v0.0.4

func (s *Pipet) Conn() *gorm.DB

func (*Pipet) Create added in v0.0.4

func (s *Pipet) Create(value interface{}) *gorm.DB

func (*Pipet) Exec added in v0.0.4

func (s *Pipet) Exec(sql string, values ...interface{}) *gorm.DB

func (*Pipet) Instance added in v0.0.5

func (s *Pipet) Instance(conn string) *gorm.DB

func (*Pipet) Save added in v0.0.4

func (s *Pipet) Save(value interface{}) *gorm.DB

func (*Pipet) SetRead added in v0.0.4

func (s *Pipet) SetRead(host string, port string, user string, password string, database string)

func (*Pipet) SetWrite added in v0.0.4

func (s *Pipet) SetWrite(host string, port string, user string, password string, database string)

func (*Pipet) Where added in v0.0.4

func (s *Pipet) Where(query interface{}, args ...interface{}) *gorm.DB

Jump to

Keyboard shortcuts

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