コード例 #1
0
func (me *datasetTest) TestDeleteSqlWithOrder() {
	t := me.T()
	mDb, _ := sqlmock.New()
	ds1 := New("order", mDb).From("items")
	sql, _, err := ds1.Order(I("name").Desc()).ToDeleteSql()
	assert.Nil(t, err)
	assert.Equal(t, sql, `DELETE FROM "items" ORDER BY "name" DESC`)
}
コード例 #2
0
func (me *datasetTest) TestDeleteSqlWithLimit() {
	t := me.T()
	mDb, _ := sqlmock.New()
	ds1 := New("limit", mDb).From("items")
	sql, _, err := ds1.Limit(10).ToDeleteSql()
	assert.Nil(t, err)
	assert.Equal(t, sql, `DELETE FROM "items" LIMIT 10`)
}
コード例 #3
0
func (me *datasetTest) TestUpdateSqlWithOrder() {
	t := me.T()
	mDb, _ := sqlmock.New()
	ds1 := New("order", mDb).From("items")
	type item struct {
		Address string `db:"address"`
		Name    string `db:"name"`
	}
	sql, _, err := ds1.Order(I("name").Desc()).ToUpdateSql(item{Name: "Test", Address: "111 Test Addr"})
	assert.Nil(t, err)
	assert.Equal(t, sql, `UPDATE "items" SET "address"='111 Test Addr',"name"='Test' ORDER BY "name" DESC`)
}
コード例 #4
0
func (me *datasetTest) TestUpdateSqlWithLimit() {
	t := me.T()
	mDb, _ := sqlmock.New()
	ds1 := New("limit", mDb).From("items")
	type item struct {
		Address string `db:"address"`
		Name    string `db:"name"`
	}
	sql, _, err := ds1.Limit(10).ToUpdateSql(item{Name: "Test", Address: "111 Test Addr"})
	assert.Nil(t, err)
	assert.Equal(t, sql, `UPDATE "items" SET "address"='111 Test Addr',"name"='Test' LIMIT 10`)
}