Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (b Delete) Returning(values ...interface{}) Delete {
panic("loukoum: delete builder has returning clause already defined")
}

b.query.Returning = stmt.NewReturning(ToColumns(values))
b.query.Returning = stmt.NewReturning(ToSelectExpressions(values))

return b
}
Expand Down
36 changes: 18 additions & 18 deletions builder/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ func TestDelete(t *testing.T) {
loukoum.Delete("table"),
loukoum.Delete(loukoum.Table("table")),
},
SameQuery: "DELETE FROM table",
SameQuery: "DELETE FROM \"table\"",
},
{
Name: "Only",
Builders: []builder.Builder{
loukoum.Delete("table").Only(),
loukoum.Delete(loukoum.Table("table")).Only(),
},
SameQuery: "DELETE FROM ONLY table",
SameQuery: "DELETE FROM ONLY \"table\"",
},
{
Name: "As",
Builder: loukoum.Delete(loukoum.Table("table").As("foobar")),
SameQuery: "DELETE FROM table AS foobar",
SameQuery: "DELETE FROM \"table\" AS \"foobar\"",
},
{
Name: "As only",
Builder: loukoum.Delete(loukoum.Table("table").As("foobar")).Only(),
SameQuery: "DELETE FROM ONLY table AS foobar",
SameQuery: "DELETE FROM ONLY \"table\" AS \"foobar\"",
},
})
}
Expand All @@ -47,7 +47,7 @@ func TestDelete_Comment(t *testing.T) {
loukoum.Delete("table").Comment("/foo"),
loukoum.Delete(loukoum.Table("table")).Comment("/foo"),
},
SameQuery: "DELETE FROM table; -- /foo",
SameQuery: "DELETE FROM \"table\"; -- /foo",
},
})
}
Expand All @@ -60,25 +60,25 @@ func TestDelete_Using(t *testing.T) {
loukoum.Delete("table").Using("foobar"),
loukoum.Delete("table").Using(loukoum.Table("foobar")),
},
SameQuery: "DELETE FROM table USING foobar",
SameQuery: "DELETE FROM \"table\" USING \"foobar\"",
},
{
Name: "One table as",
Builder: loukoum.Delete("table").Using(loukoum.Table("foobar").As("foo")),
SameQuery: "DELETE FROM table USING foobar AS foo",
SameQuery: "DELETE FROM \"table\" USING \"foobar\" AS \"foo\"",
},
{
Name: "Two tables",
Builders: []builder.Builder{
loukoum.Delete("table").Using("foobar", "example"),
loukoum.Delete("table").Using(loukoum.Table("foobar"), "example"),
},
SameQuery: "DELETE FROM table USING foobar, example",
SameQuery: "DELETE FROM \"table\" USING \"foobar\", \"example\"",
},
{
Name: "Two tables as",
Builder: loukoum.Delete("table").Using(loukoum.Table("example"), loukoum.Table("foobar").As("foo")),
SameQuery: "DELETE FROM table USING example, foobar AS foo",
SameQuery: "DELETE FROM \"table\" USING \"example\", \"foobar\" AS \"foo\"",
},
})
}
Expand All @@ -92,19 +92,19 @@ func TestDelete_Where(t *testing.T) {
{
Name: "Simple",
Builder: loukoum.Delete("table").Where(loukoum.Condition("id").Equal(1)),
String: "DELETE FROM table WHERE (id = 1)",
Query: "DELETE FROM table WHERE (id = $1)",
NamedQuery: "DELETE FROM table WHERE (id = :arg_1)",
String: "DELETE FROM \"table\" WHERE (\"id\" = 1)",
Query: "DELETE FROM \"table\" WHERE (\"id\" = $1)",
NamedQuery: "DELETE FROM \"table\" WHERE (\"id\" = :arg_1)",
Args: []interface{}{1},
},
{
Name: "Complex",
Builder: loukoum.Delete("table").
Where(loukoum.Condition("id").Equal(1)).
And(loukoum.Condition("created_at").GreaterThan(when)),
String: "DELETE FROM table WHERE ((id = 1) AND (created_at > '2017-11-23 16:47:27+00'))",
Query: "DELETE FROM table WHERE ((id = $1) AND (created_at > $2))",
NamedQuery: "DELETE FROM table WHERE ((id = :arg_1) AND (created_at > :arg_2))",
String: "DELETE FROM \"table\" WHERE ((\"id\" = 1) AND (\"created_at\" > '2017-11-23 16:47:27+00'))",
Query: "DELETE FROM \"table\" WHERE ((\"id\" = $1) AND (\"created_at\" > $2))",
NamedQuery: "DELETE FROM \"table\" WHERE ((\"id\" = :arg_1) AND (\"created_at\" > :arg_2))",
Args: []interface{}{1, when},
},
})
Expand All @@ -114,13 +114,13 @@ func TestDelete_Returning(t *testing.T) {
RunBuilderTests(t, []BuilderTest{
{
Name: "*",
Builder: loukoum.Delete("table").Returning("*"),
SameQuery: "DELETE FROM table RETURNING *",
Builder: loukoum.Delete("table").Returning(loukoum.Raw("*")),
SameQuery: "DELETE FROM \"table\" RETURNING *",
},
{
Name: "id",
Builder: loukoum.Delete("table").Returning("id"),
SameQuery: "DELETE FROM table RETURNING id",
SameQuery: "DELETE FROM \"table\" RETURNING \"id\"",
},
})
}
2 changes: 1 addition & 1 deletion builder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (b Insert) Returning(values ...interface{}) Insert {
panic("loukoum: insert builder has returning clause already defined")
}

b.query.Returning = stmt.NewReturning(ToColumns(values))
b.query.Returning = stmt.NewReturning(ToSelectExpressions(values))

return b
}
Expand Down
Loading