Skip to content

Commit ca254c6

Browse files
author
Enric Sala
committed
Add support for executing arbitrary queries and commands
Mostly intended for use with schema exploration and management commands
1 parent 7dea756 commit ca254c6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ ttable = weather.timetable('Europe/Paris');
170170

171171
Notice that the `time()` and `timetable()` methods take an optional timezone argument.
172172

173+
Other commands
174+
--------------
175+
176+
Use `runCommand(command, requiresPost)` for executing commands not provided in the library:
177+
178+
```matlab
179+
% Show series and tag keys in a database
180+
influxdb.runCommand('SHOW SERIES ON "example" FROM "weather"');
181+
influxdb.runCommand('SHOW TAG KEYS ON "example" FROM "weather"');
182+
183+
% Create and drop a database
184+
influxdb.runCommand('CREATE DATABASE "example"', true);
185+
influxdb.runCommand('DROP DATABASE "example"', true);
186+
187+
% Create a retention policy that keeps data for one day
188+
influxdb.runCommand('CREATE RETENTION POLICY "one_day" ON "example" DURATION 1d REPLICATION 1', true);
189+
influxdb.runCommand('SHOW RETENTION POLICIES ON "example"', false);
190+
```
191+
192+
See the [InfluxDB documentation][influxdb-docs] for more schema exploration and management commands.
193+
173194

174195
Contributing
175196
------------

influxdb-client/InfluxDB.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@
106106
function builder = writer(obj)
107107
builder = WriteBuilder().influxdb(obj);
108108
end
109+
110+
% Execute other queries or commands
111+
function response = runCommand(obj, command, requiresPost)
112+
url = [obj.Url '/query'];
113+
opts = weboptions('Username', obj.User, 'Password', obj.Password);
114+
if nargin > 2 && requiresPost
115+
opts.Timeout = obj.WriteTimeout;
116+
response = webwrite(url, 'q', command, opts);
117+
else
118+
opts.Timeout = obj.ReadTimeout;
119+
response = webread(url, 'q', command, opts);
120+
end
121+
end
109122
end
110123

111124
end

0 commit comments

Comments
 (0)