53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
|
package sdbc
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func Test__find_FindById(t *testing.T) {
|
||
|
var driver = NewSDBC(&Config{
|
||
|
Dbname: "test.db",
|
||
|
MaxIdleConn: 10,
|
||
|
MaxOpenConn: 100,
|
||
|
MaxLifetime: time.Hour,
|
||
|
Debug: true,
|
||
|
}).BindModel(&ModelArticles{})
|
||
|
var doc = &ModelArticles{
|
||
|
Title: "hello world1",
|
||
|
CreateTime: time.Now().Unix(),
|
||
|
}
|
||
|
err := driver.Find().FindById(5, doc)
|
||
|
assert.NoError(t, err)
|
||
|
t.Logf("doc: %v", doc)
|
||
|
}
|
||
|
|
||
|
func Test__find_FindByIds(t *testing.T) {
|
||
|
var driver = NewSDBC(&Config{
|
||
|
Dbname: "test.db",
|
||
|
MaxIdleConn: 10,
|
||
|
MaxOpenConn: 100,
|
||
|
MaxLifetime: time.Hour,
|
||
|
Debug: true,
|
||
|
}).BindModel(&ModelArticles{})
|
||
|
var docs []ModelArticles
|
||
|
err := driver.Find().FindByIds([]int{4, 5, 6}, &docs)
|
||
|
assert.NoError(t, err)
|
||
|
t.Logf("doc: %v", docs)
|
||
|
}
|
||
|
|
||
|
func Test__find_Find(t *testing.T) {
|
||
|
var driver = NewSDBC(&Config{
|
||
|
Dbname: "test.db",
|
||
|
MaxIdleConn: 10,
|
||
|
MaxOpenConn: 100,
|
||
|
MaxLifetime: time.Hour,
|
||
|
Debug: true,
|
||
|
}).BindModel(&ModelArticles{})
|
||
|
var docs []ModelArticles
|
||
|
err := driver.Find().SetNot("id = ?", 1).SetWhere("create_time = ?", 0).SetOr("update_time = ?", 0).Find(&docs)
|
||
|
assert.NoError(t, err)
|
||
|
t.Logf("doc: %v", docs)
|
||
|
}
|