forked from go-ozzo/ozzo-dbx
-
Notifications
You must be signed in to change notification settings - Fork 31
/
builder_oci_test.go
56 lines (44 loc) · 1.75 KB
/
builder_oci_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
// Copyright 2016 Qiang Xue. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package dbx
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOciBuilder_DropIndex(t *testing.T) {
b := getOciBuilder()
q := b.DropIndex("users", "idx")
assert.Equal(t, q.SQL(), `DROP INDEX "idx"`, "t1")
}
func TestOciBuilder_RenameTable(t *testing.T) {
b := getOciBuilder()
q := b.RenameTable("users", "user")
assert.Equal(t, q.SQL(), `ALTER TABLE "users" RENAME TO "user"`, "t1")
}
func TestOciBuilder_AlterColumn(t *testing.T) {
b := getOciBuilder()
q := b.AlterColumn("users", "name", "int")
assert.Equal(t, q.SQL(), `ALTER TABLE "users" MODIFY "name" int`, "t1")
}
func TestOciQueryBuilder_BuildOrderByAndLimit(t *testing.T) {
qb := getOciBuilder().QueryBuilder()
sql := qb.BuildOrderByAndLimit("SELECT *", []string{"name"}, 10, 2)
expected := "WITH USER_SQL AS (SELECT *\nORDER BY \"name\"),\n\tPAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)\nSELECT * FROM PAGINATION WHERE rowNumId > 2 AND rowNum <= 10"
assert.Equal(t, sql, expected, "t1")
sql = qb.BuildOrderByAndLimit("SELECT *", nil, -1, -1)
expected = "SELECT *"
assert.Equal(t, sql, expected, "t2")
sql = qb.BuildOrderByAndLimit("SELECT *", []string{"name"}, -1, -1)
expected = "SELECT *\nORDER BY \"name\""
assert.Equal(t, sql, expected, "t3")
sql = qb.BuildOrderByAndLimit("SELECT *", nil, 10, -1)
expected = "WITH USER_SQL AS (SELECT *),\n\tPAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)\nSELECT * FROM PAGINATION WHERE rowNum <= 10"
assert.Equal(t, sql, expected, "t4")
}
func getOciBuilder() Builder {
db := getDB()
b := NewOciBuilder(db, db.sqlDB)
db.Builder = b
return b
}