forked from zhihu/norm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_finished.go
56 lines (49 loc) · 1.45 KB
/
api_finished.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
package norm
import (
"github.com/zhihu/norm/dialectors"
"github.com/zhihu/norm/internal/converts"
)
// Execute 执行某条sql
func (db *DB) Execute(sql string) (*dialectors.ResultSet, error) {
return db.execute(sql)
}
// ExecuteAndParse 执行某条sql, 然后解析为传入的结构.
// in 可以是 map[string]interface{}, *Strcut, *[]map, *[]struct
func (db *DB) ExecuteAndParse(sql string, in interface{}) error {
nResult, err := db.execute(sql)
if err != nil {
return err
}
return converts.UnmarshalResultSet(nResult, in)
}
// InsertVertex 解析结构体, 然后插入一个点.
func (db *DB) InsertVertex(in IVertex) error {
sql, err := converts.ConvertToCreateVertexSql(in, in.TagName(), in.GetVid(), in.GetPolicy())
if err != nil {
return err
}
_, err = db.execute(sql)
return err
}
// InsertEdge 解析结构体, 然后插入一条边.
func (db *DB) InsertEdge(in IEdge) error {
sql, err := converts.ConvertToCreateEdgeSql(in, in.EdgeName(), in.GetVidSrc(), in.GetVidDst(),
in.GetVidSrcPolicy(), in.GetVidDstPolicy())
if err != nil {
return err
}
_, err = db.execute(sql)
return err
}
// ReturnRow 返回 nsql 执行的原始结果, 不进行任何加工
func (db *DB) ReturnRow() (*dialectors.ResultSet, error) {
return db.execute(db.sql)
}
// Return 返回数据并将结果反序列化到 out 结构体中
func (db *DB) Return(out interface{}) error {
// result, err := db.Row()
// if err != nil {
// return err
// }
panic("")
}