dal

package
v0.0.0-...-f320ac6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2015 License: MIT Imports: 7 Imported by: 0

README

Data Access Layer

(Definition from Wikipedia)

A data access layer (DAL) in computer software, is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database. This acronym is prevalently used in Microsoft ASP.NET environments.

For example, the DAL might return a reference to an object (in terms of object-oriented programming) complete with its attributes instead of a row of fields from a database table. This allows the client (or user) modules to be created with a higher level of abstraction. This kind of model could be implemented by creating a class of data access methods that directly reference a corresponding set of database stored procedures. Another implementation could potentially retrieve or write records to or from a file system. The DAL hides this complexity of the underlying data store from the external world.

This directory is the equivalent of "models" directory in other web frameworks. Put all of you database logic here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

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

func (*Base) DeleteById

func (b *Base) DeleteById(tx *sqlx.Tx, id int64) (sql.Result, error)

func (*Base) DeleteFromTable

func (b *Base) DeleteFromTable(tx *sqlx.Tx, where string) (sql.Result, error)

func (*Base) InsertIntoTable

func (b *Base) InsertIntoTable(tx *sqlx.Tx, data map[string]interface{}) (sql.Result, error)

func (*Base) UpdateById

func (b *Base) UpdateById(tx *sqlx.Tx, data map[string]interface{}, id int64) (sql.Result, error)

func (*Base) UpdateByKeyValueString

func (b *Base) UpdateByKeyValueString(tx *sqlx.Tx, data map[string]interface{}, key, value string) (sql.Result, error)

func (*Base) UpdateFromTable

func (b *Base) UpdateFromTable(tx *sqlx.Tx, data map[string]interface{}, where string) (sql.Result, error)

type InsertResult

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

func (*InsertResult) LastInsertId

func (ir *InsertResult) LastInsertId() (int64, error)

func (*InsertResult) RowsAffected

func (ir *InsertResult) RowsAffected() (int64, error)

type Product

type Product struct {
	Base
}

func NewProduct

func NewProduct(db *sqlx.DB) *Product

func (*Product) AllProducts

func (p *Product) AllProducts(tx *sqlx.Tx) ([]*ProductRow, error)

AllProducts returns all product rows.

func (*Product) GetById

func (p *Product) GetById(tx *sqlx.Tx, id int64) (*ProductRow, error)

GetById returns record by id.

func (*Product) InsertNewProduct

func (p *Product) InsertNewProduct(tx *sqlx.Tx, name, description string, roastDate time.Time, price float64) (*ProductRow, error)

type ProductRow

type ProductRow struct {
	ID          int64     `db:"id"`
	Name        string    `db:"name"`
	RoastDate   time.Time `db:"roast_date"`
	Description string    `db:"description"`
	Price       float32   `db:"price"`
}

func (ProductRow) FormattedRoastDate

func (pr ProductRow) FormattedRoastDate() string

type User

type User struct {
	Base
}

func NewUser

func NewUser(db *sqlx.DB) *User

func (*User) AllUsers

func (u *User) AllUsers(tx *sqlx.Tx) ([]*UserRow, error)

AllUsers returns all user rows.

func (*User) GetByEmail

func (u *User) GetByEmail(tx *sqlx.Tx, email string) (*UserRow, error)

GetByEmail returns record by email.

func (*User) GetById

func (u *User) GetById(tx *sqlx.Tx, id int64) (*UserRow, error)

GetById returns record by id.

func (*User) GetUserByEmailAndPassword

func (u *User) GetUserByEmailAndPassword(tx *sqlx.Tx, email, password string) (*UserRow, error)

GetByEmail returns record by email but checks password first.

func (*User) Signup

func (u *User) Signup(tx *sqlx.Tx, email, password, passwordAgain string) (*UserRow, error)

Signup create a new record of user.

func (*User) UpdateEmailAndPasswordById

func (u *User) UpdateEmailAndPasswordById(tx *sqlx.Tx, userId int64, email, password, passwordAgain string) (*UserRow, error)

UpdateEmailAndPasswordById updates user email and password.

type UserRow

type UserRow struct {
	ID       int64  `db:"id"`
	Email    string `db:"email"`
	Password string `db:"password"`
}

Jump to

Keyboard shortcuts

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