package viewdb

import (
	"gopkg.in/mgo.v2"
	"github.com/tangs-drm/go-tool/dbm"
)

const (
	VIEW_TIMES = "view_times"
)

var Database *mgo.Database

func SetC(db *mgo.Database) {
	Database = db
}

func C(collection string) *mgo.Collection {
	return Database.C(collection)
}

func InitDb() error {
	var err error
	err = dbm.D().ExecScripts(dbScript, true)
	return err
}

var dbScript = `/*==============================================================*/
/* Table: PAGE_VIEW                                             */
/*==============================================================*/
CREATE TABLE PAGE_VIEW
(
   ID                   INT NOT NULL AUTO_INCREMENT,
   POST_ID              INT COMMENT '文章id',
   TIMES                INT COMMENT '浏览次数',
   LAST_VIEW            INT(10) COMMENT '最后一次浏览时间',
   PRIMARY KEY (ID)
);

ALTER TABLE PAGE_VIEW COMMENT '博客的浏览次数统计';
`