mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
!124 一些更新和bug
* fix: 代码合并 * feat:支持数据库版本兼容,目前兼容了oracle11g部分特性 * fix: 修改数据同步bug,数据sql里指定修改字段别,导致未正确记录修改字段值 * feat: 数据库迁移支持定时迁移和迁移到sql文件
This commit is contained in:
51
server/pkg/utils/writer/file_writer.go
Normal file
51
server/pkg/utils/writer/file_writer.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package writer
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type FileWriter struct {
|
||||
tryFlushCount int
|
||||
writer *os.File
|
||||
aborted bool
|
||||
}
|
||||
|
||||
func NewFileWriter(filePath string) *FileWriter {
|
||||
if filePath == "" {
|
||||
panic("filePath is empty")
|
||||
}
|
||||
|
||||
// 使用filepath.Dir函数提取文件夹路径
|
||||
dir := filepath.Dir(filePath)
|
||||
if dir != "" {
|
||||
// 检查文件夹路径,不存在则创建
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(dir, os.ModePerm)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fw, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &FileWriter{writer: fw}
|
||||
}
|
||||
|
||||
func (f *FileWriter) Close() {
|
||||
f.writer.Close()
|
||||
}
|
||||
|
||||
func (f *FileWriter) TryFlush() {
|
||||
}
|
||||
func (f *FileWriter) Write(b []byte) (n int, err error) {
|
||||
return f.writer.Write(b)
|
||||
}
|
||||
|
||||
func (f *FileWriter) WriteString(data string) {
|
||||
io.WriteString(f.writer, data)
|
||||
}
|
||||
50
server/pkg/utils/writer/gzip_writer.go
Normal file
50
server/pkg/utils/writer/gzip_writer.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package writer
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"mayfly-go/pkg/biz"
|
||||
)
|
||||
|
||||
type GzipWriter struct {
|
||||
tryFlushCount int
|
||||
writer *gzip.Writer
|
||||
aborted bool
|
||||
}
|
||||
|
||||
func NewGzipWriter(writer io.Writer) *GzipWriter {
|
||||
return &GzipWriter{writer: gzip.NewWriter(writer)}
|
||||
}
|
||||
|
||||
func (g *GzipWriter) WriteString(data string) {
|
||||
if g.aborted {
|
||||
return
|
||||
}
|
||||
if _, err := g.writer.Write([]byte(data)); err != nil {
|
||||
g.aborted = true
|
||||
biz.IsTrue(false, "数据库导出失败:%s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GzipWriter) Write(p []byte) (n int, err error) {
|
||||
if g.aborted {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := g.writer.Write(p); err != nil {
|
||||
g.aborted = true
|
||||
biz.IsTrue(false, "数据库导出失败:%s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (g *GzipWriter) Close() {
|
||||
g.writer.Close()
|
||||
}
|
||||
|
||||
func (g *GzipWriter) TryFlush() {
|
||||
if g.tryFlushCount%1000 == 0 {
|
||||
g.writer.Flush()
|
||||
}
|
||||
g.tryFlushCount += 1
|
||||
}
|
||||
10
server/pkg/utils/writer/writer.go
Normal file
10
server/pkg/utils/writer/writer.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package writer
|
||||
|
||||
import "io"
|
||||
|
||||
type CustomWriter interface {
|
||||
io.Writer
|
||||
WriteString(data string)
|
||||
Close()
|
||||
TryFlush()
|
||||
}
|
||||
Reference in New Issue
Block a user