ulib/3party/sqlpp11/docs/New-Features.md
tqcq 99c258107b
All checks were successful
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m24s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m30s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m43s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m47s
linux-x64-gcc / linux-gcc (push) Successful in 2m11s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 3m19s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 3m39s
feat/support_orm (#2)
Co-authored-by: tqcq <99722391+tqcq@users.noreply.github.com>
Reviewed-on: #2
2024-01-06 13:56:45 +00:00

59 lines
1.9 KiB
Markdown

# New Features
There are a bunch of new features, that are not fully documented yet. If you would like to contribute documentation, please let me know.
## Preprocessor generator for columns/tables
You'll need boost 1.50 or greater to use this feature by niXman:
```C++
#include <sqlpp11/ppgen.h>
SQLPP_DECLARE_TABLE(
(tab_person)
,
(id , int , SQLPP_AUTO_INCREMENT)
(name , varchar(255), SQLPP_NOT_NULL )
(feature, int , SQLPP_NOT_NULL )
)
```
See `examples/ppgen.hpp`.
## Union
Unions are now supported. The arguments need to have the same names and types in their columns.
```C++
db(select(t.alpha).from(t).where(true)
.union_distinct(select(f.epsilon.as(t.alpha)).from(f).where(true)));
db(select(t.alpha).from(t).where(true)
.union_all(select(f.epsilon.as(t.alpha)).from(f).where(true)));
```
## With
sqlpp11 supports common table expressions:
```C++
auto x = sqlpp::cte(sqlpp::alias::x).as(select(all_of(t)).from(t));
db(with(x)(select(x.alpha).from(x).where(true)));
```
## Custom Queries
This allows you to combine building blocks of sqlpp11 into custom queries, for instance a SELECT..INTO which is not supported yet.
```C++
// A custom (select ... into) with adjusted return type
// The first argument with a return type is the select,
// but the custom query is really an insert. Thus, we tell it so.
db(custom_query(select(all_of(t)).from(t), into(f))
.with_result_type_of(insert_into(f)));
```
## Schema-qualified tables
sqlpp11 assumes that you're connection addresses one database, normally. But you can tell it about other databases using the `sqlpp::schema_t` and instantiating schema-qualified tables with it:
```C++
auto schema = db.attach("lorem_ipsum");
auto s = schema_qualified_table(schema, TabSample{}).as(sqlpp::alias::x)
// s now represents "lorem_ipsum.tab_sample as x"
// s can be used like any other table in the code
```