Skip to content

Commit f7fe6cb

Browse files
committed
working on LazyOrm class
1 parent a36f3b7 commit f7fe6cb

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(LazyORM_HEADERS
1616
include/FilterVariant.h
1717
include/AbstractLazy.h
1818
include/FilteringAbstractLazy.h
19+
include/LazyOrm.h
1920

2021
include/MariadbLazy.h
2122
include/MariadbFilteringLazy.h
@@ -27,6 +28,7 @@ set(LazyORM_HEADERS
2728
include/PostgreFilteringLazy.h
2829

2930
include/Transaction.h
31+
3032
)
3133

3234
add_library(LazyOrm STATIC
@@ -36,6 +38,7 @@ add_library(LazyOrm STATIC
3638
src/DbList.cpp
3739
src/WhereFilter.cpp
3840
src/FilterVariant.cpp
41+
src/LazyOrm.cpp
3942

4043
src/AbstractLazy.cpp
4144
src/FilteringAbstractLazy.cpp

include/LazyOrm.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef LAZYORM_H
2+
#define LAZYORM_H
3+
4+
#include "MariadbLazy.h"
5+
#include "PostgreLazy.h"
6+
#include "SqliteLazy.h"
7+
8+
9+
10+
namespace LazyOrm {
11+
12+
class LazyOrm : public MariadbLazy, public PostgreLazy, public SqliteLazy
13+
{
14+
public:
15+
enum DBMS_TYPE
16+
{
17+
MariaDB =1,
18+
Postgre,
19+
Sqlite
20+
};
21+
22+
LazyOrm();
23+
24+
std::string queryString(const DBMS_TYPE &dbms);
25+
};
26+
27+
}
28+
29+
30+
#endif // LAZYORM_H

include/PostgreLazy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class PostgreLazy : public AbstractLazy
1010
{
1111
private:
1212
PostgreFilteringLazy mFilter;
13+
std::string primaryKey="id";
1314

1415
protected:
1516
std::string insert_query() const override;
@@ -33,6 +34,8 @@ class PostgreLazy : public AbstractLazy
3334

3435
void setFilter(const PostgreFilteringLazy filter);
3536

37+
void setPrimaryKey(const std::string &primaryKey);
38+
3639
};
3740
}
3841
#endif // POSTGRELAZY_H

src/AbstractLazy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ FilteringAbstractLazy& AbstractLazy::operator[](const LazyOrm::Filters &filter)
135135

136136
WhereFilter& AbstractLazy::operator[](const LazyOrm::NestedWhere &nestedWhere)
137137
{
138-
return mWhereFilter;//getCurrentFilters()[nestedWhere];
138+
return mWhereFilter;
139139
}
140140

141141
//void AbstractLazy::operator=(const LazyOrm::FilterVariant &variant)

src/LazyOrm.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "LazyOrm.h"
2+
3+
namespace LazyOrm {
4+
5+
LazyOrm::LazyOrm()
6+
{
7+
8+
}
9+
10+
std::string LazyOrm::queryString(const DBMS_TYPE &dbms)
11+
{
12+
switch (dbms) {
13+
case MariaDB:
14+
return static_cast<MariadbLazy*>(this)->queryString();
15+
case Postgre:
16+
return static_cast<PostgreLazy*>(this)->queryString();
17+
case Sqlite:
18+
return static_cast<SqliteLazy*>(this)->queryString();
19+
}
20+
}
21+
22+
}

src/PostgreLazy.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ PostgreLazy::PostgreLazy()
88

99
}
1010

11+
void PostgreLazy::setPrimaryKey(const std::string &primaryKey)
12+
{
13+
this->primaryKey = primaryKey;
14+
}
15+
1116
PostgreLazy::PostgreLazy(const std::string &table, const Query &queryType)
1217
{
1318
setTabeName(table);
@@ -35,7 +40,7 @@ std::string PostgreLazy::insert_query() const
3540
queryString.append(" ("+string_join(",",keys)+") ");
3641
queryString.append("VALUES");
3742
queryString.append(" ("+string_join(",",values)+") ");
38-
// TODO: RETURNING id; i dont now id name
43+
queryString.append(" returning "+primaryKey);
3944
queryString.append(";");
4045
return queryString;
4146
}

0 commit comments

Comments
 (0)