File tree 2 files changed +31
-21
lines changed
2 files changed +31
-21
lines changed Original file line number Diff line number Diff line change 1
1
package sqlite
2
2
3
3
import (
4
- "fmt"
5
- "github.com/uozi-tech/cosy/settings"
6
- "gorm.io/driver/sqlite"
7
- "gorm.io/gorm"
8
- "path"
4
+ "fmt"
5
+ "gorm.io/driver/sqlite"
6
+ "gorm.io/gorm"
7
+ "path"
9
8
)
10
9
11
- func Open (dir string , dbs * settings.DataBase ) gorm.Dialector {
12
- return sqlite .Open (path .Join (dir , fmt .Sprintf ("%s.db" , dbs .Name )))
10
+ type DBSettings interface {
11
+ GetName () string
12
+ }
13
+
14
+ func Open (dir string , dbs DBSettings ) gorm.Dialector {
15
+ return sqlite .Open (path .Join (dir , fmt .Sprintf ("%s.db" , dbs .GetName ())))
13
16
}
Original file line number Diff line number Diff line change 1
1
package sqlite
2
2
3
3
import (
4
- "github.com/uozi-tech/cosy/settings"
5
- "gorm.io/driver/sqlite"
6
- "testing"
4
+ "gorm.io/driver/sqlite"
5
+ "testing"
7
6
)
8
7
8
+ type DataBase struct {
9
+ Name string
10
+ }
11
+
12
+ func (d * DataBase ) GetName () string {
13
+ return d .Name
14
+ }
15
+
9
16
func TestOpen (t * testing.T ) {
10
- dbs := & settings. DataBase {
11
- Name : "cosy" ,
12
- }
17
+ dbs := & DataBase {
18
+ Name : "cosy" ,
19
+ }
13
20
14
- dialector := Open ("" , dbs )
21
+ dialector := Open ("" , dbs )
15
22
16
- d , ok := dialector .(* sqlite.Dialector )
17
- if ! ok {
18
- t .Fatal ("dialector is not *Dialector" )
19
- }
20
- if d .DSN == "" {
21
- t .Error ("dialector.DSN is empty" )
22
- }
23
+ d , ok := dialector .(* sqlite.Dialector )
24
+ if ! ok {
25
+ t .Fatal ("dialector is not *Dialector" )
26
+ }
27
+ if d .DSN == "" {
28
+ t .Error ("dialector.DSN is empty" )
29
+ }
23
30
}
You can’t perform that action at this time.
0 commit comments