forked from micanzhang/xorm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
session_cols_test.go
70 lines (56 loc) · 1.47 KB
/
session_cols_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2017 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 xorm
import (
"context"
"testing"
"github.com/lingochamp/core"
"github.com/stretchr/testify/assert"
)
func TestSetExpr(t *testing.T) {
assert.NoError(t, prepareEngine())
type UserExpr struct {
Id int64
Show bool
}
assert.NoError(t, testEngine.Sync2(context.Background(), new(UserExpr)))
cnt, err := testEngine.Insert(context.Background(), &UserExpr{
Show: true,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
var not = "NOT"
if testEngine.Dialect().DBType() == core.MSSQL {
not = "~"
}
cnt, err = testEngine.SetExpr("show", not+" `show`").ID(1).Update(context.Background(), new(UserExpr))
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
}
func TestCols(t *testing.T) {
assert.NoError(t, prepareEngine())
type ColsTable struct {
Id int64
Col1 string
Col2 string
}
assertSync(t, new(ColsTable))
_, err := testEngine.Insert(context.Background(), &ColsTable{
Col1: "1",
Col2: "2",
})
assert.NoError(t, err)
sess := testEngine.ID(1)
_, err = sess.Cols("col1").Cols("col2").Update(context.Background(), &ColsTable{
Col1: "",
Col2: "",
})
assert.NoError(t, err)
var tb ColsTable
has, err := testEngine.ID(1).Get(context.Background(), &tb)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, "", tb.Col1)
assert.EqualValues(t, "", tb.Col2)
}