mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
dialect/sql: Add context.Context to sql.Selector (#1185)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -1400,3 +1401,16 @@ func TestSelector_OrderByExpr(t *testing.T) {
|
||||
require.Equal(t, "SELECT * FROM `users` WHERE `age` > ? ORDER BY `name`, CASE WHEN id=? THEN id WHEN id=? THEN name END DESC", query)
|
||||
require.Equal(t, []interface{}{28, 1, 2}, args)
|
||||
}
|
||||
|
||||
func TestBuilderContext(t *testing.T) {
|
||||
type key string
|
||||
want := "myval"
|
||||
ctx := context.WithValue(context.Background(), key("mykey"), want)
|
||||
sel := Dialect(dialect.Postgres).Select().WithContext(ctx)
|
||||
if got := sel.Context().Value(key("mykey")).(string); got != want {
|
||||
t.Fatalf("expected selector context key to be %q but got %q", want, got)
|
||||
}
|
||||
if got := sel.Clone().Context().Value(key("mykey")).(string); got != want {
|
||||
t.Fatalf("expected cloned selector context key to be %q but got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user