當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ConnectionFactory.GetConnection方法代碼示例

本文整理匯總了Golang中com/papersns/mongo.ConnectionFactory.GetConnection方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConnectionFactory.GetConnection方法的具體用法?Golang ConnectionFactory.GetConnection怎麽用?Golang ConnectionFactory.GetConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com/papersns/mongo.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.GetConnection方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UpdateAll3

func (c ResumeTest) UpdateAll3() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}
	txnId := txnManager.BeginTransaction()

	query := map[string]interface{}{
		"_id": map[string]interface{}{
			"$lte": 100,
		},
	}
	update := map[string]interface{}{
		"$inc": map[string]interface{}{
			"age": 5,
		},
	}
	unModify := map[string]interface{}{
		"$inc": map[string]interface{}{
			"age": -5,
		},
	}
	obj, _ := txnManager.UpdateAll(txnId, "Test1", query, update, unModify)
	fmt.Println("obj3", obj)
	txnManager.Commit(txnId)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("UpdateAll3")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:30,代碼來源:resumetest.go

示例2: RecoverTest

func (c ResumeTest) RecoverTest() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}

	txnId := txnManager.BeginTransaction()
	defer func() {
		if x := recover(); x != nil {
			txnManager.Rollback(txnId)
			panic(x)
		}
	}()

	test1 := map[string]interface{}{"name": "insertTest1"}
	txnManager.Insert(txnId, "Test1", test1)
	test2 := map[string]interface{}{"name": "insertTest2"}
	txnManager.Insert(txnId, "Test2", test2)

	txnManager.Commit(txnId)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("Commit1")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:25,代碼來源:resumetest.go

示例3: Commit9

func (c ResumeTest) Commit9() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}

	txnId := txnManager.BeginTransaction()

	test1 := map[string]interface{}{"name": "insertTest9"}
	txnManager.Insert(txnId, "Test1", test1)

	test3 := map[string]interface{}{"_id": 3, "name": "insertTest9"}
	txnManager.Remove(txnId, "Test2", test3)

	test2 := map[string]interface{}{"_id": 4, "name": "insertTest9"}
	txnManager.Update(txnId, "Test2", test2)

	test4 := map[string]interface{}{"_id": 5, "name": "insertTest9"}
	txnManager.Remove(txnId, "Test2", test4)

	txnManager.Commit(txnId)

	c.Response.ContentType = "text/plain; charset=utf-9"
	return c.RenderText("Commit9")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:26,代碼來源:resumetest.go

示例4: UpdateAll1

func (c ResumeTest) UpdateAll1() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}
	txnId := txnManager.BeginTransaction()

	query := map[string]interface{}{
		"_id": 36,
	}
	update := map[string]interface{}{
		"$set": map[string]interface{}{
			"age": 20,
		},
	}
	unModify := map[string]interface{}{
		"$unset": map[string]interface{}{
			"age": 1,
		},
	}
	txnManager.UpdateAll(txnId, "Test1", query, update, unModify)
	txnManager.Commit(txnId)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("UpdateAll1")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:27,代碼來源:resumetest.go

示例5: ResumeBeginCommit2

func (c ResumeTest) ResumeBeginCommit2() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}
	txnManager.ResumePeriod()

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("ResumeBeginCommit2")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:11,代碼來源:resumetest.go

示例6: BeginTransaction

func (c ModelTest) BeginTransaction() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}

	txnManager.BeginTransaction()

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("BeginTransaction")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:12,代碼來源:sysuser.go

示例7: Commit12

func (c ModelTest) Commit12() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}

	txnId := txnManager.BeginTransaction()

	{
		query := map[string]interface{}{
			"_id": map[string]interface{}{
				"$lt": 7,
			},
		}
		update := map[string]interface{}{
			"$set": map[string]interface{}{
				"age": 9,
			},
		}
		unModify := map[string]interface{}{
			"$unset": map[string]interface{}{
				"age": 1,
			},
		}
		txnManager.UpdateAll(txnId, "Test1", query, update, unModify)
	}
	{
		query := map[string]interface{}{
			"_id": map[string]interface{}{
				"$gte": 8,
			},
		}
		update := map[string]interface{}{
			"$set": map[string]interface{}{
				"age": 9,
			},
		}
		unModify := map[string]interface{}{
			"$unset": map[string]interface{}{
				"age": 1,
			},
		}
		txnManager.UpdateAll(txnId, "Test2", query, update, unModify)
	}

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("Commit12")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:49,代碼來源:sysuser.go

示例8: SelectForUpdate2

func (c ResumeTest) SelectForUpdate2() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}
	txnId := txnManager.BeginTransaction()

	test1 := map[string]interface{}{
		"_id":  36,
		"name": "SelectForUpdate2",
	}
	txnManager.SelectForUpdate(txnId, "Test1", test1)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("SelectForUpdate2")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:17,代碼來源:resumetest.go

示例9: Commit2

func (c ModelTest) Commit2() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}

	txnId := txnManager.BeginTransaction()

	test1 := map[string]interface{}{"name": "insertTest2"}
	txnManager.Insert(txnId, "Test1", test1)
	test2 := map[string]interface{}{"name": "insertTest2"}
	txnManager.Insert(txnId, "Test2", test2)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("Commit2")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:17,代碼來源:sysuser.go

示例10: RemoveAll1

func (c ResumeTest) RemoveAll1() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}
	txnId := txnManager.BeginTransaction()

	query := map[string]interface{}{
		"_id": 5,
	}
	obj, _ := txnManager.RemoveAll(txnId, "Test1", query)
	fmt.Println("removeAll1", obj)
	txnManager.Commit(txnId)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("RemoveAll1")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:18,代碼來源:resumetest.go

示例11: Commit20

func (c ResumeTest) Commit20() revel.Result {
	connectionFactory := mongo.ConnectionFactory{}
	session, db := connectionFactory.GetConnection()
	defer session.Close()

	txnManager := TxnManager{db}
	txnId := txnManager.BeginTransaction()

	test1 := map[string]interface{}{
		"name": "insertTest20",
	}
	test1 = txnManager.Insert(txnId, "Test1", test1)
	test1["address"] = "xiamen"
	test1, _ = txnManager.Update(txnId, "Test1", test1)
	test1["age"] = 20
	test1, _ = txnManager.Update(txnId, "Test1", test1)

	c.Response.ContentType = "text/plain; charset=utf-8"
	return c.RenderText("Commit20")
}
開發者ID:hongjinqiu,項目名稱:finance,代碼行數:20,代碼來源:resumetest.go


注:本文中的com/papersns/mongo.ConnectionFactory.GetConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。