Exemplo n.º 1
0
func TestSQLTagBuilder(t *testing.T) {
	tag := "column:nick_name"
	sqlTag := db.SQLStructTagBuilder{logger.NewTestLogger(t)}.BuildFromString(tag)
	test.Fatal(t, sqlTag.ColumnName, "nick_name")
	test.Fatal(t, sqlTag.PersistZeroValue, false)
	tag = "column:email_address,persistzerovalue"
	sqlTag = db.SQLStructTagBuilder{logger.NewTestLogger(t)}.BuildFromString(tag)
	test.Fatal(t, sqlTag.ColumnName, "email_address")
	test.Fatal(t, sqlTag.PersistZeroValue, true)
}
Exemplo n.º 2
0
func TestParser(t *testing.T) {
	testLogger := logger.NewTestLogger(t)

	for _, fixture := range []struct {
		String      string
		Length      int
		Definitions []*tag.Definition
	}{
		{`field:foo;complex_field(name:param,name2:param2,name_3:3);field:1;last_field`,
			4,
			[]*tag.Definition{
				{Name: "field", Value: "foo"},
				{Name: "complex_field", Parameters: []tag.Parameter{{Key: "name", Value: "param"}, {Key: "name2", Value: "param2"}, {Key: "name_3", Value: "3"}}},
				{Name: "field", Value: "1"},
				{Name: "last_field"},
			},
		},
	} {
		parser := tag.NewParser(strings.NewReader(fixture.String))
		parser.SetLogger(testLogger)
		definitions, err := parser.Parse()
		test.Fatal(t, err, nil)
		test.Fatal(t, len(definitions), fixture.Length)
		test.Fatal(t, reflect.DeepEqual(definitions, fixture.Definitions), true)
	}

}
Exemplo n.º 3
0
func TestConnectionCreateQueryBuilderQuery(t *testing.T) {
	connection := GetConnection(t)
	err := LoadFixtures(connection)
	test.Fatal(t, err, nil)
	connection.SetLogger(logger.NewTestLogger(t))
	users := []*AppUser{}
	err = connection.CreateQueryBuilder().
		Select("u.name , u.email").
		From("users", "u").
		Where(expression.Neq("Name", "?")).
		OrderBy("name", "ASC").
		Query("Jack Doe").
		GetResults(&users)
	test.Fatal(t, err, nil)
	test.Fatal(t, len(users), 2)
	test.Fatal(t, users[0].Name, "Jane Doe")

}