gomysql

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 3 Imported by: 0

README

go-mysql

An easy to use Mockable db interface for mysql

Go Report Card


    mm := &MyDB{
	    Host:     "localhost:3306",
	    User:     "test",
	    Password: "test",
	    Database: "test",				
    }
    m := mm.New()
    m.Connect()
    m.Insert(query, args...)
    m.Update(query, args...)
    m.Get(query, args...)
    m.GetList(query, args...)
    m.Delete(query, args...)

Also Supports Transactions

 mm := &MyDB{
	    Host:     "localhost:3306",
	    User:     "test",
	    Password: "test",
	    Database: "test",				
    }
    m := mm.New()
    m.Connect()
    tr := m.BeginTransaction()
    tr.Insert(query, args...)
    tr.Update(query, args...)
    tr.Get(query, args...)
    tr.GetList(query, args...)
    tr.Delete(query, args...)
    tr.Commit()
    //Or
    tr.Rollback()


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Connect() bool
	BeginTransaction() Transaction
	Test(query string, args ...any) *DbRow
	Insert(query string, args ...any) (bool, int64)
	Update(query string, args ...any) bool
	Get(query string, args ...any) *DbRow
	GetList(query string, args ...any) *DbRows
	Delete(query string, args ...any) bool
	Close() bool
}

Database Database

type DbRow

type DbRow struct {
	Columns []string
	Row     []string
}

DbRow database row

type DbRows

type DbRows struct {
	Columns []string
	Rows    [][]string
}

DbRows array of database rows

type MyDB

type MyDB struct {
	Host     string
	User     string
	Password string
	Database string
	// contains filtered or unexported fields
}

MyDB MyDB

func (*MyDB) BeginTransaction

func (m *MyDB) BeginTransaction() Transaction

BeginTransaction BeginTransaction

func (*MyDB) Close

func (m *MyDB) Close() bool

Close Close

func (*MyDB) Connect

func (m *MyDB) Connect() bool

Connect Connect

func (*MyDB) Delete

func (m *MyDB) Delete(query string, args ...any) bool

Delete Delete

func (*MyDB) Get

func (m *MyDB) Get(query string, args ...any) *DbRow

Get Get

func (*MyDB) GetList

func (m *MyDB) GetList(query string, args ...any) *DbRows

GetList GetList

func (*MyDB) Insert

func (m *MyDB) Insert(query string, args ...any) (bool, int64)

Insert Insert

func (*MyDB) New

func (m *MyDB) New() Database

New NewDatabase

func (*MyDB) Test

func (m *MyDB) Test(query string, args ...any) *DbRow

Test Test

func (*MyDB) Update

func (m *MyDB) Update(query string, args ...any) bool

Update Update

type MyDBMock

type MyDBMock struct {
	Host     string
	User     string
	Password string
	Database string

	MockConnectSuccess  bool
	MockCloseSuccess    bool
	MockCommitSuccess   bool
	MockRollbackSuccess bool

	MockInsertSuccess1 bool
	MockInsertSuccess2 bool
	MockInsertSuccess3 bool
	MockInsertSuccess4 bool
	MockInsertSuccess5 bool
	MockInsertSuccess6 bool
	MockInsertSuccess7 bool
	MockInsertSuccess8 bool

	MockInsertID1 int64
	MockInsertID2 int64
	MockInsertID3 int64
	MockInsertID4 int64
	MockInsertID5 int64
	MockInsertID6 int64
	MockInsertID7 int64
	MockInsertID8 int64

	MockUpdateSuccess1 bool
	MockUpdateSuccess2 bool
	MockUpdateSuccess3 bool
	MockUpdateSuccess4 bool

	MockDeleteSuccess1 bool
	MockDeleteSuccess2 bool
	MockDeleteSuccess3 bool
	MockDeleteSuccess4 bool
	MockDeleteSuccess5 bool
	MockDeleteSuccess6 bool
	MockDeleteSuccess7 bool
	MockDeleteSuccess8 bool

	MockTestRow *DbRow

	MockRow1 *DbRow
	MockRow2 *DbRow
	MockRow3 *DbRow
	MockRow4 *DbRow
	MockRow5 *DbRow
	MockRow6 *DbRow
	MockRow7 *DbRow
	MockRow8 *DbRow

	MockRows1 *DbRows
	MockRows2 *DbRows
	MockRows3 *DbRows
	MockRows4 *DbRows
	MockRows5 *DbRows
	MockRows6 *DbRows
	MockRows7 *DbRows
	MockRows8 *DbRows
	// contains filtered or unexported fields
}

MyDBMock MyDBMock

func (*MyDBMock) BeginTransaction

func (m *MyDBMock) BeginTransaction() Transaction

BeginTransaction BeginTransaction

func (*MyDBMock) Close

func (m *MyDBMock) Close() bool

Close Close

func (*MyDBMock) Connect

func (m *MyDBMock) Connect() bool

Connect Connect

func (*MyDBMock) Delete

func (m *MyDBMock) Delete(query string, args ...any) bool

Delete Delete

func (*MyDBMock) Get

func (m *MyDBMock) Get(query string, args ...any) *DbRow

Get Get

func (*MyDBMock) GetList

func (m *MyDBMock) GetList(query string, args ...any) *DbRows

GetList GetList

func (*MyDBMock) GetNewDatabase

func (m *MyDBMock) GetNewDatabase() Database

GetNewDatabase GetNewDatabase

func (*MyDBMock) Insert

func (m *MyDBMock) Insert(query string, args ...any) (bool, int64)

Insert Insert

func (*MyDBMock) New added in v1.0.3

func (m *MyDBMock) New() Database

New New

func (*MyDBMock) Test

func (m *MyDBMock) Test(query string, args ...any) *DbRow

Test Test

func (*MyDBMock) Update

func (m *MyDBMock) Update(query string, args ...any) bool

Update Update

type MyDbTx

type MyDbTx struct {
	Tx *sql.Tx
}

MyDbTx MyDbTx

func (*MyDbTx) Commit

func (t *MyDbTx) Commit() bool

Commit Commit

func (*MyDbTx) Delete

func (t *MyDbTx) Delete(query string, args ...any) bool

Delete Delete

func (*MyDbTx) Insert

func (t *MyDbTx) Insert(query string, args ...any) (bool, int64)

Insert Insert

func (*MyDbTx) Rollback

func (t *MyDbTx) Rollback() bool

Rollback Rollback

func (*MyDbTx) Update

func (t *MyDbTx) Update(query string, args ...any) bool

Update Update

type MyDbTxMock

type MyDbTxMock struct {
	Tx       *sql.Tx
	MyDBMock *MyDBMock
}

MyDbTxMock MyDbTxMock

func (*MyDbTxMock) Commit

func (t *MyDbTxMock) Commit() bool

Commit Commit

func (*MyDbTxMock) Delete

func (t *MyDbTxMock) Delete(query string, args ...any) bool

Delete Delete

func (*MyDbTxMock) Insert

func (t *MyDbTxMock) Insert(query string, args ...any) (bool, int64)

Insert Insert

func (*MyDbTxMock) Rollback

func (t *MyDbTxMock) Rollback() bool

Rollback Rollback

func (*MyDbTxMock) Update

func (t *MyDbTxMock) Update(query string, args ...any) bool

Update Update

type Transaction

type Transaction interface {
	Insert(query string, args ...any) (bool, int64)
	Update(query string, args ...any) bool
	Delete(query string, args ...any) bool
	Commit() bool
	Rollback() bool
}

Transaction transaction

Jump to

Keyboard shortcuts

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