# crud **Repository Path**: onetech-cloud/crud ## Basic Information - **Project Name**: crud - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-27 - **Last Updated**: 2024-12-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **Requirements** - C++ compiler with at least C++11 support. - Asio development headers (1.10.9 or later). # 1、升级g++到11 ```sh sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt install g++-11 -y sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 60 sudo update-alternatives --config g++ g++ --version ``` # 2、安装依赖库 ```sh sudo apt install libasio-dev -y dpkg -l | grep libasio sudo apt-get install libc6-dev -y sudo apt-get install libsqlite3-dev -y ``` # 3、编译Crow ```sh git clone https://github.com/CrowCpp/Crow.git cd Crow mkdir build && cd build cmake .. -DCROW_BUILD_EXAMPLES=OFF -DCROW_BUILD_TESTS=OFF make install ``` # 4、编译nlohmann/json ```sh git clone https://github.com/nlohmann/json.git cd json mkdir build && cd build cmake .. sudo make install ``` # 5、进入程序路径,编译crud程序 ```sh cd crud mkdir build && cd build cmake .. make ./crud ``` # 6、执行程序 ```sh ./bin/crud ``` # 7、调用接口 ```sh curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","age":30}' http://localhost:18080/user curl -X GET -H "Content-Type: application/json" http://localhost:18080/user/1 curl -X PUT -H "Content-Type: application/json" -d '{"name":"John Doe","age":29,"id":1}' http://localhost:18080/user curl -X DELETE -H "Content-Type: application/json" http://localhost:18080/user/1 ``` gflags编译 https://gflags.github.io/gflags/ git clone https://github.com/gflags/gflags.git cd gflags mkdir build cd build cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON .. make sudo make install CMake Option Description CMAKE_INSTALL_PREFIX Installation directory, e.g., "/usr/local" on Unix and "C:\Program Files\gflags" on Windows. BUILD_SHARED_LIBS Request build of dynamic link libraries. BUILD_STATIC_LIBS Request build of static link libraries. Implied if BUILD_SHARED_LIBS is OFF. BUILD_PACKAGING Enable binary package generation using CPack. BUILD_TESTING Build tests for execution by CTest. BUILD_NC_TESTS Request inclusion of negative compilation tests (requires Python). BUILD_CONFIG_TESTS Request inclusion of package configuration tests (requires Python). BUILD_gflags_LIBS Request build of multi-threaded gflags libraries (if threading library found). BUILD_gflags_nothreads_LIBS Request build of single-threaded gflags libraries. GFLAGS_NAMESPACE Name of the C++ namespace to be used by the gflags library. Note that the public source header files are installed in a subdirectory named after this namespace. To maintain backwards compatibility with the Google Commandline Flags, set this variable to "google". The default is "gflags". GFLAGS_INTTYPES_FORMAT String identifying format of built-in integer types. GFLAGS_INCLUDE_DIR Name of headers installation directory relative to CMAKE_INSTALL_PREFIX. LIBRARY_INSTALL_DIR Name of library installation directory relative to CMAKE_INSTALL_PREFIX. INSTALL_HEADERS Request installation of public header files. gflags参数类型 DEFINE_bool: boolean DEFINE_int32: 32-bit integer DEFINE_int64: 64-bit integer DEFINE_uint64: unsigned 64-bit integer DEFINE_double: double DEFINE_string: C++ string ./crud --http_host=0.0.0.0 --http_port=8080 --database=ttt --table=aaa --max_connection_pool_size=1 --connection_max_lifetime_seconds=4 TODO glog编译 https://google.github.io/glog/ git clone https://github.com/google/glog.git cd glog cmake -S . -B build -G "Unix Makefiles" cmake --build build cmake --build build --target install # 或者使用系统包管理 sudo apt install libgoogle-glog-dev dpkg -l | grep libgoogle-glog-dev TODO 引入FakerCpp进行数据生成 https://github.com/marak/FakerCpp.git git clone https://github.com/marak/FakerCpp.git TODO 引入单元测试 https://github.com/google/googletest.git