Skip to content

Commit 10a2dea

Browse files
committed
Implement IS NOT NULL operator and update related files
- Added `is_not_null_t` operator object in `ast/is_not_null.h`. - Updated `ast_iterator.h`, `column_result.h`, `conditions.h`, `node_tuple.h`, and `statement_serializer.h` to integrate the new operator. - Refactored existing code to use the new structure for serialization and argument handling.
1 parent e9afc5f commit 10a2dea

File tree

7 files changed

+96
-54
lines changed

7 files changed

+96
-54
lines changed

dev/ast/is_not_null.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#ifndef SQLITE_ORM_IMPORT_STD_MODULE
4+
#include <utility> // std::move
5+
#endif
6+
7+
#include "../tags.h"
8+
#include "../functional/config.h"
9+
10+
namespace sqlite_orm::internal {
11+
/**
12+
* IS NOT NULL operator object.
13+
*/
14+
template<class T>
15+
struct is_not_null_t : condition_t, negatable_t {
16+
using argument_type = T;
17+
using self = is_not_null_t<argument_type>;
18+
19+
argument_type argument;
20+
21+
is_not_null_t(argument_type argument_) : argument(std::move(argument_)) {}
22+
};
23+
}
24+
25+
SQLITE_ORM_EXPORT namespace sqlite_orm {
26+
27+
/**
28+
* IS NOT NULL operator.
29+
*/
30+
template<class T>
31+
internal::is_not_null_t<T> is_not_null(T t) {
32+
return {std::move(t)};
33+
}
34+
}

dev/ast_iterator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "ast/limit.h"
3030
#include "ast/in.h"
3131
#include "ast/between.h"
32+
#include "ast/is_null.h"
33+
#include "ast/is_not_null.h"
3234

3335
namespace sqlite_orm::internal {
3436
/**
@@ -530,8 +532,8 @@ namespace sqlite_orm::internal {
530532
using node_type = is_not_null_t<T>;
531533

532534
template<class L>
533-
SQLITE_ORM_STATIC_CALLOP void operator()(const node_type& i, L& lambda) SQLITE_ORM_OR_CONST_CALLOP {
534-
iterate_ast(i.t, lambda);
535+
SQLITE_ORM_STATIC_CALLOP void operator()(const node_type& node, L& lambda) SQLITE_ORM_OR_CONST_CALLOP {
536+
iterate_ast(node.argument, lambda);
535537
}
536538
};
537539

dev/column_result.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ast/in.h"
3131
#include "ast/between.h"
3232
#include "ast/is_null.h"
33+
#include "ast/is_not_null.h"
3334

3435
namespace sqlite_orm::internal {
3536
/**

dev/conditions.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -322,24 +322,6 @@ namespace sqlite_orm::internal {
322322
}
323323
};
324324

325-
struct is_not_null_string {
326-
operator std::string() const {
327-
return "IS NOT NULL";
328-
}
329-
};
330-
331-
/**
332-
* IS NOT NULL operator object.
333-
*/
334-
template<class T>
335-
struct is_not_null_t : condition_t, is_not_null_string, negatable_t {
336-
using self = is_not_null_t<T>;
337-
338-
T t;
339-
340-
is_not_null_t(T t_) : t(std::move(t_)) {}
341-
};
342-
343325
struct order_by_base {
344326
std::string _collate_argument;
345327
int _order = 0; // -1 = desc, 1 = asc, 0 = unspecified
@@ -934,11 +916,6 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
934916
get_from_expression(std::forward<R>(r))};
935917
}
936918

937-
template<class T>
938-
internal::is_not_null_t<T> is_not_null(T t) {
939-
return {std::move(t)};
940-
}
941-
942919
template<class L, class R>
943920
constexpr internal::is_equal_t<L, R> is_equal(L l, R r) {
944921
return {std::move(l), std::move(r)};

dev/node_tuple.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "ast/cast.h"
2828
#include "ast/limit.h"
2929
#include "ast/in.h"
30+
#include "ast/is_null.h"
31+
#include "ast/is_not_null.h"
3032

3133
namespace sqlite_orm::internal {
3234
template<class T, class SFINAE = void>

dev/statement_serializer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "ast/rank.h"
3434
#include "ast/special_keywords.h"
3535
#include "ast/limit.h"
36+
#include "ast/is_null.h"
37+
#include "ast/is_not_null.h"
3638
#include "core_functions.h"
3739
#include "constraints.h"
3840
#include "conditions.h"
@@ -803,10 +805,10 @@ namespace sqlite_orm::internal {
803805
using statement_type = is_not_null_t<T>;
804806

805807
template<class Ctx>
806-
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& c,
808+
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
807809
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
808810
std::stringstream ss;
809-
ss << serialize(c.t, context) << " " << static_cast<std::string>(c);
811+
ss << serialize(statement.argument, context) << " IS NOT NULL";
810812
return ss.str();
811813
}
812814
};

include/sqlite_orm/sqlite_orm.h

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5540,24 +5540,6 @@ namespace sqlite_orm::internal {
55405540
}
55415541
};
55425542

5543-
struct is_not_null_string {
5544-
operator std::string() const {
5545-
return "IS NOT NULL";
5546-
}
5547-
};
5548-
5549-
/**
5550-
* IS NOT NULL operator object.
5551-
*/
5552-
template<class T>
5553-
struct is_not_null_t : condition_t, is_not_null_string, negatable_t {
5554-
using self = is_not_null_t<T>;
5555-
5556-
T t;
5557-
5558-
is_not_null_t(T t_) : t(std::move(t_)) {}
5559-
};
5560-
55615543
struct order_by_base {
55625544
std::string _collate_argument;
55635545
int _order = 0; // -1 = desc, 1 = asc, 0 = unspecified
@@ -6152,11 +6134,6 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
61526134
get_from_expression(std::forward<R>(r))};
61536135
}
61546136

6155-
template<class T>
6156-
internal::is_not_null_t<T> is_not_null(T t) {
6157-
return {std::move(t)};
6158-
}
6159-
61606137
template<class L, class R>
61616138
constexpr internal::is_equal_t<L, R> is_equal(L l, R r) {
61626139
return {std::move(l), std::move(r)};
@@ -12106,6 +12083,41 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
1210612083
return {std::move(t)};
1210712084
}
1210812085
}
12086+
// #include "ast/is_not_null.h"
12087+
12088+
#ifndef SQLITE_ORM_IMPORT_STD_MODULE
12089+
#include <utility> // std::move
12090+
#endif
12091+
12092+
// #include "../tags.h"
12093+
12094+
// #include "../functional/config.h"
12095+
12096+
namespace sqlite_orm::internal {
12097+
/**
12098+
* IS NOT NULL operator object.
12099+
*/
12100+
template<class T>
12101+
struct is_not_null_t : condition_t, negatable_t {
12102+
using argument_type = T;
12103+
using self = is_not_null_t<argument_type>;
12104+
12105+
argument_type argument;
12106+
12107+
is_not_null_t(argument_type argument_) : argument(std::move(argument_)) {}
12108+
};
12109+
}
12110+
12111+
SQLITE_ORM_EXPORT namespace sqlite_orm {
12112+
12113+
/**
12114+
* IS NOT NULL operator.
12115+
*/
12116+
template<class T>
12117+
internal::is_not_null_t<T> is_not_null(T t) {
12118+
return {std::move(t)};
12119+
}
12120+
}
1210912121

1211012122
namespace sqlite_orm::internal {
1211112123
/**
@@ -16275,6 +16287,10 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
1627516287

1627616288
// #include "ast/between.h"
1627716289

16290+
// #include "ast/is_null.h"
16291+
16292+
// #include "ast/is_not_null.h"
16293+
1627816294
namespace sqlite_orm::internal {
1627916295
/**
1628016296
* ast_iterator accepts any expression and a callable object
@@ -16775,8 +16791,8 @@ namespace sqlite_orm::internal {
1677516791
using node_type = is_not_null_t<T>;
1677616792

1677716793
template<class L>
16778-
SQLITE_ORM_STATIC_CALLOP void operator()(const node_type& i, L& lambda) SQLITE_ORM_OR_CONST_CALLOP {
16779-
iterate_ast(i.t, lambda);
16794+
SQLITE_ORM_STATIC_CALLOP void operator()(const node_type& node, L& lambda) SQLITE_ORM_OR_CONST_CALLOP {
16795+
iterate_ast(node.argument, lambda);
1678016796
}
1678116797
};
1678216798

@@ -20100,6 +20116,10 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
2010020116

2010120117
// #include "ast/limit.h"
2010220118

20119+
// #include "ast/is_null.h"
20120+
20121+
// #include "ast/is_not_null.h"
20122+
2010320123
// #include "core_functions.h"
2010420124

2010520125
// #include "constraints.h"
@@ -21770,10 +21790,10 @@ namespace sqlite_orm::internal {
2177021790
using statement_type = is_not_null_t<T>;
2177121791

2177221792
template<class Ctx>
21773-
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& c,
21793+
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
2177421794
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
2177521795
std::stringstream ss;
21776-
ss << serialize(c.t, context) << " " << static_cast<std::string>(c);
21796+
ss << serialize(statement.argument, context) << " IS NOT NULL";
2177721797
return ss.str();
2177821798
}
2177921799
};
@@ -26266,6 +26286,10 @@ namespace sqlite_orm::internal {
2626626286

2626726287
// #include "ast/in.h"
2626826288

26289+
// #include "ast/is_null.h"
26290+
26291+
// #include "ast/is_not_null.h"
26292+
2626926293
namespace sqlite_orm::internal {
2627026294
template<class T, class SFINAE = void>
2627126295
struct node_tuple {

0 commit comments

Comments
 (0)