model

package
v0.0.0-...-1561ecf Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoContent no body response sql interogation
	ErrNoContent = errors.New("No content found")
)

Functions

func ArticleJSON

func ArticleJSON(database DB) ([]byte, error)

ArticleJSON return article JSON format from joining multiple tables Article, Cateogries, Image, Comment, Users.

func CategoriesJSON

func CategoriesJSON(rows *sql.Rows) ([]byte, error)

CategoriesJSON readss from rows object and return all the info in JSON frormat

func OneArticleJSON

func OneArticleJSON(database DB, id uint64) ([]byte, error)

OneArticleJSON makes query and responds with one article in json format

func OneCategoryJSON

func OneCategoryJSON(databse DB, queryStmt string, args ...interface{}) ([]byte, error)

OneCategoryJSON return one row from Category table JSON format

Types

type Articles

type Articles struct {
	ID       int       `json: "ID"`
	Title    string    `json: "Title"`
	Time     string    `json: "Time"`
	Author   string    `json: "Author"`
	Content  string    `json: "Content"`
	Category string    `json: "Category"`
	Image    []Image   `json: "Image"`
	Comments []Comment `json "Comments"`
}

Articles struct serializable json response

type Categories

type Categories struct {
	ID   int    `json : "ID"`
	Name string `json : "Name"`
}

Categories struct serializable json response

type Comment

type Comment struct {
	ID      uint64 `json : "ID"`
	User    User   `json: "User"`
	Time    string `json : "Time"`
	Content string `json : "Content"`
}

Comment struct serializable json response

type DB

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

DB struct pointer to sql.DB sql.Open return handler for database database/sql package manages a pool of connections in the background and dosen't open any connections util you need them. Before making queries we test with handler.Ping() or with err, _ = db.Exec("DO 1")

if err != nil {
	panic(err.Error())
}

func NewOpen

func NewOpen(dbtype, auth string) (DB, error)

NewOpen returns a new db type object basically returns a db object to make a connection to mysql/maria db

func (*DB) Close

func (d *DB) Close()

Close the handler use with defer stmts

func (DB) Exec

func (d DB) Exec(queryStmt string, args ...interface{}) error

Exec query direct without bothering about the results

func (DB) ExecStmt

func (d DB) ExecStmt(stmt *sql.Stmt, args ...interface{}) error

ExecStmt execute query with the prepare binding stmt

func (DB) Handler

func (d DB) Handler() *sql.DB

Handler get *sql.DB handler

func (DB) Prepare

func (d DB) Prepare(queryStmt string) (*sql.Stmt, error)

Prepare query to be execed

func (DB) Query

func (d DB) Query(queryStmt string, args ...interface{}) (*sql.Rows, error)

Query the databse returing the ptr to sql.Rows object to consume it

type ErrSQL

type ErrSQL struct {
	Message string `json: "Message"`
}

ErrSQL struct for internal purpose error handleing

func (ErrSQL) Error

func (e ErrSQL) Error() string

Error implement error interface

type Image

type Image struct {
	ID   int    `json : "ID"`
	Link string `json : "Link"`
}

Image struct serializable json response

type Payload

type Payload struct {
	Data interface{}
}

Payload json fromat

func NewPayload

func NewPayload(d interface{}) Payload

NewPayload return new JSON response payload

type User

type User struct {
	ID    int    `json: "ID"`
	Name  string `json: "Name"`
	Email string `json: "Email:"`
}

User struct serializable json response

Jump to

Keyboard shortcuts

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