Code Monkey home page Code Monkey logo

Comments (4)

amacneil avatar amacneil commented on August 27, 2024

I'm not sure I understand the problem. Regarding the constructor, are you using dbmate as a library or a CLI?

Dbmate is intended to take a URL connection string, not a MySQL DSN. Is there a problem with using a URL such as mysql://boulder@localhost/boulder_test?parseTime=true?

from dbmate.

mmailhos avatar mmailhos commented on August 27, 2024

I'm not sure I understand the problem. Regarding the constructor, are you using dbmate as a library or a CLI?

As a library.

Is there a problem with using a URL such as mysql://boulder@localhost/boulder_test?parseTime=true?

No but there is a problem with this, for example:

sqlConfig := &mysql.Config{
	User:                 "root",
	Passwd:             "secret",
	Addr:                 "localhost:3306",
	Net:		          "tcp",
	DBName:           "mysql",
	AllowNativePasswords: true,
}
_, err := url.Parse("mysql://" + sqlConfig.FormatDSN())
// DNS:  root:secret@tcp(localhost:3306)/mysql?maxAllowedPacket=0
// parse mysql://root:secret@tcp(localhost:3306)/mysql?maxAllowedPacket=0: invalid port ":3306)" after host

https://play.golang.org/p/E12R0IG4X_7

Dbmate is intended to take a URL connection string, not a MySQL DSN.

Ok, that's not an issue if this is by design then. I just think it would be good to follow MySQL DSN format.

from dbmate.

amacneil avatar amacneil commented on August 27, 2024

I see. As you noticed, when using dbmate as an API the libraries assume that your connection string is a valid URL. We assume that any database connection string can be formatted as a url (and in fact many/most languages can support a url connection string).

The DSN format you're using above seems to be specific to the Go MySQL driver, correct? I can't find any references to it in the MySQL documentation. The reason I ask is that if it were a standard cross-language MySQL connection string format then it might make sense for us to support it (even though this would require some significant refactoring), but if it's unique to the Go MySQL driver then I think it makes more sense to leave this out.

In the meantime, you can generate a valid connection URL from your mysql.Config very easily using fmt.Sprintf.

from dbmate.

amacneil avatar amacneil commented on August 27, 2024

I looked further into this. Supporting arbitrary strings instead of a url.URL requires pretty significant refactoring since we need to be able to parse the connection string before providing it to the driver (e.g. for connecting to the root database), and each go database driver expects different things.

I'm not convinced this is worth adding support for considering the workaround you suggested is pretty simple. Dbmate is designed to support multiple databases with a standardized interface, and for now it's simpler if we keep the interface requiring a URL.

from dbmate.

Related Issues (20)

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.