data

package
v0.0.0-...-22b4903 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2014 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package data provides the database abstraction layer and helpers for the Phi Mu Alpha Sinfonia - Delta Iota chapter website.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMultipleResults is returned when a query should return only zero or a single
	// result, but returns two or more results.
	ErrMultipleResults = errors.New("db: multiple results returned")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB provides the database abstraction layer for the application.

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

Begin starts a transaction on this database instance.

func (*DB) Close

func (db *DB) Close() error

Close closes and cleans up a database instance.

func (*DB) DeleteNotification

func (db *DB) DeleteNotification(n *models.Notification) error

DeleteNotification starts a transaction, deletes the input Notification by its ID, and attempts to commit the transaction.

func (*DB) DeleteNotificationsByUserID

func (db *DB) DeleteNotificationsByUserID(userID uint64) error

DeleteNotificationsByUserID starts a transaction, deletes all Notifications with the matching user ID, and attempts to commit the transaction.

func (*DB) DeleteSession

func (db *DB) DeleteSession(s *models.Session) error

DeleteSession starts a transaction, deletes the input Session by its ID, and attempts to commit the transaction.

func (*DB) DeleteSessionsByUserID

func (db *DB) DeleteSessionsByUserID(userID uint64) error

DeleteSessionsByUserID starts a transaction, deletes all Sessions with the matching user ID, and attempts to commit the transaction.

func (*DB) DeleteUser

func (db *DB) DeleteUser(u *models.User) error

DeleteUser starts a transaction, deletes the input User by its ID, and attempts to commit the transaction.

func (*DB) InsertNotification

func (db *DB) InsertNotification(n *models.Notification) error

InsertNotification starts a transaction, inserts a new Notification, and attempts to commit the transaction.

func (*DB) InsertSession

func (db *DB) InsertSession(s *models.Session) error

InsertSession starts a transaction, inserts a new Session, and attempts to commit the transaction.

func (*DB) InsertUser

func (db *DB) InsertUser(u *models.User) error

InsertUser starts a transaction, inserts a new User, and attempts to commit the transaction.

func (*DB) IsConstraintFailure

func (db *DB) IsConstraintFailure(err error) bool

IsConstraintFailure returns whether or not an input error is due to a failed database constraint, such as an insert of an item which is not unique.

func (*DB) IsReadonly

func (db *DB) IsReadonly(err error) bool

IsReadonly returns whether or not an input error is due to a readonly database.

func (*DB) Open

func (db *DB) Open(driver string, dsn string) error

Open opens and initializes a database instance.

func (*DB) SelectAllUsers

func (db *DB) SelectAllUsers() ([]*models.User, error)

SelectAllUsers returns a slice of all Users from the database.

func (*DB) SelectNotificationsByUserID

func (db *DB) SelectNotificationsByUserID(userID uint64) ([]*models.Notification, error)

SelectNotificationsByUserID returns a slice of Notifications by user ID from the database.

func (*DB) SelectSessionByKey

func (db *DB) SelectSessionByKey(key string) (*models.Session, error)

SelectSessionByKey returns a single Session by key from the database.

func (*DB) SelectUserByID

func (db *DB) SelectUserByID(id uint64) (*models.User, error)

SelectUserByID returns a single User by ID from the database.

func (*DB) SelectUserByUsername

func (db *DB) SelectUserByUsername(username string) (*models.User, error)

SelectUserByUsername returns a single User by Username from the database.

func (*DB) UpdateNotification

func (db *DB) UpdateNotification(n *models.Notification) error

UpdateNotification starts a transaction, updates the input Notification by its ID, and attempts to commit the transaction.

func (*DB) UpdateSession

func (db *DB) UpdateSession(s *models.Session) error

UpdateSession starts a transaction, updates the input Session by its ID, and attempts to commit the transaction.

func (*DB) UpdateUser

func (db *DB) UpdateUser(u *models.User) error

UpdateUser starts a transaction, updates the input User by its ID, and attempts to commit the transaction.

func (*DB) WithTx

func (db *DB) WithTx(fn func(tx *Tx) error) error

WithTx creates a new wrapped transaction, invokes an input closure, and commits or rolls back the transaction, depending on the result of the closure invocation.

type Rows

type Rows struct {
	*sql.Rows
}

Rows is a wrapped set of database rows, which provides additional methods for interacting directly with custom types.

func (*Rows) ScanNotifications

func (r *Rows) ScanNotifications() ([]*models.Notification, error)

ScanNotifications returns a slice of Notifications from wrapped rows.

func (*Rows) ScanSessions

func (r *Rows) ScanSessions() ([]*models.Session, error)

ScanSessions returns a slice of Sessions from wrapped rows.

func (*Rows) ScanUsers

func (r *Rows) ScanUsers() ([]*models.User, error)

ScanUsers returns a slice of Users from wrapped rows.

type Tx

type Tx struct {
	*sql.Tx
}

Tx is a wrapped database transaction, which provides additional methods for interacting directly with custom types.

func (*Tx) DeleteNotification

func (tx *Tx) DeleteNotification(n *models.Notification) error

DeleteNotification updates the input Notification by its ID, in the context of the current transaction.

func (*Tx) DeleteNotificationsByUserID

func (tx *Tx) DeleteNotificationsByUserID(userID uint64) error

DeleteNotificationsByUserID deletes all Notifications with the input user ID, in the context of the current transaction.

func (*Tx) DeleteSession

func (tx *Tx) DeleteSession(s *models.Session) error

DeleteSession updates the input Session by its ID, in the context of the current transaction.

func (*Tx) DeleteSessionsByUserID

func (tx *Tx) DeleteSessionsByUserID(userID uint64) error

DeleteSessionsByUserID deletes all Sessions with the input user ID, in the context of the current transaction.

func (*Tx) DeleteUser

func (tx *Tx) DeleteUser(u *models.User) error

DeleteUser updates the input User by its ID, in the context of the current transaction.

func (*Tx) InsertNotification

func (tx *Tx) InsertNotification(n *models.Notification) error

InsertNotification inserts a new Notification in the context of the current transaction.

func (*Tx) InsertSession

func (tx *Tx) InsertSession(s *models.Session) error

InsertSession inserts a new Session in the context of the current transaction.

func (*Tx) InsertUser

func (tx *Tx) InsertUser(u *models.User) error

InsertUser inserts a new User in the context of the current transaction.

func (*Tx) UpdateNotification

func (tx *Tx) UpdateNotification(n *models.Notification) error

UpdateNotification updates the input Notification by its ID, in the context of the current transaction.

func (*Tx) UpdateSession

func (tx *Tx) UpdateSession(s *models.Session) error

UpdateSession updates the input Session by its ID, in the context of the current transaction.

func (*Tx) UpdateUser

func (tx *Tx) UpdateUser(u *models.User) error

UpdateUser updates the input User by its ID, in the context of the current transaction.

Directories

Path Synopsis
Package models provides the backing data models for the Phi Mu Alpha Sinfonia - Delta Iota chapter website.
Package models provides the backing data models for the Phi Mu Alpha Sinfonia - Delta Iota chapter website.

Jump to

Keyboard shortcuts

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