Comments (4)
I guess this would fix it.
Index: database/mysql.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/database/mysql.go b/database/mysql.go
--- a/database/mysql.go (revision 9284e51bb1d5409d4ccf2b6f61f0517070a48eef)
+++ b/database/mysql.go (date 1644248808874)
@@ -328,7 +328,13 @@
}
func (d *mySQL) dumpTableData(w io.Writer, table string) error {
- rows, columns, err := d.selectAllDataFor(table)
+ columns, err := d.getColumnsForSelect(table, false)
+
+ if err != nil {
+ return err
+ }
+
+ rows, _, err := d.selectAllDataFor(table)
if a := d.evaluateErrors(err, rows); a != nil {
return a
}
@@ -442,7 +448,7 @@
}
func (d *mySQL) getSelectQueryFor(table string) (cols []string, query string, err error) {
- cols, err = d.getColumnsForSelect(table)
+ cols, err = d.getColumnsForSelect(table, true)
if err != nil {
return cols, "", err
}
@@ -461,7 +467,7 @@
return "UNLOCK TABLES;\n"
}
-func (d *mySQL) getColumnsForSelect(table string) (columns []string, err error) {
+func (d *mySQL) getColumnsForSelect(table string, considerRewriteMap bool) (columns []string, err error) {
rows, err := d.db.Query(fmt.Sprintf("SELECT * FROM `%s` LIMIT 1", table))
if a := d.evaluateErrors(err, rows); a != nil {
return columns, a
@@ -484,7 +490,11 @@
}
replacement, ok := d.selectMap[strings.ToLower(table)][strings.ToLower(column)]
- if ok {
+ if ok && considerRewriteMap {
+ if len(replacement) >= 5 && replacement[0:5] == "faker" {
+ replacement = fmt.Sprintf("'%s'", replacement)
+ }
+
columns = append(columns, fmt.Sprintf("%s AS `%s`", replacement, column))
} else {
columns = append(columns, fmt.Sprintf("`%s`", column))
What you think?
from go-mad.
or getColumnsForSelect
returns a struct with two functions then getRewritedColumns, getColumns
from go-mad.
Both solutions are legit, the second one may be a bit cleaner but will increase (slightly) the memory footprint.
If you want to open a PR ❤️, go for the one you feel would be the best 🙂
from go-mad.
I am struggling with the current tests. They fail weird 😅
from go-mad.
Related Issues (10)
- Is --quick really faster on importing? HOT 2
- Hex blob columns HOT 8
- Gzip result file HOT 1
- Ignore generated columns HOT 13
- Progress bar to show progress HOT 3
- Rewrite only if data exists in the row HOT 3
- Database Triggers are missing HOT 2
- triggers can not be imported using mysql cli HOT 6
- cant find column named in Camelcase HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-mad.