database

package
v0.0.0-...-685a0e9 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2016 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

database wraps the appengine/datastore to provide support to Golb

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotUseCursor = errors.New("Fail to decode this cursor")
View Source
var ErrPostExists = errors.New("Post with this title exists in datastore")
View Source
var ErrPostNotExists = errors.New("Post with this title doesn't exist in datastore")

Functions

func Delete

func Delete(title string, ctx appengine.Context) error

func Get

func Get(key string, ctx appengine.Context) (*post.Post, error)

Get returns a post from datastore. If the key is item key, it returns item part if the key is content key, it returns item along with content part if the key is contentmd key, it returns item along with original part

func Put

func Put(data *post.Post, isUpdate bool, ctx appengine.Context) error

Put stored a post into datastore. It split original data into 3 parts: PostItem, Content with HTML, Original Markdown Content. Then store them in a transaction if isUpdate is true, then it is a update to original post. otherwise it is a new post.

func Query

func Query(offset, limit int, encodedCursor string, ctx appengine.Context) ([]post.Post, bool, string, error)

Query first jumps 'offset' posts, then return 'limit' posts, along with a boolean value to denote if database has more posts, a string to denote cursor for that query. Based on GAE document, offset has its own cost, so App should store this value, and use it for the same query next time. Otherwise, use empty string "" as encodedCursor, this function will do query with offset (has more workload)

Types

type PostContent

type PostContent struct {
	Content string `datastore:",noindex"`
}

type PostItem

type PostItem struct {
	Title, Author, Snapshot string `datastore:",noindex"`
	Tag                     string
	Date                    time.Time
}

Jump to

Keyboard shortcuts

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