Ejemplo n.º 1
0
func (this *Tweet) Insert() error {
	session, err := dao.GetSession()
	if err != nil {
		return err
	}

	b := cqlr.Bind(`INSERT INTO tweet (timeline, id, text) VALUES (?, ?, ?)`, this)
	return b.Exec(session)
}
Ejemplo n.º 2
0
func TestKitchenSink(t *testing.T) {

	s := setup(t, "kitchen_sink")

	var buf bytes.Buffer
	fmt.Fprint(&buf, "INSERT INTO kitchen_sink (")

	colFragments := kitchenSinkColumns

	colClause := strings.Join(colFragments, ", ")
	fmt.Fprint(&buf, colClause)

	fmt.Fprint(&buf, ") VALUES (")

	placeHolderFragments := make([]string, len(colFragments))
	for i, _ := range placeHolderFragments {
		placeHolderFragments[i] = "?"
	}

	placeHolderClause := strings.Join(placeHolderFragments, ",")
	fmt.Fprint(&buf, placeHolderClause)
	fmt.Fprint(&buf, ")")

	insert := buf.String()

	if err := cqlr.Bind(insert, k).Exec(s); err != nil {
		t.Fatal(err)
	}

	buf.Reset()

	q := s.Query("SELECT * FROM kitchen_sink WHERE id = ?", k.Id)
	b := cqlr.BindQuery(q)

	var nk KitchenSink
	count := 0
	for b.Scan(&nk) {
		count++
	}

	assert.Equal(t, 1, count)
	assert.Equal(t, k, nk)
}