database

package
v0.0.0-...-5e43dd1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

For managing authentication database.

Database management stuff.

Commonly used ConnectionHooks.

For managing review DBs.

For managing user DBs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(path string) (*sql.DB, error)

NOTE Caller has to Close the db.

func OpenAuthDB

func OpenAuthDB(path string) (*sql.DB, error)

Opens the authentication database. The caller has to Close the db.

func OpenReviewDB

func OpenReviewDB(path string) (*sql.DB, error)

Opens review database. The caller has to Close the db.

func OpenUserDB

func OpenUserDB(path string) (*sql.DB, error)

Opens database for one user. The caller has to Close the db.

func UpgradeReviewDB

func UpgradeReviewDB(db *sql.DB) error

Upgrades review DB to the latest version.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Wrapper around sql.Conn.

func NewConnection

func NewConnection(
	db *sql.DB,
	ctx context.Context,
	hooks ...ConnectionHook,
) (*Connection, error)

The caller is expected to close the Connection after use.

func (*Connection) Begin

func (c *Connection) Begin() (*sql.Tx, error)

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Exec

func (c *Connection) Exec(query string, args ...any) (sql.Result, error)

func (*Connection) Query

func (c *Connection) Query(query string, args ...any) (*sql.Rows, error)

func (*Connection) QueryRow

func (c *Connection) QueryRow(query string, args ...any) *sql.Row

type ConnectionHook

type ConnectionHook struct {
	// Called after the connection is created.
	Enter func(con *Connection) error

	// Called before the connection is closed.
	Exit func(con *Connection) error
}

func AttachCourse

func AttachCourse(path string) ConnectionHook

Enter: attach course database. Exit: detach course database.

func DefaultConnectionHook

func DefaultConnectionHook() ConnectionHook

type Querier

type Querier interface {
	*sql.DB | *sql.Tx | *Connection

	Begin() (*sql.Tx, error)
	Exec(query string, args ...any) (sql.Result, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
}

Jump to

Keyboard shortcuts

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