Documentation ¶
Index ¶
- Variables
- type CountQuery
- type DB
- func (db *DB) Begin() (*sql.Tx, error)
- func (db *DB) Count(table string, count string) *CountQuery
- func (db *DB) Delete(obj interface{}) (sql.Result, error)
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) Insert(obj interface{}) (sql.Result, error)
- func (db *DB) ManualDelete(table string) *DeleteQuery
- func (db *DB) ManualUpdate(table string) *UpdateQuery
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row
- func (db *DB) Register(structs ...interface{}) error
- func (db *DB) Select(fields ...string) *SelectQuery
- func (db *DB) Update(obj interface{}) (sql.Result, error)
- type DeleteQuery
- func (dq *DeleteQuery) Exec() (sql.Result, error)
- func (dq *DeleteQuery) Join(join string) *DeleteQuery
- func (dq *DeleteQuery) OrWhere(condition string, args ...interface{}) *DeleteQuery
- func (dq *DeleteQuery) String() string
- func (dq *DeleteQuery) Where(condition string, args ...interface{}) *DeleteQuery
- type SelectQuery
- func (sq *SelectQuery) Join(join string) *SelectQuery
- func (sq *SelectQuery) Limit(limit int64) *SelectQuery
- func (sq *SelectQuery) Offset(offset int64) *SelectQuery
- func (sq *SelectQuery) OrWhere(condition string, args ...interface{}) *SelectQuery
- func (sq *SelectQuery) OrderBy(orderBy string) *SelectQuery
- func (sq *SelectQuery) String() string
- func (sq *SelectQuery) To(out interface{}) error
- func (sq *SelectQuery) Where(condition string, args ...interface{}) *SelectQuery
- type UpdateQuery
- func (uq *UpdateQuery) Exec() (sql.Result, error)
- func (uq *UpdateQuery) Join(join string) *UpdateQuery
- func (uq *UpdateQuery) OrWhere(condition string, args ...interface{}) *UpdateQuery
- func (uq *UpdateQuery) Set(set string, args ...interface{}) *UpdateQuery
- func (uq *UpdateQuery) String() string
- func (uq *UpdateQuery) Where(condition string, args ...interface{}) *UpdateQuery
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = errors.New("no result found")
ErrNotFound .
Functions ¶
This section is empty.
Types ¶
type CountQuery ¶
type CountQuery struct {
// contains filtered or unexported fields
}
CountQuery .
func (*CountQuery) OrWhere ¶
func (cq *CountQuery) OrWhere(condition string, args ...interface{}) *CountQuery
OrWhere .
func (*CountQuery) String ¶
func (cq *CountQuery) String() string
String returns the string representation of CountQuery.
func (*CountQuery) Where ¶
func (cq *CountQuery) Where(condition string, args ...interface{}) *CountQuery
Where .
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a wrapper around sql.DB.
func (*DB) Delete ¶
Delete .
Example ¶
package main import ( "database/sql" "fmt" "os" _ "github.com/mattn/go-sqlite3" "github.com/twharmon/gosql" ) func main() { os.Remove("/tmp/foo.db") sqliteDB, _ := sql.Open("sqlite3", "/tmp/foo.db") sqliteDB.Exec("create table user (id integer not null primary key, name text); delete from user") db := gosql.New(sqliteDB) type User struct { ID int `gosql:"primary"` Name string } db.Register(User{}) user := User{ID: 5, Name: "Gopher"} db.Insert(&user) db.Delete(&user) var foo User err := db.Select("*").To(&foo) fmt.Println(err) }
Output: no result found
func (*DB) Insert ¶
Insert .
Example ¶
package main import ( "database/sql" "fmt" "os" _ "github.com/mattn/go-sqlite3" "github.com/twharmon/gosql" ) func main() { os.Remove("/tmp/foo.db") sqliteDB, _ := sql.Open("sqlite3", "/tmp/foo.db") sqliteDB.Exec("create table user (id integer not null primary key, name text); delete from user") db := gosql.New(sqliteDB) type User struct { ID int `gosql:"primary"` Name string } db.Register(User{}) db.Insert(&User{Name: "Gopher"}) var user User db.Select("*").To(&user) fmt.Println(user.Name) }
Output: Gopher
func (*DB) Update ¶
Update .
Example ¶
package main import ( "database/sql" "fmt" "os" _ "github.com/mattn/go-sqlite3" "github.com/twharmon/gosql" ) func main() { os.Remove("/tmp/foo.db") sqliteDB, _ := sql.Open("sqlite3", "/tmp/foo.db") sqliteDB.Exec("create table user (id integer not null primary key, name text, email text); delete from user") db := gosql.New(sqliteDB) type User struct { ID int `gosql:"primary"` Name string Email string } db.Register(User{}) user := User{ID: 5, Name: "Gopher", Email: "gopher@example.com"} db.Insert(&user) user.Name = "Gofer" user.Email = "gofer@example.com" db.Update(&user) var foo User db.Select("*").To(&foo) fmt.Println(foo.Name, foo.Email) }
Output: Gofer gofer@example.com
type DeleteQuery ¶
type DeleteQuery struct {
// contains filtered or unexported fields
}
DeleteQuery .
func (*DeleteQuery) OrWhere ¶
func (dq *DeleteQuery) OrWhere(condition string, args ...interface{}) *DeleteQuery
OrWhere .
func (*DeleteQuery) String ¶
func (dq *DeleteQuery) String() string
String returns the string representation of DeleteQuery.
func (*DeleteQuery) Where ¶
func (dq *DeleteQuery) Where(condition string, args ...interface{}) *DeleteQuery
Where .
type SelectQuery ¶
type SelectQuery struct {
// contains filtered or unexported fields
}
SelectQuery .
func (*SelectQuery) OrWhere ¶
func (sq *SelectQuery) OrWhere(condition string, args ...interface{}) *SelectQuery
OrWhere .
func (*SelectQuery) String ¶
func (sq *SelectQuery) String() string
String returns the string representation of SelectQuery.
func (*SelectQuery) To ¶
func (sq *SelectQuery) To(out interface{}) error
To sets the result of the query to out. To() can only take a pointer to a struct, a pointer to a slice of structs, or a pointer to a slice of pointers to structs.
func (*SelectQuery) Where ¶
func (sq *SelectQuery) Where(condition string, args ...interface{}) *SelectQuery
Where .
type UpdateQuery ¶
type UpdateQuery struct {
// contains filtered or unexported fields
}
UpdateQuery .
func (*UpdateQuery) OrWhere ¶
func (uq *UpdateQuery) OrWhere(condition string, args ...interface{}) *UpdateQuery
OrWhere .
func (*UpdateQuery) Set ¶
func (uq *UpdateQuery) Set(set string, args ...interface{}) *UpdateQuery
Set .
func (*UpdateQuery) String ¶
func (uq *UpdateQuery) String() string
String returns the string representation of UpdateQuery.
func (*UpdateQuery) Where ¶
func (uq *UpdateQuery) Where(condition string, args ...interface{}) *UpdateQuery
Where .
Click to show internal directories.
Click to hide internal directories.