qicosmos / ormpp

modern C++ ORM, C++17, support mysql, postgresql,sqlite
Apache License 2.0
1.2k stars 260 forks source link

add REGISTER_AUTO_KEY #129

Closed Jacyking closed 7 months ago

Jacyking commented 7 months ago
struct person {
  std::optional<std::string> name;
  std::optional<int> age;
  int id;
};
REGISTER_AUTO_KEY(person, id)
REFLECTION(person, id, name, age)

REGISTER_AUTO_KEY(person, id) used to set which field is the auto increment key;

for PG:

struct student {
  int code;
  std::string name;
  char sex;
  int age;
  double dm;
  std::string classroom;
};
#ifdef ORMPP_ENABLE_PG
REGISTER_CONFLICT_KEY(student, code)
#endif
REFLECTION(student, code, name, sex, age, dm, classroom)

REGISTER_CONFLICT_KEY(student, code) only for PG: insert with update, more details: https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-upsert/

codecov-commenter commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (cf53076) 39.88% compared to head (47cedd8) 40.00%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #129 +/- ## ========================================== + Coverage 39.88% 40.00% +0.12% ========================================== Files 22 22 Lines 2856 2867 +11 ========================================== + Hits 1139 1147 +8 - Misses 1717 1720 +3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

qicosmos commented 7 months ago

REGISTER_CONFLICT_KEY 这个是PG里面专有的吗,我还不知道这个干啥的,为啥要加这个,在pr描述里加一段文字介绍吧,

Jacyking commented 7 months ago

REGISTER_CONFLICT_KEY 这个是PG里面专有的吗,我还不知道这个干啥的,为啥要加这个,在pr描述里加一段文字介绍吧,

[ WITH [ RECURSIVE ] with_query [, ...] ] INSERT INTO table_name [ ( column_name [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query } [ ON CONFLICT [ ( { column_name_index | ( expression_index ) } [ COLLATE collation ] [ opclass ] [, ...] [ WHERE index_predicate ] ) ] { IGNORE | UPDATE SET { column_name = { expression | DEFAULT } | ( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...] [ WHERE condition ] } ] [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

https://wiki.postgresql.org/wiki/UPSERT#SQLite:_..._ONCONFLICT..._.2FINSERT.2FUPDATE...OR...