Lightweight 0.20260213.0
Loading...
Searching...
No Matches
Entities.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "../Utils.hpp"
6
7#include <Lightweight/Lightweight.hpp>
8
9#include <ostream>
10
11/// @file Entities.hpp
12/// @brief Entity definitions for the large test database schema.
13///
14/// This file contains all entity structs for a complex 500MB+ test database
15/// that works across all supported backends (SQLite3, PostgreSQL, MS-SQL Server).
16
17// Forward declarations
18struct LargeDb_User;
19struct LargeDb_Category;
20struct LargeDb_Product;
22struct LargeDb_Order;
24struct LargeDb_Review;
25struct LargeDb_Tag;
29struct LargeDb_Article;
30
31/// @brief User entity with large bio and avatar fields.
32/// Estimated: 2,000 rows × 11KB = 22MB
48
49/// @brief Category entity.
50/// Estimated: 200 rows × 2.5KB = 0.5MB
52{
55 Light::Field<Light::SqlText> description; // ~2KB
57 Light::Field<bool> is_active { true };
58 Light::Field<int> sort_order { 0 };
59 // Simplified: removed self-referential parent to avoid ORM recursion issues
61};
62
63/// @brief Product entity with large description and specifications JSON.
64/// Estimated: 2,000 rows × 12KB = 24MB
66{
71 Light::Field<Light::SqlText> long_description; // ~8KB - main size contributor
72 Light::Field<Light::SqlText> specifications_json; // ~2KB
75 Light::Field<int> stock_quantity { 0 };
76 Light::Field<bool> is_active { true };
77 Light::Field<bool> is_featured { false };
80
81 Light::BelongsTo<Member(LargeDb_Category::id), Light::SqlRealName { "category_id" }> category {};
82};
83
84/// @brief ProductImage entity - main size driver with large binary image data.
85/// Estimated: 4,000 rows × 55KB = 220MB (largest contributor)
87{
91 Light::Field<Light::SqlText> image_data; // ~50KB pseudo-image (stored as text for compatibility)
92 Light::Field<Light::SqlText> thumbnail_data; // ~5KB pseudo-thumbnail (stored as text for compatibility)
93 Light::Field<int> sort_order { 0 };
94 Light::Field<bool> is_primary { false };
96
97 Light::BelongsTo<Member(LargeDb_Product::id), Light::SqlRealName { "product_id" }> product {};
98};
99
100/// @brief Order entity with address JSON fields.
101/// Estimated: 10,000 rows × 1.5KB = 15MB
103{
105 Light::Field<Light::SqlGuid> order_number;
106 Light::Field<Light::SqlAnsiString<20>> status; // pending, processing, shipped, delivered, cancelled
107 Light::Field<double> subtotal;
108 Light::Field<double> tax_amount;
109 Light::Field<double> shipping_amount;
110 Light::Field<double> total_amount;
111 Light::Field<Light::SqlText> shipping_address_json; // ~500 bytes
112 Light::Field<Light::SqlText> billing_address_json; // ~500 bytes
116
117 Light::BelongsTo<Member(LargeDb_User::id), Light::SqlRealName { "user_id" }> user {};
118};
119
120/// @brief OrderItem entity - join between Order and Product with quantity and price.
121/// Estimated: 30,000 rows × 600B = 18MB
123{
125 Light::Field<int> quantity;
126 Light::Field<double> unit_price;
127 Light::Field<double> total_price;
128 Light::Field<std::optional<double>> discount_amount;
129
130 Light::BelongsTo<Member(LargeDb_Order::id), Light::SqlRealName { "order_id" }> order {};
131 Light::BelongsTo<Member(LargeDb_Product::id), Light::SqlRealName { "product_id" }> product {};
132};
133
134/// @brief Review entity with content, pros and cons.
135/// Estimated: 8,000 rows × 3.5KB = 28MB
137{
139 Light::Field<int> rating; // 1-5
141 Light::Field<Light::SqlText> content; // ~2KB
144 Light::Field<bool> is_verified_purchase { false };
145 Light::Field<int> helpful_votes { 0 };
148
149 Light::BelongsTo<Member(LargeDb_User::id), Light::SqlRealName { "user_id" }> user {};
150 Light::BelongsTo<Member(LargeDb_Product::id), Light::SqlRealName { "product_id" }> product {};
151};
152
153/// @brief Tag entity for product tagging.
154/// Estimated: 500 rows × 350B = 175KB
162
163/// @brief ProductTag join table for many-to-many Product<->Tag relationship.
164/// Estimated: 6,000 rows × 50B = 300KB
166{
168
169 Light::BelongsTo<Member(LargeDb_Product::id), Light::SqlRealName { "product_id" }> product {};
170 Light::BelongsTo<Member(LargeDb_Tag::id), Light::SqlRealName { "tag_id" }> tag {};
171};
172
173/// @brief ActivityLog for tracking user actions - high volume table.
174/// Estimated: 50,000 rows × 2.5KB = 125MB
176{
178 Light::Field<Light::SqlAnsiString<50>> action_type; // login, logout, view_product, add_to_cart, purchase, etc.
181 Light::Field<std::optional<Light::SqlText>> old_values_json; // ~1KB
182 Light::Field<std::optional<Light::SqlText>> new_values_json; // ~1KB
186
187 Light::BelongsTo<Member(LargeDb_User::id), Light::SqlRealName { "user_id" }, Light::SqlNullable::Null> user {};
188};
189
190/// @brief SystemAuditLog for system-level events - standalone high-volume table.
191/// Estimated: 5,000 rows × 8.5KB = 42.5MB
204
205/// @brief Article entity for blog/content management with large content.
206/// Estimated: 500 rows × 37KB = 18.5MB
208{
213 Light::Field<Light::SqlText> content; // ~15KB
214 Light::Field<std::optional<Light::SqlText>> featured_image; // ~20KB (stored as text for compatibility)
215 Light::Field<Light::SqlAnsiString<20>> status; // draft, published, archived
216 Light::Field<int> view_count { 0 };
217 Light::Field<bool> allow_comments { true };
221
222 Light::BelongsTo<Member(LargeDb_User::id), Light::SqlRealName { "author_id" }> author {};
223};
224
225// Output stream operators for debugging
226
227inline std::ostream& operator<<(std::ostream& os, LargeDb_User const& value)
228{
229 return os << std::format("LargeDb_User {{ id: {}, email: {}, name: {} {} }}",
230 value.id.Value(),
231 value.email.Value().c_str(),
232 value.first_name.Value().c_str(),
233 value.last_name.Value().c_str());
234}
235
236inline std::ostream& operator<<(std::ostream& os, LargeDb_Category const& value)
237{
238 return os << std::format("LargeDb_Category {{ id: {}, name: {} }}", value.id.Value(), value.name.Value().c_str());
239}
240
241inline std::ostream& operator<<(std::ostream& os, LargeDb_Product const& value)
242{
243 return os << std::format("LargeDb_Product {{ id: {}, sku: {}, name: {} }}",
244 value.id.Value(),
245 value.sku.Value(),
246 value.name.Value().c_str());
247}
248
249inline std::ostream& operator<<(std::ostream& os, LargeDb_Order const& value)
250{
251 return os << std::format("LargeDb_Order {{ id: {}, order_number: {}, status: {} }}",
252 value.id.Value(),
253 value.order_number.Value(),
254 value.status.Value().c_str());
255}
256
257inline std::ostream& operator<<(std::ostream& os, LargeDb_Review const& value)
258{
259 return os << std::format("LargeDb_Review {{ id: {}, rating: {} }}", value.id.Value(), value.rating.Value());
260}
261
262inline std::ostream& operator<<(std::ostream& os, LargeDb_Tag const& value)
263{
264 return os << std::format("LargeDb_Tag {{ id: {}, name: {} }}", value.id.Value(), value.name.Value().c_str());
265}
266
267inline std::ostream& operator<<(std::ostream& os, LargeDb_Article const& value)
268{
269 return os << std::format("LargeDb_Article {{ id: {}, title: {} }}", value.id.Value(), value.title.Value().c_str());
270}
Represents a one-to-one relationship.
Definition BelongsTo.hpp:57
ActivityLog for tracking user actions - high volume table. Estimated: 50,000 rows × 2....
Definition Entities.hpp:176
Article entity for blog/content management with large content. Estimated: 500 rows × 37KB = 18....
Definition Entities.hpp:208
Category entity. Estimated: 200 rows × 2.5KB = 0.5MB.
Definition Entities.hpp:52
OrderItem entity - join between Order and Product with quantity and price. Estimated: 30,...
Definition Entities.hpp:123
Order entity with address JSON fields. Estimated: 10,000 rows × 1.5KB = 15MB.
Definition Entities.hpp:103
ProductImage entity - main size driver with large binary image data. Estimated: 4,...
Definition Entities.hpp:87
ProductTag join table for many-to-many Product<->Tag relationship. Estimated: 6,000 rows × 50B = 300K...
Definition Entities.hpp:166
Product entity with large description and specifications JSON. Estimated: 2,000 rows × 12KB = 24MB.
Definition Entities.hpp:66
Review entity with content, pros and cons. Estimated: 8,000 rows × 3.5KB = 28MB.
Definition Entities.hpp:137
SystemAuditLog for system-level events - standalone high-volume table. Estimated: 5,...
Definition Entities.hpp:193
Tag entity for product tagging. Estimated: 500 rows × 350B = 175KB.
Definition Entities.hpp:156
User entity with large bio and avatar fields. Estimated: 2,000 rows × 11KB = 22MB.
Definition Entities.hpp:34
Represents a single column in a table.
Definition Field.hpp:84
constexpr T const & Value() const noexcept
Returns the value of the field.
Definition Field.hpp:317
Helper class, used to represent a real SQL column names as template arguments.