dbx

package module
v0.0.0-...-1a16d00 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 8 Imported by: 0

README

Dependencies:

- github.com/jmoiron/sqlx

Example for connection:

connString := fmt.Sprintf("user=%s dbname=%s sslmode=disable password=%s", config.Config.Postgres.Username, config.Config.Postgres.Database, config.Config.Postgres.Password)
db := dbx.MustConnect()
db.QuoteIdentifier = pq.QuoteIdentifier

Example for current methods:

db.Create(&model)
db.Get(&model, id)
db.Select(&[]model, condition)

They all use the Tabler interface, so if the name of the table is not the plural of the struct name, fullfil the interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultQuoteIdentifier

func DefaultQuoteIdentifier(s string) string

func Select

func Select(target interface{}, cond interface{}) error

Types

type DB

type DB struct {
	DB                *sqlx.DB
	QuoteIdentifierFn func(string) string
}

func MustConnect

func MustConnect(dialect, connectionString string) *DB

func Open

func Open(dialect, connectionString string) (*DB, error)

func (*DB) CreateWithDB

func (db *DB) CreateWithDB(i interface{}) error

func (*DB) DeleteWithDB

func (db *DB) DeleteWithDB(target interface{}) error

func (*DB) Get

func (db *DB) Get(target interface{}, id interface{}) error

func (*DB) QuoteIdentifier

func (db *DB) QuoteIdentifier(s string) string

func (*DB) UpdateWithDB

func (db *DB) UpdateWithDB(target interface{}, newValues interface{}) error

type DBAccess

type DBAccess interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row

	MustExec(string, ...interface{}) sql.Result
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRowx(query string, args ...interface{}) *sqlx.Row

	Get(dest interface{}, query string, args ...interface{}) error
	Select(dest interface{}, query string, args ...interface{}) error

	Prepare(query string) (*sql.Stmt, error)
	Preparex(query string) (*sqlx.Stmt, error)
}

type Tabler

type Tabler interface {
	TableName() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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