本文整理匯總了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)
}
示例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())
}
示例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")
}
示例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")
}
示例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 = ?")
}
示例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")
}
示例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 = ?")
}
示例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())
}
示例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")
}
示例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 = ?")
}
示例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")
}
示例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 = ?)")
}
示例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")
}
示例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)
}
示例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 = ?")
}