Skip to content

Commit fc30ca2

Browse files
committed
feat: implement static checks for Ids in get*, remove operations
Added static_assert in get, get_pointer, get_optional and remove to produce a clear compile-time error when non-bindable types (e.g. where()) are passed as Ids, instead of a runtime crash. Changes are applied in dev/storage.h; include/sqlite_orm/sqlite_orm.h is the regenerated amalgamation.
1 parent 237b8e0 commit fc30ca2

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

dev/storage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ namespace sqlite_orm::internal {
392392
*/
393393
template<class O, class... Ids>
394394
void remove(Ids... ids) {
395+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
395396
this->assert_mapped_type<O>();
396397
auto statement = this->prepare(sqlite_orm::remove<O>(std::forward<Ids>(ids)...));
397398
this->execute(statement);
@@ -535,6 +536,7 @@ namespace sqlite_orm::internal {
535536
*/
536537
template<class O, class... Ids>
537538
O get(Ids... ids) {
539+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
538540
this->assert_mapped_type<O>();
539541
this->assert_primary_key_type<O>();
540542
auto statement = this->prepare(sqlite_orm::get<O>(std::forward<Ids>(ids)...));
@@ -554,6 +556,7 @@ namespace sqlite_orm::internal {
554556
*/
555557
template<class O, class... Ids>
556558
std::unique_ptr<O> get_pointer(Ids... ids) {
559+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
557560
this->assert_mapped_type<O>();
558561
this->assert_primary_key_type<O>();
559562
auto statement = this->prepare(sqlite_orm::get_pointer<O>(std::forward<Ids>(ids)...));
@@ -592,6 +595,7 @@ namespace sqlite_orm::internal {
592595
*/
593596
template<class O, class... Ids>
594597
std::optional<O> get_optional(Ids... ids) {
598+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
595599
this->assert_mapped_type<O>();
596600
this->assert_primary_key_type<O>();
597601
auto statement = this->prepare(sqlite_orm::get_optional<O>(std::forward<Ids>(ids)...));

include/sqlite_orm/sqlite_orm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25388,6 +25388,7 @@ namespace sqlite_orm::internal {
2538825388
*/
2538925389
template<class O, class... Ids>
2539025390
void remove(Ids... ids) {
25391+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
2539125392
this->assert_mapped_type<O>();
2539225393
auto statement = this->prepare(sqlite_orm::remove<O>(std::forward<Ids>(ids)...));
2539325394
this->execute(statement);
@@ -25531,6 +25532,7 @@ namespace sqlite_orm::internal {
2553125532
*/
2553225533
template<class O, class... Ids>
2553325534
O get(Ids... ids) {
25535+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
2553425536
this->assert_mapped_type<O>();
2553525537
this->assert_primary_key_type<O>();
2553625538
auto statement = this->prepare(sqlite_orm::get<O>(std::forward<Ids>(ids)...));
@@ -25550,6 +25552,7 @@ namespace sqlite_orm::internal {
2555025552
*/
2555125553
template<class O, class... Ids>
2555225554
std::unique_ptr<O> get_pointer(Ids... ids) {
25555+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
2555325556
this->assert_mapped_type<O>();
2555425557
this->assert_primary_key_type<O>();
2555525558
auto statement = this->prepare(sqlite_orm::get_pointer<O>(std::forward<Ids>(ids)...));
@@ -25588,6 +25591,7 @@ namespace sqlite_orm::internal {
2558825591
*/
2558925592
template<class O, class... Ids>
2559025593
std::optional<O> get_optional(Ids... ids) {
25594+
static_assert((internal::is_bindable_v<Ids> && ...), "Only primary key values are accepted as Ids");
2559125595
this->assert_mapped_type<O>();
2559225596
this->assert_primary_key_type<O>();
2559325597
auto statement = this->prepare(sqlite_orm::get_optional<O>(std::forward<Ids>(ids)...));

0 commit comments

Comments
 (0)