This repository has been archived by the owner on Jun 14, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add insert select support * refactor insert select * improve sort * update test * fix * hide fiddle sql tests * update README * update README
- Loading branch information
Showing
13 changed files
with
148 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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 ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuilderInsert(t *testing.T) { | ||
sql, err := Insert(Eq{"c": 1, "d": 2}).Into("table1").ToBoundSQL() | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, "INSERT INTO table1 (c,d) Values (1,2)", sql) | ||
|
||
sql, err = Insert(Eq{"c": 1, "d": Expr("SELECT b FROM t WHERE d=? LIMIT 1", 2)}).Into("table1").ToBoundSQL() | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, "INSERT INTO table1 (c,d) Values (1,(SELECT b FROM t WHERE d=2 LIMIT 1))", sql) | ||
|
||
sql, err = Insert(Eq{"c": 1, "d": 2}).ToBoundSQL() | ||
assert.Error(t, err) | ||
assert.EqualValues(t, ErrNoTableName, err) | ||
assert.EqualValues(t, "", sql) | ||
|
||
sql, err = Insert(Eq{}).Into("table1").ToBoundSQL() | ||
assert.Error(t, err) | ||
assert.EqualValues(t, ErrNoColumnToInsert, err) | ||
assert.EqualValues(t, "", sql) | ||
} | ||
|
||
func TestBuidlerInsert_Select(t *testing.T) { | ||
sql, err := Insert().Into("table1").Select().From("table2").ToBoundSQL() | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, "INSERT INTO table1 SELECT * FROM table2", sql) | ||
|
||
sql, err = Insert("a, b").Into("table1").Select("b, c").From("table2").ToBoundSQL() | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, "INSERT INTO table1 (a, b) SELECT b, c FROM table2", sql) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.