Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nfjBill committed Feb 15, 2022
1 parent 1fc899b commit 8a4accb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# gorm-driver-dm
# GORM DM8 Driver

达梦数据库`gorm`驱动

## Quick Start

```go
import (
"github.com/nfjBill/gorm-driver-dm"
"gorm.io/gorm"
)

// https://github.com/nfjBill/gorm-driver-dm
dsn := "dm://SYSDBA:[email protected]:5236?autoCommit=true"
db, err := gorm.Open(dm.Open(dsn), &gorm.Config{})
```

达梦数据库用户名即模式名

## 入门

- `clone`本项目到本地,进入项目目录
- 修改`dsn`调整为本地正确信息
- 运行`go test -v`
- 如果无报错,参考`dm_test.go`使用即可

## 注意事项

- 超过4096长度字符串,需要使用`dmSchema.Clob`,不超过使用`string`即可
- 列名不要使用达梦关键字,否则会出现错误
6 changes: 3 additions & 3 deletions dm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func TestWhere(t *testing.T) {
}
}

func TestAll(t *testing.T) {
func TestGetAll(t *testing.T) {
var data []User
err := Table().GetAll(&data)

if err != nil {
fmt.Printf("Error: failed to All: %v\n", err)
fmt.Printf("Error: failed to GetAll: %v\n", err)
return
}
}
Expand All @@ -109,7 +109,7 @@ func TestDelete(t *testing.T) {
_ = Table(&User{Key: "1"}).GetWhere(&data)

if err != nil || len(data) == 1 {
fmt.Printf("Error: failed to Update: %v\n", err)
fmt.Printf("Error: failed to Delete: %v\n", err)
return
}
}
Expand Down
3 changes: 0 additions & 3 deletions schema/clob.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import (

type Clob string

// 写入数据库之前,对数据做类型转换
func (clob Clob) Value() (driver.Value, error) {
if len(clob) == 0 {
return nil, nil
}
return string(clob), nil
}

// 将数据库中取出的数据,赋值给目标类型
func (clob *Clob) Scan(v interface{}) error {
switch v.(type) {
case *dmr.DmClob:
Expand All @@ -32,7 +30,6 @@ func (clob *Clob) Scan(v interface{}) error {
*clob = Clob(str)
break

//非clob,当成字符串,兼容oracle
default:
*clob = Clob(v.(string))
}
Expand Down

0 comments on commit 8a4accb

Please sign in to comment.