-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.cpp
41 lines (34 loc) · 973 Bytes
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
#include "sql.hpp"
using books =
sql::schema<
"books", sql::index<"title">,
sql::column<"title", std::string>,
sql::column<"genre", std::string>,
sql::column<"year", unsigned>,
sql::column<"pages", unsigned>
>;
using authored =
sql::schema<
"authored", sql::index<>,
sql::column<"title", std::string>,
sql::column<"name", std::string>
>;
using query =
sql::query<
"SELECT title AS book, name AS author, year, pages "
"FROM books NATURAL JOIN (SELECT * FROM authored WHERE name = \"Harlan Ellison\") "
"WHERE year = 1967 OR year >= 1972 AND genre = \"science fiction\"",
books, authored
>;
int main()
{
authored a{ sql::load<authored>("tests/data/authored.tsv", '\t') };
books b{ sql::load<books>("tests/data/books.tsv", '\t') };
for (query q{ b, a }; auto const& [book, author, year, pages] : q)
{
std::cout << book << '\t' << author << '\t' << year << '\t' << pages << '\n';
}
return 0;
}