Documentation ¶
Overview ¶
Package adapters offers adapters for pouplar databases
Index ¶
- type Adapter
- func (db *Adapter) InsertSQL(pk string) string
- func (db *Adapter) ParseTime(s string) (time.Time, error)
- func (db *Adapter) Placeholder(i int) string
- func (db *Adapter) QuoteField(name string) string
- func (db *Adapter) ReplaceArgPlaceholder(sql string, args []interface{}) string
- func (db *Adapter) TimeString(t time.Time) string
- type Database
- type MysqlAdapter
- func (db *MysqlAdapter) Close() error
- func (db *MysqlAdapter) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *MysqlAdapter) Insert(query string, args ...interface{}) (id int64, err error)
- func (db *MysqlAdapter) Open(opts map[string]string) error
- func (db *MysqlAdapter) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *MysqlAdapter) QuoteField(name string) string
- func (db *MysqlAdapter) SQLDB() *sql.DB
- type PostgresqlAdapter
- func (db *PostgresqlAdapter) Close() error
- func (db *PostgresqlAdapter) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *PostgresqlAdapter) Insert(sql string, args ...interface{}) (id int64, err error)
- func (db *PostgresqlAdapter) InsertSQL(pk string) string
- func (db *PostgresqlAdapter) Open(opts map[string]string) error
- func (db *PostgresqlAdapter) Placeholder(i int) string
- func (db *PostgresqlAdapter) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *PostgresqlAdapter) SQLDB() *sql.DB
- type SqliteAdapter
- func (db *SqliteAdapter) Close() error
- func (db *SqliteAdapter) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *SqliteAdapter) Insert(query string, args ...interface{}) (id int64, err error)
- func (db *SqliteAdapter) Open(opts map[string]string) error
- func (db *SqliteAdapter) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *SqliteAdapter) SQLDB() *sql.DB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is a struct defining a few functions used by all adapters
func (*Adapter) InsertSQL ¶
InsertSQL provides extra SQL for end of insert statement (RETURNING for psql)
func (*Adapter) Placeholder ¶
Placeholder is the argument placeholder for this adapter
func (*Adapter) QuoteField ¶
QuoteField quotes a table name or column name
func (*Adapter) ReplaceArgPlaceholder ¶
ReplaceArgPlaceholder does no replacements by default, and use default ? placeholder for args psql requires a different placeholder numericall labelled
type Database ¶
type Database interface { // Open and close Open(opts map[string]string) error Close() error SQLDB() *sql.DB // Execute queries with or without returned rows Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) // Insert a record, returning id Insert(sql string, args ...interface{}) (id int64, err error) // Return extra SQL for insert statement (see psql) InsertSQL(pk string) string // A format string for the arg placeholder Placeholder(i int) string // Quote Table and Column names QuoteField(name string) string // Convert a time to a string TimeString(t time.Time) string // Convert a string to a time ParseTime(s string) (time.Time, error) }
Database provides an interface for database adapters to conform to
type MysqlAdapter ¶
type MysqlAdapter struct { *Adapter // contains filtered or unexported fields }
MysqlAdapter conforms to the query.Database interface
func (*MysqlAdapter) Exec ¶
func (db *MysqlAdapter) Exec(query string, args ...interface{}) (sql.Result, error)
Exec - use this for non-select statements
func (*MysqlAdapter) Insert ¶
func (db *MysqlAdapter) Insert(query string, args ...interface{}) (id int64, err error)
Insert a record with params and return the id - psql behaves differently
func (*MysqlAdapter) Open ¶
func (db *MysqlAdapter) Open(opts map[string]string) error
Open this database
func (*MysqlAdapter) Query ¶
func (db *MysqlAdapter) Query(query string, args ...interface{}) (*sql.Rows, error)
Query SQL execute - NB caller must call use defer rows.Close() with rows returned
func (*MysqlAdapter) QuoteField ¶
func (db *MysqlAdapter) QuoteField(name string) string
QuoteField quotes a table name or column name
func (*MysqlAdapter) SQLDB ¶
func (db *MysqlAdapter) SQLDB() *sql.DB
SQLDB returns the internal db.sqlDB pointer
type PostgresqlAdapter ¶
type PostgresqlAdapter struct { *Adapter // contains filtered or unexported fields }
PostgresqlAdapter conforms to the query.Database interface
func (*PostgresqlAdapter) Exec ¶
func (db *PostgresqlAdapter) Exec(query string, args ...interface{}) (sql.Result, error)
Exec - use this for non-select statements
func (*PostgresqlAdapter) Insert ¶
func (db *PostgresqlAdapter) Insert(sql string, args ...interface{}) (id int64, err error)
Insert a record with params and return the id
func (*PostgresqlAdapter) InsertSQL ¶
func (db *PostgresqlAdapter) InsertSQL(pk string) string
InsertSQL is extra SQL for end of insert statement (RETURNING for psql)
func (*PostgresqlAdapter) Open ¶
func (db *PostgresqlAdapter) Open(opts map[string]string) error
Open this database with the given options opts map keys:adapter, user, password, db, host, port, params (give extra parameters in the params option) Additional options available are detailed in the pq driver docs at https://godoc.org/github.com/lib/pq
func (*PostgresqlAdapter) Placeholder ¶
func (db *PostgresqlAdapter) Placeholder(i int) string
Placeholder returns the db placeholder
func (*PostgresqlAdapter) Query ¶
func (db *PostgresqlAdapter) Query(query string, args ...interface{}) (*sql.Rows, error)
Query executes query SQL - NB caller must call use defer rows.Close() with rows returned
func (*PostgresqlAdapter) SQLDB ¶
func (db *PostgresqlAdapter) SQLDB() *sql.DB
SQLDB returns the internal db.sqlDB pointer
type SqliteAdapter ¶
type SqliteAdapter struct { *Adapter Mutex *sync.RWMutex // contains filtered or unexported fields }
SqliteAdapter conforms to the query.Database interface
func (*SqliteAdapter) Exec ¶
func (db *SqliteAdapter) Exec(query string, args ...interface{}) (sql.Result, error)
Exec - use this for non-select statements
func (*SqliteAdapter) Insert ¶
func (db *SqliteAdapter) Insert(query string, args ...interface{}) (id int64, err error)
Insert a record with params and return the id - psql behaves differently
func (*SqliteAdapter) Open ¶
func (db *SqliteAdapter) Open(opts map[string]string) error
Open this database
func (*SqliteAdapter) Query ¶
func (db *SqliteAdapter) Query(query string, args ...interface{}) (*sql.Rows, error)
Query execute Query SQL - NB caller must call use defer rows.Close() with rows returned
func (*SqliteAdapter) SQLDB ¶
func (db *SqliteAdapter) SQLDB() *sql.DB
SQLDB returns the internal db.sqlDB pointer