Documentation ¶
Overview ¶
Copyright (c) 2017 Derek Santos. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (c) 2017 Derek Santos. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (c) 2017 Derek Santos. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (c) 2017 Derek Santos. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (c) 2017 Derek Santos. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright (c) 2017 Derek Santos. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Index ¶
- func Exec(db *sql.DB, query string, args ...interface{}) error
- func Insert(db *sql.DB, query string, args ...interface{}) (int64, error)
- func QueryRow(db *sql.DB, query string, scanner func(*sql.Row) error, args ...interface{}) error
- func QueryRows(db *sql.DB, query string, scanner func(*sql.Rows) error, args ...interface{}) error
- type Entity
- type EntityCollection
- type EntityDefiner
- type Field
- type MD5
- type Password
- type Sha256
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QueryRow ¶
QueryRow facilitates queries that retrieve a single row. The scanner func argument is expected to handle scanning the row if it's found. The args parameter is passed into the query for parameterized queries.
Types ¶
type Entity ¶
An Entity defines the relationship between an instance of a struct and a row in a database table or collection. It's important to note that it's related to an instance, and so has pointers to the stucts fields. This facilitates row scanning and prepared statements.
func (*Entity) Delete ¶
Delete executes a delete statement using the Key value of the receiver. The entity requires only the Key to be set for the delete to work.
Example:
person := &Person{ID:1} err := person.Entity().Delete() if err != nil { panic(err) }
func (*Entity) Get ¶
Get scans a single row of data from an auto-generated sql statement into the Entity's value pointers. It returns the row based on the primary key value of the entity.
Example:
person := &Person{ID:1} err := person.Entity().Get()
func (*Entity) Insert ¶
Insert executes an insert statement on a single row of data using the values in the receiver. The new ID will be returned if applicable. Fields with ReadOnly set to true will not be included in the insert.
Example:
person := &Person{Name:"John Doe", Email"test@test.com"} id, err := person.Entity().Insert() if err != nil { panic(err) } person.ID = id
func (*Entity) Update ¶
Update executes an update statement on a single row of data using values in the receiver. Fields with ReadOnly set to true will not be included in the update.
Example:
person := &Person{ID:1} e := person.Entity() err := e.Get() if err != nil { panic(err) } person.Name = "New Name" err = e.Update() if err != nil { panic(err) }
type EntityCollection ¶
type EntityCollection func() EntityDefiner
func (EntityCollection) Select ¶
func (c EntityCollection) Select(db *sql.DB, clause string, args ...interface{}) ([]EntityDefiner, error)
type EntityDefiner ¶
type EntityDefiner interface {
Entity() *Entity
}
An EntityDefiner must return a pointer to an Entity struct. This interface should be implemented by structs that relate to a database table or collection.
type Field ¶
type Field struct { Name string Value interface{} ReadOnly bool // NonIncrementing should be set to true when you need a primary key // whos value does not auto increment. NonIncrementing bool }
A Field maps the name of a database column to a pointer in a struct. If ReadOnly is true, this field will not be included in writes to the database.
type Password ¶
type Password string
Password is a string type used to represent secure password fields that are hashed using BCrypt.
func (*Password) Compare ¶
Compare will use bcrypt to check for equality between the specified candidate parameter and the receiver. It will return an error if they do not match.