|
| 1 | +# fb-cpp |
| 2 | + |
| 3 | +A modern C++ wrapper for the Firebird database API. |
| 4 | + |
| 5 | +[Documentation](https://asfernandes.github.io/fb-cpp) |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +`fb-cpp` provides a clean, modern C++ interface to the Firebird database engine. |
| 10 | +It wraps the Firebird C++ API with RAII principles, smart pointers, and modern C++ features. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- **Modern C++**: Uses C++20 features for type safety and performance |
| 15 | +- **RAII**: Automatic resource management with smart pointers |
| 16 | +- **Type Safety**: Strong typing for database operations |
| 17 | +- **Exception Safety**: Proper error handling with exceptions |
| 18 | +- **Boost Integration**: Optional Boost.DLL for loading fbclient and Boost.Multiprecision support for large numbers |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +```cpp |
| 23 | +#include "fb-cpp/fb-cpp.h" |
| 24 | + |
| 25 | +using namespace fbcpp; |
| 26 | + |
| 27 | +// Create a client |
| 28 | +Client client{"fbclient"}; |
| 29 | + |
| 30 | +// Connect to a database |
| 31 | +const auto attachmentOptions = AttachmentOptions() |
| 32 | + .setConnectionCharSet("UTF8"); |
| 33 | +Attachment attachment{client, "localhost:database.fdb", attachmentOptions}; |
| 34 | + |
| 35 | +// Start a transaction |
| 36 | +const auto transactionOptions = TransactionOptions() |
| 37 | + .setIsolationLevel(TransactionIsolationLevel::READ_COMMITTED); |
| 38 | +Transaction transaction{attachment, transactionOptions}; |
| 39 | + |
| 40 | +// Prepare a statement |
| 41 | +Statement statement{attachment, transaction, "select id, name from users where id = ?"}; |
| 42 | + |
| 43 | +// Set parameters |
| 44 | +statement.setInt32(0, 42); |
| 45 | +/* Or |
| 46 | +statement.set(0, 42); |
| 47 | +*/ |
| 48 | + |
| 49 | +// Execute and get results |
| 50 | +statement.execute(transaction); |
| 51 | + |
| 52 | +// Process results... |
| 53 | +do |
| 54 | +{ |
| 55 | + const std::optional<std::int32_t> id = statement.getInt32(0); |
| 56 | + const std::optional<std::string> name = statement.getString(1); |
| 57 | + |
| 58 | + /* Or |
| 59 | + const auto id = statement.get<std::int32_t>(0); |
| 60 | + const auto name = statement.get<std::string>(1); |
| 61 | + */ |
| 62 | +} while (statement.fetchNext()); |
| 63 | + |
| 64 | +// Commit transaction |
| 65 | +transaction.commit(); |
| 66 | +``` |
| 67 | +
|
| 68 | +## Building |
| 69 | +
|
| 70 | +This project uses CMake with vcpkg for dependency management. |
| 71 | +
|
| 72 | +```bash |
| 73 | +# Clone the repository |
| 74 | +git clone --recursive-submodules https://github.com/asfernandes/fb-cpp.git |
| 75 | +
|
| 76 | +# Configure |
| 77 | +cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release |
| 78 | +
|
| 79 | +# Build |
| 80 | +cmake --build build/Release |
| 81 | +
|
| 82 | +# Install |
| 83 | +cmake --install build/Release |
| 84 | +
|
| 85 | +# Generate documentation |
| 86 | +cmake --build build/Release --target docs |
| 87 | +``` |
| 88 | + |
| 89 | +## Documentation |
| 90 | + |
| 91 | +The complete API documentation is available in the build `doc/docs/` directory after building with the `docs` target. |
| 92 | + |
| 93 | +## License |
| 94 | + |
| 95 | +MIT License - see LICENSE.md for details. |
0 commit comments