当前位置: 首页>>代码示例>>Golang>>正文


Golang DbMap.AddTableWithName方法代码示例

本文整理汇总了Golang中github.com/coopernurse/gorp.DbMap.AddTableWithName方法的典型用法代码示例。如果您正苦于以下问题:Golang DbMap.AddTableWithName方法的具体用法?Golang DbMap.AddTableWithName怎么用?Golang DbMap.AddTableWithName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coopernurse/gorp.DbMap的用法示例。


在下文中一共展示了DbMap.AddTableWithName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewDbMap

func NewDbMap() *gorp.DbMap {
	dsn, _ := globalCfg.ReadString("dsn", "root:[email protected]/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
}
开发者ID:4T-Shirt,项目名称:tyrant,代码行数:33,代码来源:db.go

示例2: jobNetworkMapping

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")
}
开发者ID:unikk,项目名称:cuto,代码行数:10,代码来源:connection.go

示例3: jobMapping

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")
}
开发者ID:unikk,项目名称:cuto,代码行数:15,代码来源:connection.go

示例4: addTable

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")
}
开发者ID:public0821,项目名称:gotemp,代码行数:8,代码来源:manager.go

示例5: HostInit

// 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
}
开发者ID:jakecoffman,项目名称:game-server,代码行数:67,代码来源:tictactoe.go

示例6: InitDbTableMap

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")
}
开发者ID:nangong92t,项目名称:go_src,代码行数:17,代码来源:dbmap.go

示例7: init

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))

}
开发者ID:rafadev7,项目名称:server,代码行数:48,代码来源:db.go

示例8: AddTables

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")
}
开发者ID:Chandler,项目名称:goflesh,代码行数:19,代码来源:flesh.go

示例9: registerTables

func registerTables(db *gorp.DbMap) {
	db.AddTableWithName(models.Product{}, "products").SetKeys(true, "Id")
}
开发者ID:joiggama,项目名称:martini-example,代码行数:3,代码来源:db.go

示例10: InitTables

func InitTables(dbmap *gorp.DbMap) error {
	dbmap.AddTableWithName(LogLine{}, "log_lines").SetKeys(true, "Id")
	return dbmap.CreateTablesIfNotExists()
}
开发者ID:rf-,项目名称:gologs,代码行数:4,代码来源:logs.go


注:本文中的github.com/coopernurse/gorp.DbMap.AddTableWithName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。