Skip to content
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

Is there any way to use this lib to create a InfluxDB database #46

Open
mong0520 opened this issue Sep 10, 2020 · 1 comment
Open

Is there any way to use this lib to create a InfluxDB database #46

mong0520 opened this issue Sep 10, 2020 · 1 comment

Comments

@mong0520
Copy link

I'd like to use this lib to create a new InfluxDB database like the SQL command create database xxx.
Is it possible to do that?

@jknutson
Copy link

jknutson commented Dec 16, 2020

There is a NewQuery function in the client package: https://github.com/influxdata/influxdb1-client/blob/master/v2/client.go#L471-L473

You could probably just change the example in the readme to execute the query that you wish to run:

func ExampleClient_query() {
	c, err := client.NewHTTPClient(client.HTTPConfig{
		Addr: "http://localhost:8086",
	})
	if err != nil {
		fmt.Println("Error creating InfluxDB Client: ", err.Error())
	}
	defer c.Close()

	q := client.NewQuery("create database xxx", "", "")
	if response, err := c.Query(q); err == nil && response.Error() == nil {
		fmt.Println(response.Results)
	}
}

I've not tested this, but it might work.

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants