goqu icon indicating copy to clipboard operation
goqu copied to clipboard

improve dialects usage

Open caioaao opened this issue 2 years ago • 0 comments

As of now, to register a dialect you have to import the package only for the side-effects and call goqu.Dialect with a name to use it. This commit proposes declaring the dialect name in a const so we can use it when fetching the dialect, thus ensuring the package with the init is being imported.

This means that, instead of doing this:

package bla
import (
	"github.com/doug-martin/goqu/v9"
	_ "github.com/doug-martin/goqu/v9/dialect/postgres"
)

var dialect = goqu.Dialect("postgres")

we can do this:

package bla
import (
	"github.com/doug-martin/goqu/v9"
	"github.com/doug-martin/goqu/v9/dialect/postgres"
)

var dialect = goqu.Dialect(postgres.DialectName)

Not a lot of difference, but it makes clear which import is registering the dialect.

PS: A side effect is that it could reduce the debugging time when you misspell the dialect name.

caioaao avatar Jul 05 '22 01:07 caioaao