mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-04 07:29:30 -05:00
a2714be30e
Added practically everything I wanted to have in except for updating columns. Needed to name the schema namespace as Orm::SchemaNs to avoid collision with the Orm::Schema class. - unit tests with great coverage - new schema constants - a new prefix_indexes and engine DB conncetion configurations Others: - IsModel tag - enhanced columnize in the BaseGrammar - used a new columnize logic in all grammars - new constants - new container utils class for joining containers - new DB::driver() getter for QSqlDriver - avoid possible crash in tests with pretend, added empty log checks - clang tidy, excluded to word from short variable names
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#pragma once
|
|
#ifndef ORM_UTILS_CONTAINER_HPP
|
|
#define ORM_UTILS_CONTAINER_HPP
|
|
|
|
#include "orm/macros/systemheader.hpp"
|
|
TINY_SYSTEM_HEADER
|
|
|
|
#include "orm/constants.hpp"
|
|
#include "orm/ormconcepts.hpp"
|
|
|
|
TINYORM_BEGIN_COMMON_NAMESPACE
|
|
|
|
namespace Orm::Utils
|
|
{
|
|
|
|
/*! Containers related library class. */
|
|
class Container
|
|
{
|
|
Q_DISABLE_COPY(Container)
|
|
|
|
public:
|
|
/*! Deleted default constructor, this is a pure library class. */
|
|
Container() = delete;
|
|
/*! Deleted destructor. */
|
|
~Container() = delete;
|
|
|
|
/*! Convert a string container into a (comma) delimited string. */
|
|
template<ColumnContainer T, DelimiterConcept D = const QString &>
|
|
static QString
|
|
join(const T &container, D &&delimiter = Constants::COMMA);
|
|
};
|
|
|
|
template<ColumnContainer T, DelimiterConcept D>
|
|
QString Container::join(const T &container, D &&delimiter)
|
|
{
|
|
QString columnized;
|
|
// Estimate a size to avoid resizing, 7 for an item and 2 for the delimiter
|
|
columnized.reserve(container.size() * (7 + 2));
|
|
|
|
if (container.isEmpty())
|
|
return columnized;
|
|
|
|
const auto end = container.cend() - 1;
|
|
auto it = container.begin();
|
|
|
|
for (; it < end; ++it)
|
|
columnized += Constants::NOSPACE.arg(*it).arg(std::forward<D>(delimiter));
|
|
|
|
if (it == end)
|
|
columnized += *it;
|
|
|
|
return columnized;
|
|
}
|
|
|
|
} // namespace Orm::Utils
|
|
|
|
TINYORM_END_COMMON_NAMESPACE
|
|
|
|
#endif // ORM_UTILS_CONTAINER_HPP
|