Coder Social home page Coder Social logo

Comments (4)

shyim avatar shyim commented on September 26, 2024

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.

shyim avatar shyim commented on September 26, 2024

or getColumnsForSelect returns a struct with two functions then getRewritedColumns, getColumns

from go-mad.

bolovsky avatar bolovsky commented on September 26, 2024

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.

shyim avatar shyim commented on September 26, 2024

I am struggling with the current tests. They fail weird 😅

from go-mad.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.