// Copyright 2018 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 ( "fmt" "testing" "github.com/stretchr/testify/assert" ) func TestBuilder_Select(t *testing.T) { sql, args, err := Select("c, d").From("table1").ToSQL() assert.NoError(t, err) assert.EqualValues(t, "SELECT c, d FROM table1", sql) assert.EqualValues(t, []interface{}(nil), args) sql, args, err = Select("c, d").From("table1").Where(Eq{"a": 1}).ToSQL() assert.NoError(t, err) assert.EqualValues(t, "SELECT c, d FROM table1 WHERE a=?", sql) assert.EqualValues(t, []interface{}{1}, args) sql, args, err = Select("c, d").From("table1").LeftJoin("table2", Eq{"table1.id": 1}.And(Lt{"table2.id": 3})). RightJoin("table3", "table2.id = table3.tid").Where(Eq{"a": 1}).ToSQL() assert.NoError(t, err) assert.EqualValues(t, "SELECT c, d FROM table1 LEFT JOIN table2 ON table1.id=? AND table2.id