cached

Caches all the results of a query into memory at once.

This allows to keep all the rows returned from a query accessible in any order and indefinitely.

Return Value

A CachedResults struct that allows to iterate on the rows and their columns with an array-like interface.

The CachedResults struct is equivalent to an array of 'rows', which in turn can be viewed as either an array of ColumnData or as an associative array of ColumnData indexed by the column names.

Examples

1 auto db = Database(":memory:");
2 db.run("CREATE TABLE test (msg TEXT, num FLOAT);
3         INSERT INTO test (msg, num) VALUES ('ABC', 123);
4         INSERT INTO test (msg, num) VALUES ('DEF', 456);");
5 
6 auto results = db.execute("SELECT * FROM test").cached;
7 assert(results.length == 2);
8 assert(results[0][0].as!string == "ABC");
9 assert(results[0][1].as!int == 123);
10 assert(results[1]["msg"].as!string == "DEF");
11 assert(results[1]["num"].as!int == 456);

Meta