4#include "Stroika/Frameworks/StroikaPreComp.h"
11#include "Stroika/Foundation/Common/GUID.h"
12#include "Stroika/Foundation/Containers/Set.h"
13#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
22#include "ComputerNetwork.h"
29using namespace Stroika::Foundation::Database;
30using namespace Stroika::Foundation::Database::SQL;
33using namespace Stroika::Foundation::Time;
37using SQL::ORM::Schema::StandardSQLStatements;
53 nonvirtual
bool operator== (
const Device& rhs)
const =
default;
71 {
"id"sv, &Device::id},
72 {
"name"sv, &Device::name},
73 {
"openPorts"sv, &Device::openPorts},
74 {
"hardwareAddresses"sv, &Device::hardwareAddresses},
83 const SQL::ORM::Schema::Table kDeviceTableSchema_{
93 {.fName =
"ID"sv, .fVariantValueName =
"id"sv, .fRequired =
true, .fVariantValueType = VariantValue::eBLOB, .fIsKeyField =
true, .fDefaultExpression =
"randomblob(16)"sv},
94 {.fName =
"name"sv, .fRequired =
true, .fVariantValueType = VariantValue::eString}},
95 SQL::ORM::Schema::CatchAllField{}};
98void Stroika::Samples::SQL::ComputerNetworksModel (
const std::function<
Connection::Ptr ()>& connectionFactory)
108 auto addDevice = [&] (
const Device& d) {
109 Statement addDeviceStatement = conn.
mkStatement (StandardSQLStatements{kDeviceTableSchema_}.Insert ());
113 Statement getAllDevicesStatement = conn.
mkStatement (StandardSQLStatements{kDeviceTableSchema_}.GetAllElements ());
117 auto removeDevice = [&] (
const GUID& id) {
118 Statement deleteDeviceStatement = conn.
mkStatement (StandardSQLStatements{kDeviceTableSchema_}.DeleteByID ());
125 if (not getAllDevices ().empty ()) {
128 addDevice (kDevice1_);
129 addDevice (kDevice2_);
131 auto devices = getAllDevices ();
132 if (devices.size () != 2) {
135 if (not devices.Contains (kDevice1_)) {
138 if (not devices.Contains (kDevice2_)) {
142 removeDevice (kDevice2_.id);
144 auto devices = getAllDevices ();
145 if (devices.size () != 1) {
148 if (not devices.Contains (kDevice1_)) {
String is like std::u32string, except it is much easier to use, often much more space efficient,...
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
nonvirtual void AddClass(const Traversal::Iterable< StructFieldInfo > &fieldDescriptions, const ClassMapperOptions< CLASS > &mapperOptions={})
nonvirtual void AddCommonType(ARGS &&... args)
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual Statement mkStatement(const String &sql)
nonvirtual void Execute()
nonvirtual Sequence< Row > GetAllRows()
call Reset (), and then GetAllRemainingRows () - which always starts current statement with current b...
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
static GUID GenerateNew() noexcept