Delete this DB
Insert data into the DB.
Insert Mir times-series with single column into the DB. Supported time types are SysTime, DateTime, Date, and long.
Insert data into the DB.
Insert Mir times-series with multiple columns into the DB. Supported time types are SysTime, DateTime, Date, and long.
Sends management commands to the DB (CREATE, DROP). The parameter must be the full command (e.g. "DROP DATABASE mydb")
Queries the DB. The query must be a full InfluxDB query (e.g. "SELECT * FROM foo")
1 // not pure because of asdf.deserialize 2 3 string[string][] manages; 4 string[string][] queries; 5 string[string][] writes; 6 7 alias TestDatabase = DatabaseImpl!( 8 (url, cmd) => manages ~= ["url": url, "cmd": cmd], // manage 9 (url, db, query) { // query 10 queries ~= ["url": url, "db": db, "query": query]; 11 return 12 `{ 13 "results": [{ 14 "series": [{ 15 "columns": ["time", "othervalue", "tag1", "tag2", "value"], 16 "name": "lename", 17 "values": [ 18 ["2015-06-11T20:46:02Z", 4, "toto", "titi", 2], 19 ["2017-03-14T23:15:01.06282785Z", 3, "letag", "othertag", 1] 20 ] 21 }], 22 "statement_id": 33 23 }] 24 }`; 25 }, 26 (url, db, line) => writes ~= ["url": url, "db": db, "line": line] 27 ); 28 29 manages.shouldBeEmpty; 30 const database = TestDatabase("http://db.com", "testdb"); 31 manages.shouldEqual([["url": "http://db.com", "cmd": "CREATE DATABASE testdb"]]); 32 33 writes.shouldBeEmpty; 34 database.insert(Measurement("cpu", ["tag1": "foo"], ["temperature": "42"])); 35 writes.shouldEqual([["url": "http://db.com", "db": "testdb", 36 "line": "cpu,tag1=foo temperature=42"]]); 37 38 queries.shouldBeEmpty; 39 const response = database.query("SELECT * from foo"); 40 queries.shouldEqual([["url": "http://db.com", "db": "testdb", "query": "SELECT * from foo"]]); 41 42 response.results.length.shouldEqual(1); 43 response.results[0].statement_id.shouldEqual(33); 44 response.results[0].series.length.shouldEqual(1); 45 const series = response.results[0].series[0]; 46 series.shouldEqual( 47 MeasurementSeries( 48 "lename", //name 49 ["time", "othervalue", "tag1", "tag2", "value"], //columns 50 //values 51 [ 52 ["2015-06-11T20:46:02Z", "4", "toto", "titi", "2"], 53 ["2017-03-14T23:15:01.06282785Z", "3", "letag", "othertag", "1"], 54 ] 55 ) 56 );
string[] lines; alias TestDatabase = DatabaseImpl!( (url, cmd) { }, // manage (url, db, query) => `{}`, // query (url, db, line) => lines ~= line // write ); const database = TestDatabase("http://db.com", "testdb"); database.insert( Measurement("cpu", ["index": "1"], ["temperature": "42"]), Measurement("cpu", ["index": "2"], ["temperature": "42"]), Measurement("cpu", ["index": "2"], ["temperature": "42"]), ); () @trusted { lines.shouldEqual( [ "cpu,index=1 temperature=42\ncpu,index=2 temperature=42\ncpu,index=2 temperature=42", ] ); }();
Holds information about the database name and URL, forwards it to the implemetation functions for managing, querying and writing to the DB