gocockroachdb

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 3 Imported by: 0

README

go-cockroachdb

A simple mockable cockroach db interface

Go Report Card


    // Connecting to local insecure CockroachDB
    // For production cluster add password and set SslMode and Sslrootrert
     cc := &CockRDB{ 
			c.Database = "customer_orders"
			c.Host = "localhost"
			c.Port = "26257"
			c.User = "root"
			c.Sslmode = "disable"
    }

  
    c := cc.New()
    c.Connect()
    //Insert requires  RETURNING id on end of prepared statement query
        //Example: "insert into carrier (carrier, type, store_id) values($1, $2, $3) RETURNING id"
    c.Insert(query, args...)
    c.Update(query, args...)
    c.Get(query, args...)
    c.GetList(query, args...)
    c.Delete(query, args...)

Also Supports Transactions


    cc := &CockRDB{ 
			c.Database = "customer_orders"
			c.Host = "localhost"
			c.Port = "26257"
			c.User = "root"
			c.Sslmode = "disable"
    }

  
    c := cc.New()
    c.Connect()
    tr := c.BeginTransaction()
    //Insert requires  RETURNING id on end of prepared statement query
        //Example: "insert into carrier (carrier, type, store_id) values($1, $2, $3) RETURNING id"
    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 CockDbMock

type CockDbMock struct {
	Host        string
	User        string
	Password    string
	Database    string
	Port        string
	Sslmode     string
	Sslrootcert 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

	MockExecSuccess bool
	MockExecError   error
	// contains filtered or unexported fields
}

func (*CockDbMock) BeginTransaction

func (c *CockDbMock) BeginTransaction() Transaction

BeginTransaction BeginTransaction

func (*CockDbMock) Close

func (c *CockDbMock) Close() bool

Close Close

func (*CockDbMock) Connect

func (c *CockDbMock) Connect() bool

Connect Connect

func (*CockDbMock) Delete

func (c *CockDbMock) Delete(query string, args ...any) bool

Delete Delete

func (*CockDbMock) Exec added in v1.0.1

func (c *CockDbMock) Exec(query string) (bool, error)

func (*CockDbMock) Get

func (c *CockDbMock) Get(query string, args ...any) *DbRow

Get Get

func (*CockDbMock) GetList

func (c *CockDbMock) GetList(query string, args ...any) *DbRows

GetList GetList

func (*CockDbMock) Insert

func (c *CockDbMock) Insert(query string, args ...any) (bool, int64)

Insert Insert

func (*CockDbMock) New

func (c *CockDbMock) New() Database

New New

func (*CockDbMock) Test

func (c *CockDbMock) Test(query string, args ...any) *DbRow

Test Test

func (*CockDbMock) Update

func (c *CockDbMock) Update(query string, args ...any) bool

Update Update

type CockDbTx

type CockDbTx struct {
	Tx *sql.Tx
}

CockDbTx CockDbTx

func (*CockDbTx) Commit

func (t *CockDbTx) Commit() bool

Commit Commit

func (*CockDbTx) Delete

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

Delete Delete

func (*CockDbTx) Insert

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

Insert Insert

func (*CockDbTx) Rollback

func (t *CockDbTx) Rollback() bool

Rollback Rollback

func (*CockDbTx) Update

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

Update Update

type CockDbTxMock

type CockDbTxMock struct {
	Tx         *sql.Tx
	CockDbMock *CockDbMock
}

CockDbTxMock CockDbTxMock

func (*CockDbTxMock) Commit

func (t *CockDbTxMock) Commit() bool

Commit Commit

func (*CockDbTxMock) Delete

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

Delete Delete

func (*CockDbTxMock) Insert

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

Insert Insert

func (*CockDbTxMock) Rollback

func (t *CockDbTxMock) Rollback() bool

Rollback Rollback

func (*CockDbTxMock) Update

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

Update Update

type CockRDB added in v1.0.4

type CockRDB struct {
	Host        string
	User        string
	Password    string
	Database    string
	Port        string
	Sslmode     string
	Sslrootcert string
	// contains filtered or unexported fields
}

CockDB CockDB

func (*CockRDB) BeginTransaction added in v1.0.4

func (c *CockRDB) BeginTransaction() Transaction

BeginTransaction BeginTransaction

func (*CockRDB) Close added in v1.0.4

func (c *CockRDB) Close() bool

func (*CockRDB) Connect added in v1.0.4

func (c *CockRDB) Connect() bool

Connect Connect

func (*CockRDB) Delete added in v1.0.4

func (c *CockRDB) Delete(query string, args ...any) bool

Delete Delete

func (*CockRDB) Exec added in v1.0.4

func (c *CockRDB) Exec(query string) (bool, error)

func (*CockRDB) Get added in v1.0.4

func (c *CockRDB) Get(query string, args ...any) *DbRow

Get Get

func (*CockRDB) GetList added in v1.0.4

func (c *CockRDB) GetList(query string, args ...any) *DbRows

GetList GetList

func (*CockRDB) Insert added in v1.0.4

func (c *CockRDB) Insert(query string, args ...any) (bool, int64)

Insert Insert requires use of RETURNING id on end of insert query

func (*CockRDB) New added in v1.0.4

func (c *CockRDB) New() Database

func (*CockRDB) Test added in v1.0.4

func (c *CockRDB) Test(query string, args ...any) *DbRow

Test Test

func (*CockRDB) Update added in v1.0.4

func (c *CockRDB) Update(query string, args ...any) bool

Update Update

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
	Exec(query string) (bool, error)
	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 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