dbo

package
v0.0.58 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SqlScriptFileExt                     = "sql"
	FileExtensionSeparator               = "."
	TableNamePrefixSeparator             = "_"
	SearchPattern_CreateTableIfNotExists = "CREATE TABLE IF NOT EXISTS %s"
	LastInsertedIdOnError                = -1
	CountOnError                         = -1
	IdOnError                            = 0
)
View Source
const (
	ErrTableNameIsNotFound = "table name is not found"
	ErrFRowsAffectedCount  = "affected rows count error: %v vs %v"
)
View Source
const (
	Query_SaveIncident               = `INSERT INTO %s (Module, Type, Email, UserIPAB) VALUES (?, ?, ?, ?);`
	Query_SaveIncidentWithoutUserIPA = `INSERT INTO %s (Module, Type, Email) VALUES (?, ?, ?);`
)

Query format strings of prepared statements.

Variables

This section is empty.

Functions

func CheckRowsAffected added in v0.0.54

func CheckRowsAffected(sqlResult sql.Result, expectedValue cmb.Count) (err error)

func CheckRowsAffectedAndGetLastInsertedId added in v0.0.54

func CheckRowsAffectedAndGetLastInsertedId(sqlResult sql.Result, expectedValue cmb.Count) (lastInsertedId cmb.Id, err error)

func GetLastInsertedId added in v0.0.54

func GetLastInsertedId(sqlResult sql.Result) (lastInsertedId cmb.Id, err error)

Types

type DatabaseObject

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

DatabaseObject is a common database object, an entity managing all operations related to database.

func NewDatabaseObject

func NewDatabaseObject(settings cs.DbSettings) (dbo *DatabaseObject)

func (*DatabaseObject) DB

func (dbo *DatabaseObject) DB() *sql.DB

func (*DatabaseObject) Fin

func (dbo *DatabaseObject) Fin() (err error)

Fin disconnects from the database.

func (*DatabaseObject) Init

func (dbo *DatabaseObject) Init(preparedStatementQueryStrings []string) (err error)

Init connects to the database, initialises the tables and prepares SQL statements. Before calling this method, a user must manually initialise table names and a list of query strings which will be used as prepared statements.

func (*DatabaseObject) LockForReading

func (dbo *DatabaseObject) LockForReading()

LockForReading locks database access for reading operations.

func (*DatabaseObject) LockForWriting

func (dbo *DatabaseObject) LockForWriting()

LockForWriting locks database access for writing operations.

func (*DatabaseObject) PrefixTableName

func (dbo *DatabaseObject) PrefixTableName(tableName string) (tableNameFull string)

func (*DatabaseObject) PreparedStatement

func (dbo *DatabaseObject) PreparedStatement(psIndex int) *sql.Stmt

func (*DatabaseObject) ProbeDb

func (dbo *DatabaseObject) ProbeDb() (err error)

ProbeDb pings the database server.

func (*DatabaseObject) UnlockAfterReading

func (dbo *DatabaseObject) UnlockAfterReading()

UnlockAfterReading unlocks database access after reading operations.

func (*DatabaseObject) UnlockAfterWriting

func (dbo *DatabaseObject) UnlockAfterWriting()

UnlockAfterWriting unlocks database access after writing operations.

Jump to

Keyboard shortcuts

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