kndndrj / nvim-dbee

Interactive database client for neovim
GNU General Public License v3.0
755 stars 51 forks source link

Use ParseURL in Redis adapter to properly parse complex URLs #110

Open sollymay opened 5 months ago

sollymay commented 5 months ago

Motivation

When you try to use redis with nvim-dbee and the Redis URL is not a “simple” redis://username:password@host you get an error err = dial tcp: address redis://username:password@host: too many colons in address. This has been documented in https://github.com/redis/go-redis/issues/864 if you look at the third and fourth comment.

This means you can’t really use the adapter with more “complex” type of connections which require additional parameters

Implementation

Instead of just passing the raw URL, use the https://godoc.org/github.com/go-redis/redis#ParseURL method to avoid this issue

sollymay commented 5 months ago

I think if you replace:

func (r *Redis) Connect(url string) (core.Driver, error) {
    c := redis.NewClient(&redis.Options{
        Addr:     url,
        Password: "",
        DB:       0,
    })

    return &redisDriver{
        redis: c,
    }, nil
}

with something like:

func (r *Redis) Connect(url string) (core.Driver, error) {
        opt, err := redis.ParseURL(url)
    if err != nil {
        panic(err)
    }
    c := redis.NewClient(&redis.Options{
        Addr:     opt.Addr,
        Password: opt.Password,
        DB:       opt.DB,
    })

    return &redisDriver{
        redis: c,
    }, nil
}

it would work. I tried to clone the repo and use the plugin locally to test and potentially doing a pull request, however, I can't seem to be able to set it up correclty using lazyvim and lazy.