Skip to content

Commit 94fdff8

Browse files
authored
Update README.md
1 parent 774c35e commit 94fdff8

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
11
# oatpp-postgresql [![Build Status](https://dev.azure.com/lganzzzo/lganzzzo/_apis/build/status/oatpp.oatpp-postgresql?branchName=master)](https://dev.azure.com/lganzzzo/lganzzzo/_build/latest?definitionId=31&branchName=master)
22

3-
Oat++ ORM adapter for PostgreSQL
3+
Oat++ ORM adapter for PostgreSQL.
4+
*Note: this alpha version, which means that not all PostgreSQL data-types are supported.*
45

6+
More about Oat++:
7+
8+
- [Oat++ Website](https://oatpp.io/)
9+
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)
10+
- [Oat++ ORM](https://oatpp.io/docs/components/orm/)
11+
12+
## Build And Install
13+
14+
*Note: you need to install the main [oatpp](https://github.com/oatpp/oatpp) module and PostgreSQL dev package first.*
15+
16+
- Clone this repository.
17+
- In the root of the repository run:
18+
```bash
19+
mkdir build && cd build
20+
cmake ..
21+
make install
22+
```
23+
24+
## API
25+
26+
Detailed documentation on Oat++ ORM you can find [here](https://oatpp.io/docs/components/orm/).
27+
28+
### Connect to Database
29+
30+
All you need to start using oatpp ORM with PostgreSQL is to create `oatpp::postgresql::Executor` and provide it to your `DbClient`.
31+
32+
```cpp
33+
#include "db/MyClient.hpp"
34+
#include "oatpp-postgresql/orm.hpp"
35+
36+
class AppComponent {
37+
public:
38+
39+
/**
40+
* Create DbClient component.
41+
*/
42+
OATPP_CREATE_COMPONENT(std::shared_ptr<db::MyClient>, myDatabaseClient)([] {
43+
/* Create database-specific ConnectionProvider */
44+
auto connectionProvider = std::make_shared<oatpp::postgresql::ConnectionProvider>("<connection-string>");
45+
46+
/* Create database-specific ConnectionPool */
47+
auto connectionPool = oatpp::postgresql::ConnectionPool::createShared(connectionProvider,
48+
10 /* max-connections */,
49+
std::chrono::seconds(5) /* connection TTL */);
50+
51+
/* Create database-specific Executor */
52+
auto executor = std::make_shared<oatpp::postgresql::Executor>(connectionPool);
53+
54+
/* Create MyClient database client */
55+
return std::make_shared<MyClient>(executor);
56+
}());
57+
58+
};
59+
```

0 commit comments

Comments
 (0)