Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
build-and-unit-test:
runs-on: ubuntu-24.04

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: false

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
ccache \
cmake \
g++ \
libboost-all-dev \
libpq-dev \
ninja-build

- name: Configure OZO
run: >
cmake -S . -B build -G Ninja
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DOZO_BUILD_TESTS=ON
-DOZO_BUILD_EXAMPLES=ON

- name: Build OZO tests and examples
run: >
cmake --build build
--target
ozo_tests
ozo_request
ozo_transaction
ozo_retry_request
ozo_role_based_request
ozo_connection_pool

- name: Run OZO unit tests
run: ctest --test-dir build --output-on-failure -R ozo_tests

- name: Configure vendored resource_pool tests
run: >
cmake -S contrib/resource_pool -B build-resource-pool -G Ninja
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DRESOURCE_POOL_BUILD_TESTS=ON

- name: Build vendored resource_pool tests
run: cmake --build build-resource-pool --target resource_pool_test

- name: Run vendored resource_pool tests
run: ctest --test-dir build-resource-pool --output-on-failure -R resource_pool_test

postgres-integration-test:
runs-on: ubuntu-24.04

services:
postgres:
image: postgres:16
env:
POSTGRES_DB: ozo_test_db
POSTGRES_USER: ozo_test_user
POSTGRES_PASSWORD: v4Xpkocl~5l6h219Ynk1lJbM61jIr!ca
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U ozo_test_user -d ozo_test_db"
--health-interval 10s
--health-timeout 5s
--health-retries 12

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: false

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
cmake \
g++ \
libboost-all-dev \
libpq-dev \
ninja-build \
postgresql-client

- name: Wait for PostgreSQL
env:
PGPASSWORD: v4Xpkocl~5l6h219Ynk1lJbM61jIr!ca
run: |
for _ in $(seq 1 30); do
if pg_isready -h 127.0.0.1 -p 5432 -U ozo_test_user -d ozo_test_db; then
exit 0
fi
sleep 2
done
exit 1

- name: Configure PostgreSQL integration tests
env:
OZO_PG_TEST_CONNINFO: host=127.0.0.1 port=5432 dbname=ozo_test_db user=ozo_test_user password=v4Xpkocl~5l6h219Ynk1lJbM61jIr!ca
run: >
cmake -S . -B build-pg -G Ninja
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DOZO_BUILD_TESTS=ON
-DOZO_BUILD_PG_TESTS=ON
-DOZO_PG_TEST_CONNINFO="$OZO_PG_TEST_CONNINFO"

- name: Build PostgreSQL integration tests
run: cmake --build build-pg --target ozo_tests

- name: Run PostgreSQL integration tests
run: ctest --test-dir build-pg --output-on-failure -R ozo_tests
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
build

# Ignore clangd cache
.cache/
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/mo
# note: boost::coroutine should automatically pull in all the dependencies,
# however, due to changes in boost it doesn't always work until CMake
# is updated. we therefore look for all the dependencies ourselves.
find_package(Boost COMPONENTS coroutine context system thread atomic REQUIRED)
find_package(Boost 1.74 COMPONENTS coroutine context system thread atomic REQUIRED)
find_package(PostgreSQL REQUIRED)

# Try and find provided resource pool (e.g. from conan), default to vendored version otherwise
Expand All @@ -25,7 +25,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
add_library(ozo INTERFACE)
add_library(yandex::ozo ALIAS ozo)

target_compile_features(ozo INTERFACE cxx_std_17)
target_compile_features(ozo INTERFACE cxx_std_20)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
# disable warnings about a compiler-specific option used for gnu-compatible compilers
Expand All @@ -40,9 +40,6 @@ target_include_directories(ozo INTERFACE

target_compile_definitions(ozo INTERFACE -DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
target_compile_definitions(ozo INTERFACE -DBOOST_HANA_CONFIG_ENABLE_STRING_UDL)
# For the time OZO may not support Executor TS
# See https://github.com/yandex/ozo/issues/266
target_compile_definitions(ozo INTERFACE -DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)

target_link_libraries(ozo INTERFACE Boost::coroutine)
target_link_libraries(ozo INTERFACE PostgreSQL::PostgreSQL)
Expand Down
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ozo

[![Build Status](https://travis-ci.org/yandex/ozo.svg?branch=master)](https://travis-ci.org/yandex/ozo)
[![CI](https://github.com/haomingbai/ozo/actions/workflows/ci.yml/badge.svg)](https://github.com/haomingbai/ozo/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/yandex/ozo/branch/master/graph/badge.svg)](https://codecov.io/gh/yandex/ozo)

## What's this

OZO is a C++17 library for asyncronous communication with PostgreSQL DBMS.
OZO is a C++20 library for asyncronous communication with PostgreSQL DBMS.
The library leverages the power of template metaprogramming, providing convenient mapping from C++ types to SQL along with rich query building possibilities. OZO supports different concurrency paradigms (callbacks, futures, coroutines), using Boost.Asio under the hood. Low-level communication with PostgreSQL server is done via libpq. All concepts in the library are designed to be easily extendable (even replaceable) by the user to simplify adaptation to specific project requirements.

### API
Expand All @@ -19,20 +19,22 @@ Since the project is on early state of development it lacks of documentation. We

## Compatibilities

For the time OZO is not compatible with new executors models that are used by default since Boost 1.74. The `BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT` macro needs to be defined. See Boost 1.74 [changelog](https://www.boost.org/doc/libs/1_74_0/doc/html/boost_asio/history.html#boost_asio.history.asio_1_18_0___boost_1_74) for the details.
OZO now targets the default executor model used by modern Boost.Asio releases.
`BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT` is no longer required and is no longer
exported to consumers.
## Dependencies

These things are needed:

* **CMake** is used as build system
* **GCC** or **Clang** C++ compiler with C++17 support (tested with GCC 7.0, Clang 5.0 and Apple LLVM version 9.0.0)
* **Boost** >= 1.66 with `BOOST_HANA_CONFIG_ENABLE_STRING_UDL` defined.
* **Boost** >= 1.74 with `BOOST_HANA_CONFIG_ENABLE_STRING_UDL` defined.
* **libpq** >= 9.3
* Ozo uses the [resource_pool](https://github.com/elsid/resource_pool) library as a git submodule, so in case of using a package version, this dependency should be satisfied too.
* OZO vendors the [resource_pool](https://github.com/elsid/resource_pool) sources directly under `contrib/resource_pool`.

If you want to run integration tests and/or build inside Docker container:
* **Docker** >= 1.13.0
* **Docker Compose** >= 1.10.0
If you want to run PostgreSQL integration tests locally:
* **Podman**
* a local copy of `docker.io/library/postgres:16` or another PostgreSQL image

## Build

Expand Down Expand Up @@ -118,24 +120,39 @@ scripts/build.sh docker docs

### Test against a local postgres

You can use `scripts/build.sh` but add `pg` first:
The recommended path is the Podman helper script:

```bash
scripts/build.sh pg <compiler> <target>
scripts/run_pg_tests_podman.sh
```

or if you want build code in docker:
The script starts a local PostgreSQL container from `docker.io/library/postgres:16`
by default, builds `ozo_tests` with `OZO_BUILD_PG_TESTS=ON`, runs the full test
suite, and removes the container afterwards.

You can override the image, port, build directory, and PostgreSQL credentials
with environment variables:

```bash
scripts/build.sh pg docker <compiler> <target>
export OZO_PODMAN_POSTGRES_IMAGE=docker.io/library/postgres:16
export OZO_PG_TEST_PORT=55432
export OZO_PG_BUILD_DIR=build-podman-pg

scripts/run_pg_tests_podman.sh
```

This will attempt to launch postgres:alpine from your Docker registry.
Or you can point ozo tests to a postgres of your choosing by setting these environment variables prior to building:
Or you can point OZO tests to a PostgreSQL instance of your choosing by setting
these environment variables prior to building:

```bash
export OZO_BUILD_PG_TESTS=ON
export OZO_PG_TEST_CONNINFO='your conninfo (connection string)'

scripts/build.sh gcc debug
cmake -S . -B build-pg -DOZO_BUILD_TESTS=ON -DOZO_BUILD_PG_TESTS=ON -DOZO_PG_TEST_CONNINFO="$OZO_PG_TEST_CONNINFO"
cmake --build build-pg -j$(nproc)
ctest --test-dir build-pg -V
```

The older `docker-compose` based scripts remain in the repository for historical
development workflows, but the maintained path for local PostgreSQL testing is
the Podman flow above.
2 changes: 1 addition & 1 deletion benchmarks/ozo_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <ozo/query_builder.h>
#include <ozo/request.h>

#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>

#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <nlohmann/json.hpp>

#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/program_options.hpp>

Expand Down
10 changes: 7 additions & 3 deletions cmake/modules/FindPostgreSQL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ endif()
# Did we find anything?
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PostgreSQL
REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR
REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR
VERSION_VAR PostgreSQL_VERSION_STRING)
set(PostgreSQL_FOUND ${POSTGRESQL_FOUND})

Expand All @@ -247,15 +247,19 @@ endfunction()

# Now try to get the include and library path.
if(PostgreSQL_FOUND)
set(PostgreSQL_INCLUDE_DIRS "${PostgreSQL_INCLUDE_DIR}")
if(PostgreSQL_TYPE_INCLUDE_DIR)
list(APPEND PostgreSQL_INCLUDE_DIRS "${PostgreSQL_TYPE_INCLUDE_DIR}")
endif()

if (NOT TARGET PostgreSQL::PostgreSQL)
add_library(PostgreSQL::PostgreSQL UNKNOWN IMPORTED)
set_target_properties(PostgreSQL::PostgreSQL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIR};${PostgreSQL_TYPE_INCLUDE_DIR}")
INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIRS}")
__postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "")
__postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "RELEASE")
__postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "DEBUG")
endif ()
set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
endif()

Expand Down
3 changes: 1 addition & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def package_info(self):
]
self.cpp_info.components["_ozo"].defines = [
"BOOST_COROUTINES_NO_DEPRECATION_WARNING",
"BOOST_HANA_CONFIG_ENABLE_STRING_UDL",
"BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT"
"BOOST_HANA_CONFIG_ENABLE_STRING_UDL"
]

compiler = self.settings.compiler
Expand Down
1 change: 0 additions & 1 deletion contrib/resource_pool
Submodule resource_pool deleted from 3ea1f9
Loading