db

package
v0.0.0-...-d1a9080 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the connection to the database.

func DB

func DB() *sql.DB

DB returns the current sql.DB instance.

func Init

func Init() error

Init creates the database schema by running all the needed migrations.

func InsertWithID

func InsertWithID(stmt *goqu.InsertDataset, r string) (id int, err error)

InsertWithID executes an insert statement and returns the value of the field given by "r". Depending on the database, it uses different ways to do just that.

func JSONBytes

func JSONBytes(value interface{}) ([]byte, error)

JSONBytes converts a string or a []uint8 to a []byte value. We need this with sqlite and postgresql not returning the same data type for their json fields.

func Open

func Open(dsn string) error

Open opens a database connection and sets internal variables that can be retrieved using DB() (holding the sql.DB reference) and Q() (holding the goqu.Database reference).

func Q

func Q() *goqu.Database

Q returns the current goqu.Database instance.

Types

type Connector

type Connector interface {
	// Dialect returns the connector's dialect
	Dialect() string

	// Open creates a new db connection.
	Open(*url.URL) (*sql.DB, error)

	// HasTable checks if a given table exists in the
	// database. It's used by the migration system.
	HasTable(string) (bool, error)
}

Connector is an interface for a database connector.

func Driver

func Driver() Connector

Driver returns the SQL driver in use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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