1 struct Item 2 { 3 int _id; 4 string name; 5 } 6 7 auto db = Database(":memory:"); 8 db.run("CREATE TABLE items (name TEXT); 9 INSERT INTO items VALUES ('Light bulb')"); 10 11 auto results = db.execute("SELECT rowid AS id, name FROM items"); 12 auto row = results.front; 13 auto thing = row.as!Item(); 14 15 assert(thing == Item(1, "Light bulb"));
Returns a struct with field members populated from the row's data.
Neither the names of the fields nor the names of the columns are used on checked. The fields are filled with the columns' data in order. Thus, the order of the struct members must be the same as the order of the columns in the prepared statement.
SQLite's conversion rules will be used. For instance, if a string field has the same rank as an INTEGER column, the field's data will be the string representation of the integer.