New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL support #239

Open
avelino opened this Issue Oct 30, 2017 · 11 comments

Comments

4 participants
@avelino
Member

avelino commented Oct 30, 2017

No description provided.

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Oct 30, 2017

I'm going to start developing this driver.

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Oct 30, 2017

I will develop it as a separate package.
Do you have a name suggestion for the package?

@fabriziomello

This comment has been minimized.

Contributor

fabriziomello commented Oct 30, 2017

Why a separate package? IMHO is better just create mysql directory inside adapter repo.

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Oct 30, 2017

What do others think about it?
Which way is best for code maintenance?

@dhuckins

This comment has been minimized.

dhuckins commented Nov 30, 2017

IMO use adapters
For implementation, reuse the config?
https://github.com/prest/config/blob/master/config.go

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Nov 30, 2017

Yes.
The MySQL connector is basically a copy of the postgres folder, with the settings for MySQL usage.

@dhuckins

This comment has been minimized.

dhuckins commented Nov 30, 2017

works for me. would find this useful, let me know through here if you fork it and can work on it

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Dec 18, 2017

@avelino @felipeweb @crgimenes @lerrua @fabriziomello
In the process of developing the MySQL adapter, I'm finding some points in the other packages that need to change to become multi-adapters.
As for example in:
prest > controllers > tables > SelectFromTables
Postgres
query := fmt.Sprintf(`%s "%s"."%s"."%s"`, selectStr, database, schema, table)
MySQL
query := fmt.Sprintf("%s `%s`.`%s`", selectStr, database, table)

I would like your opinion on how best to resolve this.
I thought about creating a method in the Adapter interface for each case that happens.
And from there each adapter implements its return, according to its standard.
What do you think? Any other ideas?

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Dec 30, 2017

Another thing.
The statements package has incompatible string patterns with MySQL and other databases.
I believe that the content of queries.go from the statements package must be inside the package of each adapter.

@joelmdesouza

This comment has been minimized.

Contributor

joelmdesouza commented Dec 30, 2017

In MySQL there is no way to return the inserted row directly in the insert.
Therefore you will need to make a select after the insert to return the line.
I think moving the indicated line in the commented code solves this problem and also the problem of the string pattern difference between Postgres and MySQL.

func InsertInTables(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	database := vars["database"]
	schema := vars["schema"]
	table := vars["table"]

	config.PrestConf.Adapter.SetDatabase(database)

	names, placeholders, values, err := config.PrestConf.Adapter.ParseInsertRequest(r)
	if err != nil {
		err = fmt.Errorf("could not perform InsertInTables: %v", err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
>>>>>   //Move this line into config.PrestConf.Adapter.Insert
>>>>>   sql := fmt.Sprintf(statements.InsertQuery, database, schema, table, names, placeholders)

	sc := config.PrestConf.Adapter.Insert(sql, values...)
	if sc.Err() != nil {
		http.Error(w, sc.Err().Error(), http.StatusBadRequest)
		return
	}
	w.Write(sc.Bytes())
}

The Insert function signature would change from:

func (adapter *Mysql) Insert(SQL string, params ...interface{}) (sc adapters.Scanner){
...
}

To:

func (adapter *Mysql) Insert(database string, schema string, table string, colsName string, placeholders string, params ...interface{}) (sc adapters.Scanner){
...
}

I need these parameters to be able to make the select that will return the inserted line.

@avelino

This comment has been minimized.

Member

avelino commented Feb 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment