-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooktable.cpp
More file actions
186 lines (159 loc) · 5.08 KB
/
Copy pathbooktable.cpp
File metadata and controls
186 lines (159 loc) · 5.08 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "booktable.hpp"
#include "search.hpp"
#include "book.hpp"
#include "author.hpp"
#include "tag.hpp"
#include "publisher.hpp"
#include "serie.hpp"
#include "format.hpp"
Data* BookTable::createData(cppdb::result& res) const
{
std::string summary;
int rating = -1;
std::string path;
try {
summary = res.get<std::string>("summary", "");
} catch(cppdb::invalid_column const& e) {}
try {
rating = res.get<int>("rating", rating);
} catch(cppdb::invalid_column const& e) {}
try {
path = res.get<std::string>("path", path);
} catch(cppdb::invalid_column const& e) {}
Book* book = Book::create(
res.get<int>("id"),
res.get<std::string>("title"),
res.get<std::string>("sort", ""),
res.get<int>("series_index"),
summary,
rating,
path
);
Author* author = Author::create(
res.get<int>("author_id", 0),
res.get<std::string>("author", ""),
res.get<std::string>("author_sort", "")
);
book->addAuthor(author);
author->addBook(book);
try {
Tag* tag = Tag::create(
res.get<int>("tag_id", 0),
res.get<std::string>("tag", "")
);
book->addTag(tag);
tag->addBook(book);
} catch(cppdb::cppdb_error const& e) {}
try {
Publisher* pub = Publisher::create(
res.get<int>("publisher_id", 0),
res.get<std::string>("publisher", ""),
res.get<std::string>("publisher_sort", "")
);
book->addPublisher(pub);
pub->addBook(book);
} catch(cppdb::cppdb_error const& e) {}
try {
Serie* serie = Serie::create(
res.get<int>("serie_id", 0),
res.get<std::string>("serie", ""),
res.get<std::string>("serie_sort", "")
);
book->addSerie(serie);
serie->addBook(book);
} catch(cppdb::cppdb_error const& e) {}
try {
Format* format = Format::create(
res.get<int>("file_id"),
res.get<std::string>("filename"),
res.get<std::string>("format"),
res.get<int>("filesize")
);
book->addFormat(format);
format->addBook(book);
} catch(cppdb::cppdb_error const& e) {}
return book;
}
std::set<Data*> BookTable::fetchAll()
{
std::vector<std::string> fields{
"id",
"title",
"sort",
"series_index",
"a.name author",
"a.id author_id",
"a.sort author_sort"
};
std::vector<Join> joins;
joins.push_back(createJoin("books_authors_link ba", "book", "id"));
joins.push_back(createJoin("authors a", "id", "author", "ba"));
return Table::fetchAll(fields, joins);
}
Data* BookTable::fetch(int id)
{
std::vector<std::string> fields{
"id",
"title",
"sort",
"path",
"series_index",
"d.format",
"d.id file_id",
"d.name filename",
"d.uncompressed_size filesize",
"c.text summary",
"r.rating",
"a.name author",
"a.id author_id",
"a.sort author_sort",
"k.name tag",
"k.id tag_id",
"p.name publisher",
"p.id publisher_id",
"p.sort publisher_sort",
"s.name serie",
"s.id serie_id",
"s.sort serie_sort"
};
std::vector<Join> joins;
joins.push_back(createJoin("books_authors_link ba", "book", "id"));
joins.push_back(createJoin("authors a", "id", "author", "ba"));
joins.push_back(createJoin("books_ratings_link br", "book", "id"));
joins.push_back(createJoin("ratings r", "id", "rating", "br"));
joins.push_back(createJoin("books_tags_link bk", "book", "id"));
joins.push_back(createJoin("tags k", "id", "tag", "bk"));
joins.push_back(createJoin("books_publishers_link bp", "book", "id"));
joins.push_back(createJoin("publishers p", "id", "publisher", "bp"));
joins.push_back(createJoin("books_series_link bs", "book", "id"));
joins.push_back(createJoin("series s", "id", "series", "bs"));
joins.push_back(createJoin("comments c", "book", "id"));
joins.push_back(createJoin("data d", "book", "id"));
return Table::fetch(id, fields, joins);
}
std::string BookTable::searchQuery(const std::set< std::string >& query, const std::string& op)
{
std::vector<std::string> fields{
"title",
"c.text"
};
std::vector<Join> joins;
joins.push_back(createJoin("comments c", "book", "id"));
return Table::searchQuery(query, op, fields, joins);
}
std::set<Data*> BookTable::search(SearchQuery const& query)
{
std::vector<std::string> fields{
"id",
"title",
"sort",
"series_index",
"a.name author",
"a.id author_id",
"a.sort author_sort"
};
std::vector<Join> joins;
joins.push_back(createJoin("books_authors_link ba", "book", "id"));
joins.push_back(createJoin("authors a", "id", "author", "ba"));
return Table::search(query, fields, joins);
}