89 lines
2.8 KiB
Markdown
89 lines
2.8 KiB
Markdown
# Todo
|
|
|
|
- replace mk_column with builder style (see `query/builder.hpp`)
|
|
- fix corresponding tests
|
|
- enhance query helper macro to look like the `book` class below
|
|
- add `aliasable_table`(see class below)
|
|
- add `as()` methode to table class
|
|
- move `sql_function_t` to own header in namespace `matador::sql`
|
|
- move `prepare_*` methods from `dialect` to `query_compiler`
|
|
- add `session_insert_builder` and `session_update_builder` (returning multiple statements)
|
|
- finish `attribued_definition` (also in `repository` class -> dependencies)
|
|
- fix compile errors
|
|
- finish fetch eager has-many/belongs-to relations
|
|
- implement lazy loading
|
|
- implement polymorphic class hierarchies
|
|
- finish `schema` and `schema_repository` classes (move add/drop from `session` to `schema`)
|
|
|
|
## book class
|
|
```cpp
|
|
class book : public matador::sql::aliasable_table<Book> {
|
|
public:
|
|
using aliasable_table::as;
|
|
|
|
Book() : aliasable_table("book", "") {}
|
|
|
|
private:
|
|
friend class aliasable_table;
|
|
|
|
explicit Book(std::string alias)
|
|
: aliasable_table("book", std::move(alias)) {}
|
|
|
|
public:
|
|
matador::sql::column id = create_column("id", *this);
|
|
matador::sql::column title = create_column("title", *this);
|
|
matador::sql::column year = create_column("year", *this);
|
|
};
|
|
```
|
|
|
|
## aliasable_table
|
|
```cpp
|
|
class table {
|
|
public:
|
|
using iterator = std::vector<column>::iterator;
|
|
using const_iterator = std::vector<column>::const_iterator;
|
|
|
|
explicit table(std::string name) : name_(std::move(name)) {}
|
|
table(std::string name, std::vector<column> columns)
|
|
: name_(std::move(name)), columns_(std::move(columns)) {}
|
|
|
|
void add_column(column column) {
|
|
column.table_ = shared_from_this();
|
|
columns_.emplace_back(std::move(column));
|
|
}
|
|
|
|
static const column& create_column(std::string name, table& t) {
|
|
column c{std::move(name)};
|
|
c.table_ = &t;
|
|
t.columns_.emplace_back(std::move(c));
|
|
return t.columns_.back();
|
|
}
|
|
operator const std::vector<column>&() const { return columns_; }
|
|
table as_table() const { return {name_, columns_}; }
|
|
|
|
iterator begin() { return columns_.begin(); }
|
|
iterator end() { return columns_.end(); }
|
|
|
|
[[nodiscard]] bool empty() const { return columns_.empty(); }
|
|
[[nodiscard]] size_t size() const { return columns_.size(); }
|
|
|
|
[[nodiscard]] const std::string& name() const { return name_; }
|
|
[[nodiscard]] const std::vector<column>& columns() const { return columns_; }
|
|
private:
|
|
std::string name_;
|
|
std::vector<column> columns_;
|
|
};
|
|
|
|
template < typename Type >
|
|
class aliasable_table : public table {
|
|
public:
|
|
aliasable_table(std::string name, std::string alias)
|
|
: table(std::move(name))
|
|
, alias_(std::move(alias)) {}
|
|
|
|
Type as(std::string alias) { return Type{std::move(alias)}; }
|
|
|
|
private:
|
|
std::string alias_;
|
|
};
|
|
``` |