datahelper

package module
v0.0.0-...-565c674 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 8 Imported by: 2

README

datahelper

Golang abstraction for mssql-go and sqlite with portable datatable

Disclaimer: This package favors convenience over performance. This should not be used in heavily utilized API.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataHelper

type DataHelper struct {
	DriverName          string            // Driver name set in the configuration file
	ConnectionID        string            // Connection ID set in the configuration file
	AllQueryOK          bool              // Flags if all queries are ok in a non-transaction mode
	Errors              []string          // Errors encountered
	Settings            cfg.Configuration // Settings from the configuration
	CurrentDatabaseInfo *cfg.DatabaseInfo // Current database information
	RowLimitInfo        RowLimiting       // Row limiting information
	// contains filtered or unexported fields
}

DataHelper struct

func NewConnected

func NewConnected(dh *DataHelper, config *cfg.Configuration, ConnectionID ...string) (*DataHelper, bool, error)

NewConnected creates a new connected datahelper. The dh parameter could optionally be supplied by a valid datahelper. Returns : DataHelper, InTransaction and Error

func NewDataHelper

func NewDataHelper(config *cfg.Configuration) *DataHelper

NewDataHelper - creates a new DataHelper

func (*DataHelper) Begin

func (dh *DataHelper) Begin(intr bool) (*sql.Tx, error)

Begin - begins a new transaction

func (*DataHelper) Commit

func (dh *DataHelper) Commit(intr bool) error

Commit - commits a transaction

func (*DataHelper) Connect

func (dh *DataHelper) Connect(ConnectionID ...string) (connected bool, err error)

Connect - connect to the database from configuration set in the NewDataHelper constructor.

func (*DataHelper) ConnectionString

func (dh *DataHelper) ConnectionString() string

ConnectionString - get the current connection string

func (*DataHelper) Discard

func (dh *DataHelper) Discard(PointID string) error

Discard - rejects a named transaction to simulate a save point

func (*DataHelper) Disconnect

func (dh *DataHelper) Disconnect(intr bool) error

Disconnect - disconnect from the database

func (*DataHelper) Exec

func (dh *DataHelper) Exec(preparedQuery string, arg ...interface{}) (sql.Result, error)

Exec - execute queries that does not return rows such us INSERT, DELETE and UPDATE

func (*DataHelper) Exists

func (dh *DataHelper) Exists(tableNameWithParameters string, args ...interface{}) (bool, error)

Exists - checks if the record exists

func (*DataHelper) GetData

func (dh *DataHelper) GetData(preparedQuery string, arg ...interface{}) (*datatable.DataTable, error)

GetData - get data from the database and return in a tabular form

func (*DataHelper) GetDataReader

func (dh *DataHelper) GetDataReader(preparedQuery string, arg ...interface{}) (datatable.Row, error)

GetDataReader - returns a DataTable Row with an internal sql.Row object for iteration.

func (*DataHelper) GetRow

func (dh *DataHelper) GetRow(columns []string, tableNameWithParameters string, args ...interface{}) (SingleRow, error)

GetRow - get a single row result from a query

func (*DataHelper) GetSequence

func (dh *DataHelper) GetSequence(SequenceKey string) (string, error)

GetSequence - get the next sequence based on the sequence key

func (*DataHelper) IsInTransaction

func (dh *DataHelper) IsInTransaction() bool

IsInTransaction - checks whether the database is in transaction

func (*DataHelper) Mark

func (dh *DataHelper) Mark(PointID string) error

Mark - starts a named transaction to simulate a save point

func (*DataHelper) Prepare

func (dh *DataHelper) Prepare(preparedQuery string) (*sql.Stmt, error)

Prepare - prepare a statement

func (*DataHelper) Rollback

func (dh *DataHelper) Rollback(intr bool) error

Rollback - rollbacks a transaction

func (*DataHelper) SetConnMaxLifetime

func (dh *DataHelper) SetConnMaxLifetime(d time.Duration)

SetConnMaxLifetime - connection maximum lifetime

func (*DataHelper) SetMaxIdleConnection

func (dh *DataHelper) SetMaxIdleConnection(max int)

SetMaxIdleConnection - max idle connection

func (*DataHelper) SetMaxOpenConns

func (dh *DataHelper) SetMaxOpenConns(max int)

SetMaxOpenConns - max open connection

type ReadType

type ReadType string

ReadType - read types in data retrieval

const (
	READALL     ReadType = `all`
	READBYKEY   ReadType = `key`
	READBYCODE  ReadType = `code`
	READFORFORM ReadType = `form`
)

ReadTypes for data access

type RowLimitPlacement

type RowLimitPlacement int

RowLimitPlacement - row limit placement of row limits

const (
	RowLimitingFront RowLimitPlacement = 0 // The database query puts row limiting inside the SELECT clause
	RowLimitingRear  RowLimitPlacement = 1 // The database query puts row limiting at the end of the SELECT clause
)

Constants

type RowLimiting

type RowLimiting struct {
	Keyword   string
	Placement RowLimitPlacement
}

RowLimiting - row limiting setup

type SingleRow

type SingleRow struct {
	HasResult bool
	Row       datatable.Row
}

SingleRow struct

Jump to

Keyboard shortcuts

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