Documentation ¶
Index ¶
- type Connection
- func (conn *Connection) Close() error
- func (conn *Connection) CountRows(table string) (int64, error)
- func (conn *Connection) CountRowsWhere(table string, cond string) (int64, error)
- func (conn *Connection) CreateTableFromObject(table string, object interface{}) error
- func (conn *Connection) DeleteObject(table string, object interface{}) error
- func (conn *Connection) DropTable(table string) error
- func (conn *Connection) InsertObject(table string, object interface{}) (int, error)
- func (conn *Connection) Lock() error
- func (conn *Connection) OldestEntry(object interface{}, table string, timestampCol string) (interface{}, error)
- func (conn *Connection) SelectForUpdate(object interface{}, table string, cond string, args ...interface{}) ([]interface{}, error)
- func (conn *Connection) SelectFrom(object interface{}, table string) ([]interface{}, error)
- func (conn *Connection) SelectFromWhere(object interface{}, table string, cond string, args ...interface{}) ([]interface{}, error)
- func (conn *Connection) Unlock() error
- func (conn *Connection) UpdateObject(table string, object interface{}) error
- type ConnectionConfig
- type Count
- type Driver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection wraps the sql.DB type.
func Connect ¶
func Connect(creds ConnectionConfig) (*Connection, error)
Connect establishes and returns a connection to the SQL database specified by the ConnectionConfig
func (*Connection) Close ¶
func (conn *Connection) Close() error
Close closes the connection to the Database receiver.
func (*Connection) CountRows ¶
func (conn *Connection) CountRows(table string) (int64, error)
CountRows accepts a table name and returns the number of rows in that table.
func (*Connection) CountRowsWhere ¶
func (conn *Connection) CountRowsWhere(table string, cond string) (int64, error)
CountRowsWhere accepts a table name and condition statement and returns the number of rows in that table that meet the condition
func (*Connection) CreateTableFromObject ¶
func (conn *Connection) CreateTableFromObject(table string, object interface{}) error
CreateTableFromObject creates an SQL table with the given name from the type of the provided object using the Connection receiver. The provided object must be a structure where:
- Each field is annotated with an "sql" tag. Fields may also be annotated with a "typ" or "opt" tag to override their default settings: - The "sql" tag denotes the column name (e.g., "id"). - The "typ" tag denotes the column type (e.g., "SERIAL"). - The "opt" tag denotes column constraints (e.g., "PRIMARY KEY").
- One field must be a 32-bit integer that corresponds to the "id" column.
func (*Connection) DeleteObject ¶
func (conn *Connection) DeleteObject(table string, object interface{}) error
DeleteObject deletes the given object from the specified table.
func (*Connection) DropTable ¶
func (conn *Connection) DropTable(table string) error
DropTable drops the given table from the Connection receiver.
func (*Connection) InsertObject ¶
func (conn *Connection) InsertObject(table string, object interface{}) (int, error)
InsertObject inserts the given object into the specified table and returns the record ID of the inserted row.
func (*Connection) Lock ¶
func (conn *Connection) Lock() error
Lock will execute the SQL BEGIN command which aids in concurrent operations Unlock must be called once the transaction is complete.
func (*Connection) OldestEntry ¶
func (conn *Connection) OldestEntry(object interface{}, table string, timestampCol string) (interface{}, error)
OldestEntry returns the oldest row in the given table
func (*Connection) SelectForUpdate ¶
func (conn *Connection) SelectForUpdate(object interface{}, table string, cond string, args ...interface{}) ([]interface{}, error)
SelectForUpdate is to be used in conjuction with Lock and Unlock to facilitate row locking TODO add this to standard select but use arguments instead of new function
func (*Connection) SelectFrom ¶
func (conn *Connection) SelectFrom(object interface{}, table string) ([]interface{}, error)
SelectFrom executes a SELECT FROM query on the Connection receiver over the given object type and table.
func (*Connection) SelectFromWhere ¶
func (conn *Connection) SelectFromWhere(object interface{}, table string, cond string, args ...interface{}) ([]interface{}, error)
SelectFromWhere executes a SELECT FROM WHERE query on the Connection receiver over the given object type, table, and conditional. Additional arguments are substituted into the conditional in a style similar to printf().
func (*Connection) Unlock ¶
func (conn *Connection) Unlock() error
Unlock will execute the SQL END command
func (*Connection) UpdateObject ¶
func (conn *Connection) UpdateObject(table string, object interface{}) error
UpdateObject updates the given object in the specified table.
type ConnectionConfig ¶
type ConnectionConfig struct { Host string Port string Database string User string Password string Driver Driver }
ConnectionConfig are required to establish a connection to a Db