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


Golang db.NewQueryBuilder函數代碼示例

本文整理匯總了Golang中github.com/Mparaiso/go-tiger/db.NewQueryBuilder函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewQueryBuilder函數的具體用法?Golang NewQueryBuilder怎麽用?Golang NewQueryBuilder使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: TestSetFirstResult

func TestSetFirstResult(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.SetFirstResult(10)
	test.Fatal(t, qb.GetState(), db.Dirty)
	test.Fatal(t, qb.GetFirstResult(), 10)
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:7,代碼來源:builder_test.go

示例2: TestDeleteWithoutAlias

func TestDeleteWithoutAlias(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Delete("users")
	test.Fatal(t, db.Delete, qb.GetType())
	test.Fatal(t, "DELETE FROM users", qb.String())
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:7,代碼來源:builder_test.go

示例3: TestBuilderSelect

func TestBuilderSelect(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.id").
		From("users", "u")
	test.Fatal(t, qb.String(), "SELECT u.id FROM users u")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:7,代碼來源:builder_test.go

示例4: TestSelectAllWithoutTableAlias

func TestSelectAllWithoutTableAlias(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("*").
		From("users")
	test.Fatal(t, qb.String(), "SELECT * FROM users")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:7,代碼來源:builder_test.go

示例5: TestUpdateWithoutAlias

func TestUpdateWithoutAlias(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Update("users").
		Set("foo", "?").
		Set("bar", "?")
	test.Fatal(t, qb.String(), "UPDATE users SET foo = ?, bar = ?")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例6: TestSelectOrderBy

func TestSelectOrderBy(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.*", "p.*").
		From("users", "u").
		OrderBy("u.name")
	test.Fatal(t, qb.String(), "SELECT u.*, p.* FROM users u ORDER BY u.name ASC")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例7: TestUpdateWhere

func TestUpdateWhere(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Update("users", "u").
		Set("u.foo", "?").
		Where("u.foo = ?")
	test.Fatal(t, qb.String(), "UPDATE users u SET u.foo = ? WHERE u.foo = ?")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例8: TestDeleteWhere

func TestDeleteWhere(t *testing.T) {
	connection := NewTestConnection(t)

	qb := db.NewQueryBuilder(connection)
	qb.Delete("users", "u").
		Where("u.foo = ?")
	test.Fatal(t, "DELETE FROM users u WHERE u.foo = ?", qb.String())
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例9: TestBuilderSelectWithJoin

func TestBuilderSelectWithJoin(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.*", "p.*").From("users", "u").
		Join("u", "phones", "p", Eq("p.user_id", "u.id"))
	test.Fatal(t, qb.String(), "SELECT u.*, p.* FROM users u JOIN phones p ON p.user_id = u.id")

}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例10: TestBuilderSelectWithWhere

func TestBuilderSelectWithWhere(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.id").
		From("users", "u").
		Where(And(Eq("u.nickname", "?")))
	test.Fatal(t, qb.String(), "SELECT u.id FROM users u WHERE u.nickname = ?")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例11: TestSelectGroupBy

func TestSelectGroupBy(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.*", "p.*").
		From("users", "u").
		GroupBy("u.id")
	test.Fatal(t, qb.String(), "SELECT u.*, p.* FROM users u GROUP BY u.id")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:8,代碼來源:builder_test.go

示例12: TestSelectWithOrOrWhereConditions

func TestSelectWithOrOrWhereConditions(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.*", "p.*").
		From("users", "u").
		OrWhere("u.username = ?").
		OrWhere("u.name = ?")
	test.Fatal(t, qb.String(), "SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:9,代碼來源:builder_test.go

示例13: TestSelectMultipleFrom

func TestSelectMultipleFrom(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Select("u.*").
		AddSelect("p.*").
		From("users", "u").
		From("phonenumbers", "p")
	test.Fatal(t, qb.String(), "SELECT u.*, p.* FROM users u, phonenumbers p")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:9,代碼來源:builder_test.go

示例14: TestGetState

func TestGetState(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	test.Fatal(t, qb.GetState(), db.Clean)
	qb.Select("u.*").From("users", "u")
	test.Fatal(t, qb.GetState(), db.Dirty)
	qb.String()
	test.Fatal(t, qb.GetState(), db.Clean)
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:9,代碼來源:builder_test.go

示例15: TestUpdate

func TestUpdate(t *testing.T) {
	connection := NewTestConnection(t)
	qb := db.NewQueryBuilder(connection)
	qb.Update("users", "u").
		Set("u.foo", "?").
		Set("u.bar", "?")
	test.Fatal(t, qb.GetType(), db.Update)
	test.Fatal(t, qb.String(), "UPDATE users u SET u.foo = ?, u.bar = ?")
}
開發者ID:Mparaiso,項目名稱:apipress,代碼行數:9,代碼來源:builder_test.go


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