adapters

package
v0.0.0-...-598a1f7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: AGPL-3.0, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package adapters offers adapters for pouplar databases

Index

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

func (db *Adapter) InsertSQL(pk string) string

InsertSQL provides extra SQL for end of insert statement (RETURNING for psql)

func (*Adapter) ParseTime

func (db *Adapter) ParseTime(s string) (time.Time, error)

ParseTime - given a string, return a time object built from it

func (*Adapter) Placeholder

func (db *Adapter) Placeholder(i int) string

Placeholder is the argument placeholder for this adapter

func (*Adapter) QuoteField

func (db *Adapter) QuoteField(name string) string

QuoteField quotes a table name or column name

func (*Adapter) ReplaceArgPlaceholder

func (db *Adapter) ReplaceArgPlaceholder(sql string, args []interface{}) string

ReplaceArgPlaceholder does no replacements by default, and use default ? placeholder for args psql requires a different placeholder numericall labelled

func (*Adapter) TimeString

func (db *Adapter) TimeString(t time.Time) string

TimeString - given a time, return the standard string representation

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) Close

func (db *MysqlAdapter) Close() error

Close the database

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) Close

func (db *PostgresqlAdapter) Close() error

Close the database

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) Close

func (db *SqliteAdapter) Close() error

Close the database

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

Jump to

Keyboard shortcuts

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