builder/cond_exists_test.go
Lunny Xiao 3cae9b5aec
Some checks failed
continuous-integration/drone/tag Build is failing
continuous-integration/drone/push Build is failing
Support Exists and NotExists (#84)
Reviewed-on: #84
2022-04-01 20:07:12 +08:00

33 lines
948 B
Go

// Copyright 2022 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package builder
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExists(t *testing.T) {
cond1 := Exists(Select("*").From("table").Where(Eq{"col1": 1}))
sql, err := ToBoundSQL(cond1)
assert.NoError(t, err)
assert.EqualValues(t, "EXISTS (SELECT * FROM table WHERE col1=1)", sql)
}
func TestNotExists1(t *testing.T) {
cond1 := Exists(Select("*").From("table").Where(Eq{"col1": 1}))
sql, err := ToBoundSQL(Not{cond1})
assert.NoError(t, err)
assert.EqualValues(t, "NOT EXISTS (SELECT * FROM table WHERE col1=1)", sql)
}
func TestNotExists2(t *testing.T) {
cond1 := NotExists(Select("*").From("table").Where(Eq{"col1": 1}))
sql, err := ToBoundSQL(cond1)
assert.NoError(t, err)
assert.EqualValues(t, "NOT EXISTS (SELECT * FROM table WHERE col1=1)", sql)
}