Initial Commit

This commit is contained in:
lganzzzo 2020-07-04 03:12:36 +03:00
commit e486f05f97
15 changed files with 948 additions and 0 deletions

47
.gitignore vendored Normal file
View File

@ -0,0 +1,47 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# tmp folder of install-deps
utility/install-deps/tmp/
# idea
.idea
cmake-build-debug/
# custom build
build/
# Mac
**/.DS_Store

109
CMakeLists.txt Normal file
View File

@ -0,0 +1,109 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
###################################################################################################
## These variables are passed to oatpp-module-install.cmake script
## use these variables to configure module installation
set(OATPP_THIS_MODULE_NAME oatpp-postgresql) ## name of the module (also name of folders in installation dirs)
set(OATPP_THIS_MODULE_VERSION "1.1.0") ## version of the module (also sufix of folders in installation dirs)
set(OATPP_THIS_MODULE_LIBRARIES oatpp-postgresql) ## list of libraries to find when find_package is called
set(OATPP_THIS_MODULE_TARGETS oatpp-postgresql) ## list of targets to install
set(OATPP_THIS_MODULE_DIRECTORIES oatpp-postgresql) ## list of directories to install
###################################################################################################
project(${OATPP_THIS_MODULE_NAME}
VERSION ${OATPP_THIS_MODULE_VERSION}
LANGUAGES CXX
## HOMEPAGE_URL "https://github.com/oatpp/oatpp-postgresql"
## DESCRIPTION "Something about postgresql"
)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(OATPP_DIR_SRC "Path to oatpp module directory (sources)")
option(OATPP_DIR_LIB "Path to directory with liboatpp (directory containing ex: liboatpp.so or liboatpp.dynlib)")
option(OATPP_BUILD_TESTS "Build tests for this module" ON)
option(OATPP_INSTALL "Install module binaries" ON)
set(OATPP_MODULES_LOCATION "INSTALLED" CACHE STRING "Location where to find oatpp modules. can be [INSTALLED|EXTERNAL|CUSTOM]")
###################################################################################################
## get oatpp main module in specified location
set(OATPP_MODULES_LOCATION_INSTALLED INSTALLED)
set(OATPP_MODULES_LOCATION_EXTERNAL EXTERNAL)
set(OATPP_MODULES_LOCATION_CUSTOM CUSTOM)
if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_INSTALLED)
message("Finding oatpp in location=INSTALLED")
find_package(oatpp ${OATPP_THIS_MODULE_VERSION} REQUIRED)
get_target_property(OATPP_INCLUDE oatpp::oatpp INTERFACE_INCLUDE_DIRECTORIES)
message("OATPP_INCLUDE=${OATPP_INCLUDE}")
get_target_property(OATPP_TEST_INCLUDE oatpp::oatpp-test INTERFACE_INCLUDE_DIRECTORIES)
message("OATPP_TEST_INCLUDE=${OATPP_TEST_INCLUDE}")
elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL)
message("Finding oatpp in location=EXTERNAL")
include(ExternalProject)
set(MODULE_WAIT_DEPS ON)
set(LIB_OATPP_EXTERNAL "lib_oatpp_external")
ExternalProject_Add(${LIB_OATPP_EXTERNAL}
GIT_REPOSITORY "https://github.com/oatpp/oatpp.git"
GIT_TAG origin/master
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOATPP_INSTALL=OFF -DOATPP_BUILD_TESTS=OFF
INSTALL_COMMAND cmake -E echo "SKIP INSTALL '${LIB_OATPP_EXTERNAL}'"
)
ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} BINARY_DIR)
set(OATPP_DIR_LIB ${BINARY_DIR}/src)
ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} SOURCE_DIR)
set(OATPP_DIR_SRC ${SOURCE_DIR}/src)
message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'")
message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'")
elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_CUSTOM)
message("Finding oatpp in location=CUSTOM")
message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'")
message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'")
else()
message("FATAL_ERROR Unknown location to find oatpp '${OATPP_MODULES_LOCATION}'")
endif()
if(OATPP_DIR_LIB)
link_directories(${OATPP_DIR_LIB})
endif()
###################################################################################################
## get dependencies
message("\n############################################################################")
message("## ${OATPP_THIS_MODULE_NAME} module. Resolving dependencies...\n")
## TODO find dependecies here (if some)
message("\n############################################################################\n")
###################################################################################################
## define targets
include(cmake/module-utils.cmake)
add_subdirectory("src")
if(OATPP_BUILD_TESTS)
enable_testing()
add_subdirectory("test")
endif()

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# oatpp-postgresql

93
azure-pipelines.yml Normal file
View File

@ -0,0 +1,93 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
jobs:
- job: ubuntu_16_04
displayName: 'Build - Ubuntu 16.04'
continueOnError: false
pool:
vmImage: 'Ubuntu 16.04'
workspace:
clean: all
steps:
- script: |
mkdir build
- script: |
git clone https://github.com/oatpp/oatpp
mkdir -p oatpp/build
displayName: 'Checkout - oatpp'
workingDirectory: build
- script: |
cmake ..
sudo make install
displayName: 'Build - oatpp'
workingDirectory: build/oatpp/build
- script: |
cmake ..
make
displayName: 'Build - module'
workingDirectory: build
- script: |
make test ARGS="-V"
displayName: 'Test'
workingDirectory: build
- job: macOS
displayName: 'Build - macOS'
continueOnError: false
pool:
vmImage: 'macOS-10.14'
workspace:
clean: all
steps:
- script: |
mkdir build
- script: |
git clone https://github.com/oatpp/oatpp
mkdir -p oatpp/build
displayName: 'Checkout - oatpp'
workingDirectory: build
- script: |
cmake ..
sudo make install
displayName: 'Build - oatpp'
workingDirectory: build/oatpp/build
- script: |
cmake ..
make
displayName: 'Build - module'
workingDirectory: build
- script: |
make test ARGS="-V"
displayName: 'Test'
workingDirectory: build
- job: windows
displayName: 'Build - Windows'
continueOnError: false
pool:
vmImage: 'windows-latest'
workspace:
clean: all
steps:
- script: |
MD build
- script: |
git clone https://github.com/oatpp/oatpp
MD oatpp\build
displayName: 'Checkout - oatpp'
workingDirectory: build
- script: |
cmake ..
cmake --build . --target INSTALL
displayName: 'Build - oatpp'
workingDirectory: build\oatpp\build
- script: |
cmake ..
cmake --build .
displayName: 'Build - module'
workingDirectory: build
- script: |
module-tests.exe
displayName: 'Test'
workingDirectory: build\test\Debug\

View File

@ -0,0 +1,11 @@
@PACKAGE_INIT@
if(NOT TARGET oatpp::@OATPP_MODULE_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@OATPP_MODULE_NAME@Targets.cmake")
endif()
set_and_check(@OATPP_MODULE_NAME@_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/oatpp-@OATPP_MODULE_VERSION@/@OATPP_MODULE_NAME@/")
set_and_check(@OATPP_MODULE_NAME@_LIBRARIES_DIRS "${PACKAGE_PREFIX_DIR}/@OATPP_MODULE_LIBDIR@/oatpp-@OATPP_MODULE_VERSION@/")
set(@OATPP_MODULE_NAME@_LIBRARIES @OATPP_MODULE_LIBRARIES@)
set(OATPP_BASE_DIR "${PACKAGE_PREFIX_DIR}/include/oatpp-@OATPP_MODULE_VERSION@/")

107
cmake/module-install.cmake Normal file
View File

@ -0,0 +1,107 @@
#######################################################################################
## Set module properties
## all oatpp modules should have the same installation procedure
##
## installation tree:
##
## prefix/
## |
## |- include/oatpp-<version>/<module-name>
## - lib/
## |
## |- cmake/<module-name>-<version>/
## | |
## | |- <module-name>Config.cmake
## | - <module-name>ConfigVersion.cmake
## |
## - oatpp-<version>/
## |
## |- lib1.a
## |- lib2.a
## - ...
##
######################################################################################
message("\n############################################################################")
message("## oatpp-module-install.cmake\n")
message("OATPP_THIS_MODULE_NAME=${OATPP_THIS_MODULE_NAME}")
message("OATPP_THIS_MODULE_VERSION=${OATPP_THIS_MODULE_VERSION}")
message("OATPP_THIS_MODULE_LIBRARIES=${OATPP_THIS_MODULE_LIBRARIES}")
message("OATPP_THIS_MODULE_TARGETS=${OATPP_THIS_MODULE_TARGETS}")
message("OATPP_THIS_MODULE_DIRECTORIES=${OATPP_THIS_MODULE_DIRECTORIES}")
message("\n############################################################################\n")
#######################################################################################
## Set cache variables to configure module-config.cmake.in template
## via call to configure_package_config_file
include(GNUInstallDirs)
set(OATPP_MODULE_NAME ${OATPP_THIS_MODULE_NAME} CACHE STRING "oatpp module name")
set(OATPP_MODULE_VERSION "${OATPP_THIS_MODULE_VERSION}" CACHE STRING "oatpp module version")
set(OATPP_MODULE_LIBRARIES
"${OATPP_THIS_MODULE_LIBRARIES}" ## list libraries to find when find_package is called
CACHE INTERNAL "oatpp module libraries"
)
set(OATPP_MODULE_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "lib folder name")
#######################################################################################
## calc directories to install (relative to this script)
## dirs should be in ( relative ../src/<dirs>)
foreach(CURR_DIR ${OATPP_THIS_MODULE_DIRECTORIES})
list(APPEND OATPP_DIRS_TO_INSTALL ${CMAKE_CURRENT_LIST_DIR}/../src/${CURR_DIR})
endforeach()
#######################################################################################
install(TARGETS ${OATPP_THIS_MODULE_TARGETS}
EXPORT "${OATPP_MODULE_NAME}Targets"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/oatpp-${OATPP_MODULE_VERSION}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/oatpp-${OATPP_MODULE_VERSION}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/oatpp-${OATPP_MODULE_VERSION}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/oatpp-${OATPP_MODULE_VERSION}/${OATPP_MODULE_NAME}"
)
install(DIRECTORY ${OATPP_DIRS_TO_INSTALL}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/oatpp-${OATPP_MODULE_VERSION}/${OATPP_MODULE_NAME}"
FILES_MATCHING PATTERN "*.hpp"
)
install(EXPORT "${OATPP_MODULE_NAME}Targets"
FILE "${OATPP_MODULE_NAME}Targets.cmake"
NAMESPACE oatpp::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}"
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${OATPP_MODULE_NAME}ConfigVersion.cmake"
VERSION ${OATPP_MODULE_VERSION}
COMPATIBILITY ExactVersion ## Use exact version matching.
)
## Take module-config.cmake.in file in this direcory as a template
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/module-config.cmake.in"
"${OATPP_MODULE_NAME}Config.cmake"
INSTALL_DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}"
PATH_VARS
OATPP_MODULE_NAME
OATPP_MODULE_VERSION
OATPP_MODULE_LIBRARIES
OATPP_MODULE_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${OATPP_MODULE_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${OATPP_MODULE_NAME}ConfigVersion.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}"
)

25
cmake/module-utils.cmake Normal file
View File

@ -0,0 +1,25 @@
macro(target_link_oatpp target)
if(TARGET oatpp::oatpp) ## OATPP_MODULES_LOCATION == INSTALLED
message("target_link_oatpp(${target}) to installed oatpp lib")
target_link_libraries(${target}
PRIVATE oatpp::oatpp
PRIVATE oatpp::oatpp-test
)
else()
message("target_link_oatpp(${target}) to found in provided path oatpp lib")
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${OATPP_DIR_SRC}>)
#target_link_directories(${target} PRIVATE ${OATPP_DIR_LIB})
target_link_libraries(${target}
PRIVATE oatpp
PRIVATE oatpp-test
)
endif()
endmacro()

30
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,30 @@
add_library(${OATPP_THIS_MODULE_NAME}
oatpp-postgresql/Executor.cpp
oatpp-postgresql/Executor.hpp
)
set_target_properties(${OATPP_THIS_MODULE_NAME} PROPERTIES
CXX_STANDARD 11
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL)
add_dependencies(${OATPP_THIS_MODULE_NAME} ${LIB_OATPP_EXTERNAL})
endif()
target_link_oatpp(${OATPP_THIS_MODULE_NAME})
target_include_directories(${OATPP_THIS_MODULE_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
## TODO link dependencies here (if some)
#######################################################################################################
## install targets
if(OATPP_INSTALL)
include("../cmake/module-install.cmake")
endif()

View File

@ -0,0 +1,149 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "Executor.hpp"
#include "oatpp/core/parser/ParsingError.hpp"
namespace oatpp { namespace postgresql {
data::share::StringTemplate::Variable Executor::parseIdentifier(parser::Caret& caret) {
StringTemplate::Variable result;
result.posStart = caret.getPosition();
if(caret.canContinueAtChar(':', 1)) {
auto label = caret.putLabel();
while(caret.canContinue()) {
v_char8 a = *caret.getCurrData();
bool isAllowedChar = (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9') || (a == '_');
if(!isAllowedChar) {
result.posEnd = caret.getPosition() - 1;
result.name = label.toString();
return result;
}
caret.inc();
}
result.name = label.toString();
} else {
caret.setError("Invalid identifier");
}
result.posEnd = caret.getPosition() - 1;
return result;
}
void Executor::skipStringInQuotes(parser::Caret& caret) {
bool opened = false;
while(caret.canContinueAtChar('\'', 1)) {
opened = true;
if(caret.findChar('\'')) {
caret.inc();
opened = false;
}
}
if(opened) {
caret.setError("Invalid quote-enclosed string");
}
}
void Executor::skipStringInDollars(parser::Caret& caret) {
if(caret.canContinueAtChar('$', 1)) {
auto label = caret.putLabel();
if(!caret.findChar('$')) {
caret.setError("Invalid dollar-enclosed string");
return;
}
caret.inc();
auto term = label.toString(false);
while(caret.canContinue()) {
if(caret.findChar('$')) {
caret.inc();
if(caret.isAtText(term->getData(), term->getSize(), true)) {
return;
}
}
}
}
caret.setError("Invalid dollar-enclosed string");
}
data::share::StringTemplate Executor::parseQueryTemplate(const oatpp::String& text) {
std::vector<StringTemplate::Variable> variables;
parser::Caret caret(text);
while(caret.canContinue()) {
v_char8 c = *caret.getCurrData();
switch(c) {
case ':': {
auto var = parseIdentifier(caret);
if(var.name) {
variables.push_back(var);
}
}
break;
case '\'': skipStringInQuotes(caret); break;
case '$': skipStringInDollars(caret); break;
default:
caret.inc();
}
}
if(caret.hasError()) {
throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition());
}
return StringTemplate(text, std::move(variables));
}
db::QueryResult Executor::execute(const StringTemplate& queryTemplate, const std::unordered_map<oatpp::String, oatpp::Any>& params) {
std::unordered_map<oatpp::String, oatpp::String> map;
for(auto p : params) {
map[p.first] = "<" + p.first + ">";
}
auto res = queryTemplate.format(map);
OATPP_LOGD("AAA", "query={%s}", res->c_str());
return db::QueryResult();
}
}}

View File

@ -0,0 +1,48 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_postgresql_Executor_hpp
#define oatpp_postgresql_Executor_hpp
#include "oatpp/db/Executor.hpp"
#include "oatpp/core/parser/Caret.hpp"
namespace oatpp { namespace postgresql {
class Executor : public db::Executor {
private:
static StringTemplate::Variable parseIdentifier(parser::Caret& caret);
static void skipStringInQuotes(parser::Caret& caret);
static void skipStringInDollars(parser::Caret& caret);
public:
StringTemplate parseQueryTemplate(const oatpp::String& text) override;
db::QueryResult execute(const StringTemplate& queryTemplate, const std::unordered_map<oatpp::String, oatpp::Any>& params) override;
};
}}
#endif // oatpp_postgresql_Executor_hpp

29
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,29 @@
add_executable(module-tests
oatpp-postgresql/tests.cpp
)
set_target_properties(module-tests PROPERTIES
CXX_STANDARD 11
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
target_include_directories(module-tests
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)
if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL)
add_dependencies(module-tests ${LIB_OATPP_EXTERNAL})
endif()
add_dependencies(module-tests ${OATPP_THIS_MODULE_NAME})
target_link_oatpp(module-tests)
target_link_libraries(module-tests
PRIVATE ${OATPP_THIS_MODULE_NAME}
)
## TODO link dependencies here (if some)
add_test(module-tests module-tests)

View File

@ -0,0 +1,72 @@
#include "oatpp-postgresql/Executor.hpp"
#include "oatpp-test/UnitTest.hpp"
#include "oatpp/core/concurrency/SpinLock.hpp"
#include "oatpp/core/base/Environment.hpp"
#include <iostream>
#include "oatpp/db/Client.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace {
#include OATPP_CODEGEN_BEGIN(DbClient)
class DbClient : public oatpp::db::Client {
public:
DbClient(const std::shared_ptr<oatpp::db::Executor>& executor)
: oatpp::db::Client(executor)
{}
QUERY(getUserById, "SELECT * FROM user WHERE tag=$<text>$a$<text>$ AND userId=:userId AND role=:role",
PARAM(oatpp::String, userId),
PARAM(oatpp::String, role))
};
#include OATPP_CODEGEN_END(DbClient)
class Test : public oatpp::test::UnitTest {
public:
Test() : oatpp::test::UnitTest("MyTag")
{}
void onRun() override {
auto executor = std::make_shared<oatpp::postgresql::Executor>();
auto client = DbClient(executor);
client.getUserById("1", "2");
}
};
void runTests() {
OATPP_RUN_TEST(Test);
}
}
int main() {
oatpp::base::Environment::init();
runTests();
/* Print how much objects were created during app running, and what have left-probably leaked */
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
std::cout << "\nEnvironment:\n";
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";
OATPP_ASSERT(oatpp::base::Environment::getObjectsCount() == 0);
oatpp::base::Environment::destroy();
return 0;
}

View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "steps to install some my dependency"

21
utility/module-uninstall.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
MODULE_NAME="oatpp-postgresql"
MODULE_VERSION="0.19.1"
echo "remove include folder: '/usr/local/include/oatpp-$MODULE_VERSION/$MODULE_NAME'"
rm -rf "/usr/local/include/oatpp-$MODULE_VERSION/$MODULE_NAME"
echo "remove cmake package: '/usr/local/lib/cmake/$MODULE_NAME-$MODULE_VERSION'"
rm -rf "/usr/local/lib/cmake/$MODULE_NAME-$MODULE_VERSION"
MODULE_LIB_PATH="/usr/local/lib/oatpp-$MODULE_VERSION"
echo "remove '$MODULE_LIB_PATH/lib$MODULE_NAME.dylib'"
rm "$MODULE_LIB_PATH/lib$MODULE_NAME.dylib"
echo "remove '$MODULE_LIB_PATH/lib$MODULE_NAME.so'"
rm "$MODULE_LIB_PATH/lib$MODULE_NAME.so"
echo "remove '$MODULE_LIB_PATH/lib$MODULE_NAME.a'"
rm "$MODULE_LIB_PATH/lib$MODULE_NAME.a"