db

package
v0.0.0-...-b5a4b96 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2016 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package db implements MongoDB database access methods.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Logger is a logger for error messages
	Logger = log.New(os.Stderr, "LOGGER [db]: ", log.Ldate|log.Ltime|log.Lshortfile)
	// Colls is a map of db collections names.
	// Keys can be used as aliases, values are real collection names.
	Colls = map[string]string{
		"urls":   "urls",
		"tracks": "tracks",
		"locks":  "locks",
		"users":  "users",
		"tests":  "tests",
	}
)

Functions

func C

func C(ctx context.Context, name string) (*mgo.Collection, error)

C return a collection pointer by its name from default database.

func CheckID

func CheckID(s string) (bson.ObjectId, error)

CheckID converts string s to ObjectId if it is possible, otherwise it returns error.

func Coll

func Coll(s *mgo.Session, name string) (*mgo.Collection, error)

Coll return database collection pointer.

func CtxSession

func CtxSession(ctx context.Context) (*mgo.Session, error)

CtxSession finds and returns MongoDB session from the Context.

func LockURL

func LockURL(s *mgo.Session) error

LockURL locks short URL creation actions. It is useful for distributed usage, database is used for consistency short URLs values.

func MongoCredential

func MongoCredential(cfg *conf.MongoCfg) error

MongoCredential initializes MongoDB credentials.

func NewContext

func NewContext(ctx context.Context, s *mgo.Session) context.Context

NewContext returns a new Context carrying MongoDB session.

func NewCtxSession

func NewCtxSession(ctx context.Context, c *conf.Config, primary bool) (context.Context, *mgo.Session, error)

NewCtxSession creates new database session and saves it to the context.

func NewSession

func NewSession(c *conf.Conn, primary bool) (*mgo.Session, error)

NewSession returns new MongoDB session based on Conn data.

func UnlockURL

func UnlockURL(s *mgo.Session) error

UnlockURL unlocks short URLs creation actions.

Types

type Item

type Item struct {
	ID bson.ObjectId `bson:"_id"`
}

Item is any DB item, it contains only identifier.

type ItemURL

type ItemURL struct {
	ID int64 `bson:"_id"`
}

ItemURL is any DB item, it contains only short URL identifier.

Jump to

Keyboard shortcuts

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