コード例 #1
0
ファイル: db.go プロジェクト: 4T-Shirt/tyrant
func NewDbMap() *gorp.DbMap {
	dsn, _ := globalCfg.ReadString("dsn", "root:root@/tyrant")
	dbType, _ := globalCfg.ReadString("db", "mysql")
	if dbType != "mysql" && dbType != "sqlite3" {
		log.Fatal("db must be mysql or sqlite3")
	}
	db, err := sql.Open(dbType, dsn)
	if err != nil {
		log.Fatal(err)
	}
	var dbmap *gorp.DbMap
	if dbType == "mysql" {
		dbmap = &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{}}
	} else {
		dbmap = &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
	}

	tbl := dbmap.AddTableWithName(Job{}, "jobs").SetKeys(true, "Id")
	tbl.ColMap("name").SetMaxSize(512).SetUnique(true)
	tbl.ColMap("executor").SetMaxSize(4096)
	tbl.ColMap("executor_flags").SetMaxSize(4096)
	tbl.ColMap("uris").SetMaxSize(2048)

	tbl = dbmap.AddTableWithName(Task{}, "tasks").SetKeys(true, "Id")
	tbl.ColMap("id").SetMaxSize(128).SetUnique(true)

	err = dbmap.CreateTablesIfNotExists()

	if err != nil {
		log.Fatal(err)
	}
	return dbmap
}
コード例 #2
0
ファイル: connection.go プロジェクト: unikk/cuto
func jobNetworkMapping(dbmap *gorp.DbMap) {
	t := dbmap.AddTableWithName(JobNetworkResult{}, "JOBNETWORK").SetKeys(true, "ID")
	t.ColMap("JobnetWork").Rename("JOBNETWORK")
	t.ColMap("StartDate").Rename("STARTDATE")
	t.ColMap("EndDate").Rename("ENDDATE")
	t.ColMap("Status").Rename("STATUS")
	t.ColMap("Detail").Rename("DETAIL")
	t.ColMap("CreateDate").Rename("CREATEDATE")
	t.ColMap("UpdateDate").Rename("UPDATEDATE")
}
コード例 #3
0
ファイル: connection.go プロジェクト: unikk/cuto
func jobMapping(dbmap *gorp.DbMap) {
	t := dbmap.AddTableWithName(JobResult{}, "JOB").SetKeys(false, "ID", "JobId")
	t.ColMap("JobId").Rename("JOBID")
	t.ColMap("JobName").Rename("JOBNAME")
	t.ColMap("StartDate").Rename("STARTDATE")
	t.ColMap("EndDate").Rename("ENDDATE")
	t.ColMap("Status").Rename("STATUS")
	t.ColMap("Detail").Rename("DETAIL")
	t.ColMap("Rc").Rename("RC")
	t.ColMap("Node").Rename("NODE")
	t.ColMap("Port").Rename("PORT")
	t.ColMap("Variable").Rename("VARIABLE")
	t.ColMap("CreateDate").Rename("CREATEDATE")
	t.ColMap("UpdateDate").Rename("UPDATEDATE")
}
コード例 #4
0
ファイル: manager.go プロジェクト: public0821/gotemp
func addTable(dbmap *gorp.DbMap) {
	// add a table, setting the table name to 'posts' and
	// specifying that the Id property is an auto incrementing PK
	dbmap.AddTableWithName(Record{}, "record").SetKeys(true, "Id")
	dbmap.AddTableWithName(SysOption{}, "sysoption").SetKeys(false, "Name")
	dbmap.AddTableWithName(ForwardServer{}, "forward_server").SetKeys(false, "Ip")
	dbmap.AddTableWithName(User{}, "user").SetKeys(false, "Name")
}
コード例 #5
0
ファイル: tictactoe.go プロジェクト: jakecoffman/game-server
// Called first when a host connects.
// NOTE that this may be called multiple times as a host may drop and reconnect.
func HostInit(playerId int, gameId string, gs GameService, ws *websocket.Conn, wsReadChan chan Message, db *gorp.DbMap) error {
	log.Printf("Host initing")

	// since host is always the first to connect, setup tables if they don't already exist
	db.AddTableWithName(TicTacToe_Board{}, "tictactoe_board").SetKeys(true, "Id")
	db.AddTableWithName(TicTacToe_Turn{}, "tictactoe_turn").SetKeys(true, "Id")
	err := db.CreateTablesIfNotExists()
	if err != nil {
		log.Printf("Unable to create TTT tables: %#v", err)
		return err
	}

	log.Printf("Tables created")

	// get the game so we know what state we should be in
	game, _, err := gs.GetGame(db, gameId, playerId)
	if err != nil {
		log.Printf("Host failed to get game: %#v", err)
		return err
	}

	log.Printf("got game")

	if game.State == "lobby" {
		log.Printf("Game is still in lobby")

		// update the lobby based on players that are currently connected
		pids := gs.GetConnectedPlayers(gameId)
		// angular wants an array of objects, it can't handle an array of ints
		players := []Message{}
		for _, pid := range pids {
			players = append(players, Message{"id": pid})
		}

		ws.WriteJSON(Message{
			"type":    "players",
			"players": players,
		})
		ws.WriteJSON(Message{
			"type":  "state",
			"state": game.State,
		})
	} else {
		log.Printf("Host rejoining game in progress")
		// get the game board so we can send an update
		board, err := getBoard(gameId, db)
		if err != nil {
			log.Printf("Could not get board, this might not be an error: %#v", err)
			return err
		}

		log.Printf("Getting nicer board: %#v", board)
		niceBoard, err := board.getBoard()
		if err != nil {
			log.Printf("Can't init with board: %#v", err)
			return err
		}
		ws.WriteJSON(Message{
			"type":  "update",
			"board": niceBoard,
			"state": "start",
		})
	}
	return nil
}
コード例 #6
0
ファイル: dbmap.go プロジェクト: nangong92t/go_src
func InitDbTableMap(dbmap *gorp.DbMap) {
	dbmap.AddTableWithName(User{}, "user").SetKeys(true, "Id")
	dbmap.AddTableWithName(Comment{}, "comment").SetKeys(true, "Id")
	dbmap.AddTableWithName(Keyword{}, "keyword").SetKeys(true, "Id")
	dbmap.AddTableWithName(Label{}, "label").SetKeys(true, "Id")
	dbmap.AddTableWithName(LabelHasKeyword{}, "label_has_keyword").SetKeys(true, "Id")
	dbmap.AddTableWithName(Notification{}, "notification").SetKeys(true, "Id")
	dbmap.AddTableWithName(Profile{}, "profile").SetKeys(false, "Id")
	dbmap.AddTableWithName(Topic{}, "topic").SetKeys(true, "Id")
	dbmap.AddTableWithName(TopicHasKeyword{}, "topic_has_keyword")
	dbmap.AddTableWithName(UserLikeKeywordRate{}, "user_like_keyword_rate")
	dbmap.AddTableWithName(UserLoadedMaxTopic{}, "user_loaded_max_topic")
	dbmap.AddTableWithName(Session{}, "user_session")
	dbmap.AddTableWithName(Attach{}, "attach").SetKeys(true, "Id")
	dbmap.AddTableWithName(UserBlocked{}, "user_blocked").SetKeys(true, "Id")
	dbmap.AddTableWithName(UnwantWord{}, "unwant_word").SetKeys(true, "Id")
}
コード例 #7
0
ファイル: db.go プロジェクト: rafadev7/server
func init() {
	log.Println("Connecting to database...")
	// connect to db using standard Go database/sql API
	// use whatever database/sql driver you wish
	dbopen, err := sql.Open("mysql", dbuser+":"+dbpass+"@/"+dbname+"?charset=utf8&parseTime=true")
	if err != nil {
		panic(err.Error()) // Just for example purpose. You should use proper error handling instead of panic
	}
	//defer db.Close() // I DUNNO IF IT WORKS HERE, LETS TEST

	dialect := gorp.MySQLDialect{"InnoDB", "UTF8"}

	// construct a gorp DbMap
	dbmap := gorp.DbMap{Db: dbopen, Dialect: dialect}

	log.Println("Database connected!")

	// Adding schemes to my ORM
	dbmap.AddTableWithName(User{}, "user").SetKeys(false, "userid")
	dbmap.AddTableWithName(Profile{}, "profile").SetKeys(false, "profileid")
	dbmap.AddTableWithName(Pic{}, "pic").SetKeys(false, "picid")
	dbmap.AddTableWithName(Token{}, "token").SetKeys(false, "tokenid", "userid")
	dbmap.AddTableWithName(Category{}, "category").SetKeys(false, "categoryid")
	dbmap.AddTableWithName(Image{}, "image").SetKeys(false, "imageid")
	dbmap.AddTableWithName(Url{}, "url").SetKeys(false, "urlid")
	dbmap.AddTableWithName(Content{}, "content").SetKeys(false, "contentid")
	dbmap.AddTableWithName(FullContent{}, "fullcontent").SetKeys(false, "contentid")
	dbmap.AddTableWithName(ContentLike{}, "contentlike").SetKeys(false, "contentid", "userid")
	dbmap.AddTableWithName(Access{}, "access").SetKeys(false, "accessid")

	// Adding to local vairable
	db = &dbmap

	log.Println("Start routine to create the default values of our datas...")

	checkAndCreateDefaultPic(db)

	checkAndCreateDefaultImage(db)

	checkAndCreateAnonymousUser(db)

	checkAndCreateCategories(db)

	log.Println("All default values has been created.")

	dbmap.TraceOn("[SQL]", log.New(os.Stdout, "[DB]", log.Lmicroseconds))

}
コード例 #8
0
ファイル: flesh.go プロジェクト: Chandler/goflesh
func AddTables(dbm *gorp.DbMap) {
	dbm.AddTable(Game{}).SetKeys(true, "Id")
	dbm.AddTable(Organization{}).SetKeys(true, "Id")
	dbm.AddTable(Player{}).SetKeys(true, "Id")
	dbm.AddTable(User{}).SetKeys(true, "Id")
	dbm.AddTable(Oz{}).SetKeys(true, "Id")
	dbm.AddTable(Tag{}).SetKeys(true, "Id")
	dbm.AddTable(Member{}).SetKeys(true, "Id")
	dbm.AddTable(Event{}).SetKeys(true, "Id")
	dbm.AddTableWithName(EventType{}, "event_type").SetKeys(true, "Id")
	dbm.AddTableWithName(EventTag{}, "event_tag")
	dbm.AddTableWithName(EventPlayer{}, "event_player")
	dbm.AddTableWithName(EventRole{}, "event_role").SetKeys(true, "Id")
	dbm.AddTableWithName(EventToPlayer{}, "event_to_player").SetKeys(true, "Id")
	dbm.AddTableWithName(EventToGame{}, "event_to_game").SetKeys(true, "Id")
	dbm.AddTableWithName(HumanCode{}, "human_code").SetKeys(false, "Id")
	dbm.AddTableWithName(OzPool{}, "oz_pool").SetKeys(true, "Id")
	dbm.AddTableWithName(PasswordReset{}, "password_reset")
}
コード例 #9
0
ファイル: db.go プロジェクト: joiggama/martini-example
func registerTables(db *gorp.DbMap) {
	db.AddTableWithName(models.Product{}, "products").SetKeys(true, "Id")
}
コード例 #10
0
ファイル: logs.go プロジェクト: rf-/gologs
func InitTables(dbmap *gorp.DbMap) error {
	dbmap.AddTableWithName(LogLine{}, "log_lines").SetKeys(true, "Id")
	return dbmap.CreateTablesIfNotExists()
}