Skip to content

Commit e947eb8

Browse files
committed
fixed a bug where SyncDb return empty string
1 parent d6cdb6a commit e947eb8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ configs/**
33
db/**
44
.vscode
55
__debug_bin
6+

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ build:
77

88
install:
99
go install github.com/asolopovas/dsync@latest
10+
11+
test:
12+
go run ./main.go -c ./dsync-config.json
13+

src/libs.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ func DumpRemoteDB(config JsonConfig) ([]byte, error) {
109109
}
110110

111111
func WriteToLocalDB(sqlDumpStr string, conf JsonConfig, dumpDb bool) {
112+
fmt.Println("Writing to local DB")
112113
sqlDump := []byte(sqlDumpStr)
113114
var stdin bytes.Buffer
114115
stdin.Write(sqlDump)
115116

116117
if dumpDb {
118+
fmt.Println("saving db.sql...")
117119
os.WriteFile("db.sql", sqlDump, 0644)
118120
}
119121

@@ -177,11 +179,10 @@ func SyncFiles(conf JsonConfig) {
177179
func SyncDb(conf JsonConfig) (string, error) {
178180
var localDump string
179181
remoteDump, err := DumpRemoteDB(conf)
180-
if err == nil {
182+
if err != nil {
181183
return "", err
182184
}
183185

184-
// Replace String in Local DB
185186
localDump = string(remoteDump)
186187
for _, item := range conf.DbReplace {
187188
localDump = strings.Replace(localDump, item.From, item.To, -1)

0 commit comments

Comments
 (0)