gosql

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

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

Go to latest
Published: Oct 29, 2019 License: LGPL-3.0 Imports: 11 Imported by: 0

README

gosql

Utility tools for working with sql databases

Instalation

$ go get github.com/asmarchenko/gosql

MySQL Databases:

  • autoclosable connections
  • supporting transactions
  • connections pool
  • mysql handler
  • custom ResultSet struct for java developers :)

MySQL examples:

Create connection:

db, err = gosql.NewMySQLConnection("localhost", 3306, "username", "password", "dbname")

Create connections pool:

config := gosql.NewMySQLConfig("localhost", 3306, "username", "password", "dbname")
poolSize := 100

pool, err := gosql.NewMySQLConnectionPool(poolSize, config)
defer pool.CloseAll()

connection := pool.Get()
......
pool.Release(connection)

Working with MySQL HANDLER:

handler := dBase.CreateMySQLHandler("table_name")
defer handler.Close()

for handler.HasNext() {
	result := handler.Next("id < 100", "index-field", 1000)
	for result.Next() {
		......
	}
}

SQLite3 Databases:

Create connection:

db, err := gosql.NewSQLiteConnection("/tmp/sqlite.db")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Index int
	Name  string
	Value []byte
}

type InsertStmt

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

//////////////////////////////////////////////////////////// /////////////////// INSERT & REPLACE /////////////////////// ////////////////////////////////////////////////////////////

func (*InsertStmt) Fields

func (in *InsertStmt) Fields(fields ...string) *InsertStmt

func (*InsertStmt) ReturnGeneratedKey

func (in *InsertStmt) ReturnGeneratedKey() int64

func (*InsertStmt) Run

func (in *InsertStmt) Run() (int64, *SQLError)

func (*InsertStmt) String

func (in *InsertStmt) String() string

func (*InsertStmt) Value

func (in *InsertStmt) Value(values ...interface{}) *InsertStmt

type MySQLConfig

type MySQLConfig struct {
	Host   string
	Port   int
	User   string
	Pass   string
	DbName string
}

////////////////// MySQLConfig ////////////////////////

func NewMySQLConfig

func NewMySQLConfig(host string, port int, user string, password string, dataBase string) *MySQLConfig

func (*MySQLConfig) String

func (conf *MySQLConfig) String() string

type MySQLConnection

type MySQLConnection struct {
	Config *MySQLConfig
	// contains filtered or unexported fields
}

///////////////// MySQLConnection //////////////////////

func CreateMySQLConnection

func CreateMySQLConnection(config *MySQLConfig) (MySQLConnection, error)

func NewMySQLConnection

func NewMySQLConnection(host string, port int, user string, password string, dataBase string) (MySQLConnection, error)

func (*MySQLConnection) Close

func (db *MySQLConnection) Close()

func (*MySQLConnection) Commit

func (db *MySQLConnection) Commit() *SQLError

func (*MySQLConnection) CreateMySQLHandler

func (db *MySQLConnection) CreateMySQLHandler(table string) *MySQLHandler

func (*MySQLConnection) DumpByQuery

func (db *MySQLConnection) DumpByQuery(query string, tables ...string) ([]string, *SQLError)

//////////////////////////////////////////////////////////// ///////////////////// DUMPING DATA ///////////////////////// ////////////////////////////////////////////////////////////

func (*MySQLConnection) DumpTable

func (db *MySQLConnection) DumpTable(tableName, whereCond string, limit int) ([]string, *SQLError)

func (*MySQLConnection) ExecuteCall

func (db *MySQLConnection) ExecuteCall(procedureName string, params ...interface{}) (ResultSet, *SQLError)

func (*MySQLConnection) ExecuteInsert

func (db *MySQLConnection) ExecuteInsert(query string, params ...interface{}) (int64, *SQLError)

func (*MySQLConnection) ExecuteUpdate

func (db *MySQLConnection) ExecuteUpdate(query string, params ...interface{}) (int64, *SQLError)

func (*MySQLConnection) Hash

func (db *MySQLConnection) Hash() uint32

func (*MySQLConnection) Insert

func (db *MySQLConnection) Insert(table string) *InsertStmt

func (*MySQLConnection) Replace

func (db *MySQLConnection) Replace(table string) *InsertStmt

func (*MySQLConnection) Rollback

func (db *MySQLConnection) Rollback() *SQLError

func (*MySQLConnection) Select

func (db *MySQLConnection) Select(query string, params ...interface{}) (ResultSet, *SQLError)

returns ResutSet struct like an java object

func (*MySQLConnection) SelectNative

func (db *MySQLConnection) SelectNative(query string, params ...interface{}) (*sql.Rows, *SQLError)

returns native *sql.Rows

func (*MySQLConnection) String

func (db *MySQLConnection) String() string

func (*MySQLConnection) Transaction

func (db *MySQLConnection) Transaction() *SQLError

func (*MySQLConnection) Update

func (db *MySQLConnection) Update(table string) *UpdateStmt

type MySQLConnectionPool

type MySQLConnectionPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

/////////////// MySQLConnectionPool ////////////////////

func NewMySQLConnectionPool

func NewMySQLConnectionPool(size int, config *MySQLConfig) (*MySQLConnectionPool, error)

func (*MySQLConnectionPool) CloseAll

func (pool *MySQLConnectionPool) CloseAll()

func (*MySQLConnectionPool) Get

func (pool *MySQLConnectionPool) Get() *MySQLConnection

func (*MySQLConnectionPool) Release

func (pool *MySQLConnectionPool) Release(connection *MySQLConnection)

func (*MySQLConnectionPool) Size

func (pool *MySQLConnectionPool) Size() int

func (*MySQLConnectionPool) String

func (pool *MySQLConnectionPool) String() string

type MySQLHandler

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

//////////////////////////////////////////////////////////// /////////////////////// HANDLER //////////////////////////// ////////////////////////////////////////////////////////////

func (*MySQLHandler) Close

func (handler *MySQLHandler) Close()

func (*MySQLHandler) HasNext

func (handler *MySQLHandler) HasNext() bool

func (*MySQLHandler) Next

func (handler *MySQLHandler) Next(condition, keyName string, limit int) ResultSet

func (*MySQLHandler) Prev

func (handler *MySQLHandler) Prev(condition, keyName string, limit int) ResultSet

type ResultSet

type ResultSet struct {
	Rows []Row
	// contains filtered or unexported fields
}

func (*ResultSet) GetBytes

func (rs *ResultSet) GetBytes(column interface{}) []byte

func (*ResultSet) GetInt

func (rs *ResultSet) GetInt(column interface{}) int

func (*ResultSet) GetLong

func (rs *ResultSet) GetLong(column interface{}) int64

func (*ResultSet) GetMetaData

func (rs *ResultSet) GetMetaData() *ResultSetMetaData

func (*ResultSet) GetString

func (rs *ResultSet) GetString(column interface{}) string

func (*ResultSet) MergeWith

func (rs *ResultSet) MergeWith(rs2 ResultSet)

func (*ResultSet) Next

func (rs *ResultSet) Next() bool

func (*ResultSet) Print

func (rs *ResultSet) Print()

func (*ResultSet) Size

func (rs *ResultSet) Size() int

type ResultSetMetaData

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

func (*ResultSetMetaData) GetColumnCount

func (rsmd *ResultSetMetaData) GetColumnCount() int

func (*ResultSetMetaData) GetColumnName

func (rsmd *ResultSetMetaData) GetColumnName(i int) string

func (*ResultSetMetaData) GetColumnType

func (rsmd *ResultSetMetaData) GetColumnType(i int) string

func (*ResultSetMetaData) Hash

func (rsmd *ResultSetMetaData) Hash() uint32

type Row

type Row struct {
	Values []Cell
}

func NewRow

func NewRow() Row

type SQLError

type SQLError struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

func (*SQLError) String

func (err *SQLError) String() string

type SQLiteConnection

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

func NewSQLiteConnection

func NewSQLiteConnection(path string) (*SQLiteConnection, error)

func (*SQLiteConnection) Close

func (con *SQLiteConnection) Close()

func (*SQLiteConnection) ExecuteInsert

func (con *SQLiteConnection) ExecuteInsert(query string, params ...interface{}) (int64, error)

returns last insert id or error

func (*SQLiteConnection) ExecuteQuery

func (con *SQLiteConnection) ExecuteQuery(query string, params ...interface{}) (ResultSet, error)

returns ResutSet struct like an java object

func (*SQLiteConnection) ExecuteUpdate

func (con *SQLiteConnection) ExecuteUpdate(query string, params ...interface{}) (int64, error)

returns affected rows count or error

type UpdateStmt

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

//////////////////////////////////////////////////////////// //////////////////////// UPDATE //////////////////////////// ////////////////////////////////////////////////////////////

func (*UpdateStmt) Limit

func (up *UpdateStmt) Limit(limit int) *UpdateStmt

func (*UpdateStmt) Run

func (up *UpdateStmt) Run() (int64, *SQLError)

func (*UpdateStmt) SetField

func (up *UpdateStmt) SetField(fName string, fValue interface{}) *UpdateStmt

func (*UpdateStmt) String

func (up *UpdateStmt) String() string

func (*UpdateStmt) WhereField

func (up *UpdateStmt) WhereField(fName string, fValue interface{}) *UpdateStmt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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