From 1424d29c5de188ff1b800e54eb8c1925af4f64f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Wed, 23 Jul 2025 22:32:26 +0200 Subject: [PATCH] Put the literals into a separate namespace; resolves #31 (#32) --- README.md | 4 + docs/README.md | 3 +- docs/col.md | 8 +- docs/connection_pool.md | 2 + docs/create_index.md | 9 +- docs/delete_from.md | 8 +- docs/group_by_and_aggregations.md | 2 + docs/joins.md | 5 +- docs/literals.md | 127 ++++++++++++++++++ docs/pattern.md | 1 + docs/postgres.md | 1 + docs/reading.md | 11 +- docs/sqlite.md | 1 + docs/to_sql.md | 5 + docs/transactions.md | 2 + docs/update.md | 13 +- include/sqlgen.hpp | 1 + include/sqlgen/col.hpp | 111 --------------- include/sqlgen/literals.hpp | 123 +++++++++++++++++ tests/postgres/test_aggregations.cpp | 1 + .../test_aggregations_with_nullable.cpp | 1 + tests/postgres/test_auto_incr_primary_key.cpp | 1 + tests/postgres/test_create_index.cpp | 1 + tests/postgres/test_create_index_dry.cpp | 1 + tests/postgres/test_create_index_where.cpp | 1 + .../postgres/test_create_index_where_dry.cpp | 1 + tests/postgres/test_create_table.cpp | 1 + tests/postgres/test_create_table_dry.cpp | 1 + tests/postgres/test_delete_from.cpp | 1 + tests/postgres/test_delete_from_dry.cpp | 1 + tests/postgres/test_drop_dry.cpp | 1 + tests/postgres/test_group_by.cpp | 1 + .../test_group_by_with_operations.cpp | 1 + tests/postgres/test_insert_and_read.cpp | 1 + .../test_insert_and_read_two_tables.cpp | 1 + tests/postgres/test_is_null.cpp | 1 + tests/postgres/test_is_null_dry.cpp | 1 + tests/postgres/test_join.cpp | 1 + tests/postgres/test_joins_nested.cpp | 1 + tests/postgres/test_joins_nested_grouped.cpp | 1 + tests/postgres/test_joins_two_tables.cpp | 1 + .../test_joins_two_tables_grouped.cpp | 1 + tests/postgres/test_like.cpp | 1 + tests/postgres/test_like_dry.cpp | 1 + tests/postgres/test_limit.cpp | 1 + tests/postgres/test_operations.cpp | 1 + .../test_operations_with_nullable.cpp | 1 + tests/postgres/test_range.cpp | 1 + tests/postgres/test_range_select_from.cpp | 1 + .../test_select_from_with_timestamps.cpp | 1 + tests/postgres/test_select_from_with_to.cpp | 1 + tests/postgres/test_timestamp.cpp | 1 + tests/postgres/test_timestamp_with_tz.cpp | 1 + tests/postgres/test_to_select_from2_dry.cpp | 1 + tests/postgres/test_transaction.cpp | 1 + tests/postgres/test_update.cpp | 1 + tests/postgres/test_update_dry.cpp | 1 + tests/postgres/test_varchar.cpp | 1 + tests/postgres/test_where.cpp | 1 + tests/postgres/test_where_dry.cpp | 1 + tests/postgres/test_where_with_operations.cpp | 1 + tests/postgres/test_where_with_timestamps.cpp | 1 + tests/postgres/test_write_and_read.cpp | 1 + .../postgres/test_write_and_read_curried.cpp | 1 + tests/postgres/test_write_and_read_pool.cpp | 1 + tests/sqlite/test_aggregations.cpp | 1 + .../test_aggregations_with_nullable.cpp | 1 + tests/sqlite/test_alpha_numeric_query.cpp | 1 + tests/sqlite/test_auto_incr_primary_key.cpp | 1 + tests/sqlite/test_create_index.cpp | 1 + tests/sqlite/test_create_table.cpp | 1 + tests/sqlite/test_delete_from.cpp | 1 + tests/sqlite/test_drop.cpp | 1 + tests/sqlite/test_group_by.cpp | 1 + .../sqlite/test_group_by_with_operations.cpp | 1 + tests/sqlite/test_insert_and_read.cpp | 1 + tests/sqlite/test_insert_by_ref_and_read.cpp | 1 + tests/sqlite/test_is_null.cpp | 1 + tests/sqlite/test_join.cpp | 1 + tests/sqlite/test_joins_nested.cpp | 1 + tests/sqlite/test_joins_nested_grouped.cpp | 1 + tests/sqlite/test_joins_two_tables.cpp | 1 + .../sqlite/test_joins_two_tables_grouped.cpp | 1 + tests/sqlite/test_like.cpp | 1 + tests/sqlite/test_limit.cpp | 1 + tests/sqlite/test_operations.cpp | 1 + .../sqlite/test_operations_with_nullable.cpp | 1 + tests/sqlite/test_order_by.cpp | 1 + tests/sqlite/test_range_select_from.cpp | 1 + .../sqlite/test_range_select_from_with_to.cpp | 1 + .../test_select_from_with_timestamps.cpp | 1 + tests/sqlite/test_single_read.cpp | 1 + tests/sqlite/test_transaction.cpp | 1 + tests/sqlite/test_update.cpp | 1 + tests/sqlite/test_where.cpp | 1 + tests/sqlite/test_where_with_nullable.cpp | 1 + .../test_where_with_nullable_operations.cpp | 1 + tests/sqlite/test_where_with_operations.cpp | 1 + tests/sqlite/test_where_with_timestamps.cpp | 1 + tests/sqlite/test_write_and_read_curried.cpp | 1 + 100 files changed, 394 insertions(+), 124 deletions(-) create mode 100644 docs/literals.md create mode 100644 include/sqlgen/literals.hpp diff --git a/README.md b/README.md index dff7bcc..e53dca6 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ VALUES (?, ?, ?, ?); #include using namespace sqlgen; +using namespace sqlgen::literals; // Build a query for adults, ordered by age const auto query = read> | @@ -200,6 +201,7 @@ LIMIT 10; ```cpp using namespace sqlgen; +using namespace sqlgen::literals; struct Children { std::string last_name; @@ -237,6 +239,7 @@ GROUP BY "last_name"; ```cpp using namespace sqlgen; +using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; @@ -274,6 +277,7 @@ ORDER BY t1."id", t3."id" ```cpp using namespace sqlgen; +using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/docs/README.md b/docs/README.md index fa03d0e..4b8eefb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,6 +6,7 @@ Welcome to the sqlgen documentation. This guide provides detailed information ab - [Defining Tables](defining_tables.md) - How to define tables using C++ structs - [sqlgen::col](col.md) - How to represent columns in queries +- [sqlgen::literals](literals.md) - How to use column and table alias literals in queries - [sqlgen::Flatten](flatten.md) - How to "inherit" fields from other structs - [sqlgen::PrimaryKey](primary_key.md) - How to define primary keys in sqlgen - [sqlgen::Result](result.md) - How sqlgen handles errors and results @@ -24,8 +25,8 @@ Welcome to the sqlgen documentation. This guide provides detailed information ab - [sqlgen::drop](drop.md) - How to drop a table - [sqlgen::exec](exec.md) - How to execute raw SQL statements - [sqlgen::group_by and Aggregations](group_by_and_aggregations.md) - How generate GROUP BY queries and aggregate data +- [sqlgen::inner_join, sqlgen::left_join, sqlgen::right_join, sqlgen::full_join](joins.md) - How to join different tables - [sqlgen::insert](insert.md) - How to insert data within transactions -- [Joins](joins.md) - How to join different tables - [sqlgen::update](update.md) - How to update data in a table ## Other Operations diff --git a/docs/col.md b/docs/col.md index 54086b7..b21cacb 100644 --- a/docs/col.md +++ b/docs/col.md @@ -10,6 +10,7 @@ Reference a column using the string literal operator: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Using string literal operator const auto age_col = "age"_c; @@ -26,6 +27,7 @@ Compare columns with values or other columns: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Compare with value const auto query1 = read> | where("age"_c > 18); @@ -55,6 +57,7 @@ Check for NULL or NOT NULL values: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Find records where age is NULL const auto query1 = read> | @@ -85,6 +88,7 @@ Use LIKE and NOT LIKE for pattern matching: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Find names starting with 'H' const auto query1 = read> | @@ -115,6 +119,7 @@ Specify column ordering in queries: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Order by age ascending const auto query1 = read> | @@ -154,6 +159,7 @@ Set column values in UPDATE statements: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Update a single column const auto query1 = update("age"_c.set(46)); @@ -192,4 +198,4 @@ WHERE "first_name" = 'Hugo'; - All operations are composable and can be chained together - The class supports both value and column-to-column comparisons - String literals are automatically converted to the appropriate SQL type -- The class is thread-safe and has no mutable state \ No newline at end of file +- The class is thread-safe and has no mutable state diff --git a/docs/connection_pool.md b/docs/connection_pool.md index 7cd859d..da4c908 100644 --- a/docs/connection_pool.md +++ b/docs/connection_pool.md @@ -105,6 +105,7 @@ Example of thread-safe usage with monadic style: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Create pool const auto pool = make_connection_pool(config, credentials); @@ -133,6 +134,7 @@ Sessions are managed through RAII (Resource Acquisition Is Initialization) and s ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Using monadic style for session management with exec session(pool) diff --git a/docs/create_index.md b/docs/create_index.md index b31acce..33622ec 100644 --- a/docs/create_index.md +++ b/docs/create_index.md @@ -37,6 +37,7 @@ Create an index only if it doesn't already exist: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = create_index<"person_ix", Person>("first_name"_c, "last_name"_c) | if_not_exists; @@ -53,6 +54,7 @@ You can also use monadic error handling here: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = create_index<"person_ix", Person>("first_name"_c, "last_name"_c) | if_not_exists; @@ -66,6 +68,7 @@ Create a unique index to enforce uniqueness constraints: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = create_unique_index<"person_ix", Person>("first_name"_c, "last_name"_c); @@ -84,6 +87,7 @@ Create a partial index by adding a WHERE clause to filter which rows are include ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = create_index<"test_table_ix", TestTable>("field1"_c, "field2"_c) | if_not_exists | @@ -104,6 +108,7 @@ The WHERE clause can be combined with other modifiers like `if_not_exists` and w ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = create_index<"person_ix", Person>("first_name"_c, "last_name"_c) | if_not_exists; @@ -120,7 +125,7 @@ This generates the following SQL: CREATE INDEX IF NOT EXISTS "person_ix" ON "Person" ("first_name", "last_name"); ``` -It is strongly recommended that you use `using namespace sqlgen`. However, +It is strongly recommended that you use `using namespace sqlgen` and `using namespace sqlgen::literals`. However, if you do not want to do that, you can rewrite the example above as follows: ```cpp @@ -134,7 +139,7 @@ const auto result = query(conn); - The `if_not_exists` clause is optional - if omitted, the query will fail if the index already exists - The `Result>` type provides error handling; use `.value()` to extract the result (will throw an exception if there's an error) or handle errors as needed or refer to the documentation on `sqlgen::Result<...>` for other forms of error handling. -- `"..."_c` refers to the name of the column. If such a field does not exist on the struct (e.g., `Person`), the code will fail to compile. +- `"..."_c` refers to the name of the column. If such a field does not exist on the struct (e.g., `Person`), the code will fail to compile. It is defined in the namespace `sqlgen::literals`. - Index names must be unique within a database - You can create indexes on multiple columns by providing multiple column names - Use `create_unique_index` when you need to enforce uniqueness constraints on the indexed columns diff --git a/docs/delete_from.md b/docs/delete_from.md index 7617d8f..4e67710 100644 --- a/docs/delete_from.md +++ b/docs/delete_from.md @@ -37,6 +37,7 @@ Delete specific records using a `where` clause: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = delete_from | where("first_name"_c == "Hugo"); @@ -52,12 +53,14 @@ WHERE "first_name" = 'Hugo'; ``` Note that `"..."_c` refers to the name of the column. If such a field does not -exist on the struct `Person`, the code will fail to compile. +exist on the struct `Person`, the code will fail to compile. `"..."_c` is +defined in the namespace `sqlgen::literals`. You can also use monadic error handling here: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = delete_from | where("first_name"_c == "Hugo"); @@ -70,6 +73,7 @@ const auto result = sqlite::connect("database.db").and_then(query); ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = delete_from | where("age"_c >= 18 and "last_name"_c == "Simpson"); @@ -88,7 +92,7 @@ DELETE FROM "Person" WHERE ("age" >= 18) AND ("last_name" = 'Simpson'); ``` -It is strongly recommended that you use `using namespace sqlgen`. However, +It is strongly recommended that you use `using namespace sqlgen` and `using namespace sqlgen::literals`. However, if you do not want to do that, you can rewrite the example above as follows: ```cpp diff --git a/docs/group_by_and_aggregations.md b/docs/group_by_and_aggregations.md index c3f5d7f..8b13efd 100644 --- a/docs/group_by_and_aggregations.md +++ b/docs/group_by_and_aggregations.md @@ -10,6 +10,7 @@ Perform aggregations without grouping: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; struct Children { int num_children; @@ -54,6 +55,7 @@ Group data and perform aggregations: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; struct Children { std::string last_name; diff --git a/docs/joins.md b/docs/joins.md index 70482d7..2d2f580 100644 --- a/docs/joins.md +++ b/docs/joins.md @@ -19,6 +19,7 @@ Each join type can be used with either a table or a subquery, and can be aliased ```cpp using namespace sqlgen; +using namespace sqlgen::literals; struct Person { sqlgen::PrimaryKey id; @@ -128,7 +129,9 @@ Where: ## Aliasing and Column References -When joining tables or subqueries, you must use aliases to disambiguate columns. Use the `_t1`, `_t2`, etc. suffixes to refer to columns from different tables or subqueries: +When joining tables or subqueries, you must use aliases to disambiguate columns. Use the `_t1`, `_t2`, etc. +suffixes to refer to columns from different tables or subqueries, which are defined in the +namespace `sqlgen::literals`: ```cpp "id"_t1, "first_name"_t2, "age"_t3 diff --git a/docs/literals.md b/docs/literals.md new file mode 100644 index 0000000..f856864 --- /dev/null +++ b/docs/literals.md @@ -0,0 +1,127 @@ +# `sqlgen::literals` + +The `sqlgen::literals` namespace provides user-defined literal operators for referencing columns and table aliases in a type-safe, expressive, and concise way when building SQL queries with sqlgen. These literals are essential for writing readable and maintainable query expressions, especially when working with complex queries involving joins and table aliases. + +## Usage + +### Column Literals: `_c` + +Reference a column by name using the `_c` literal: + +```cpp +using namespace sqlgen; +using namespace sqlgen::literals; + +// Reference the "age" column +const auto age_col = "age"_c; + +// Use in a query +const auto query = sqlgen::read> | where("age"_c < 18); +``` + +This generates SQL like: + +```sql +SELECT "id", "first_name", "last_name", "age" +FROM "Person" +WHERE "age" < 18; +``` + +If the column name does not exist in the struct, the code will fail to compile, ensuring type safety. + +### Table Alias Literals: `_t1`, `_t2`, ..., `_t99` + +When working with joins or subqueries, you often need to disambiguate columns by table alias. The `sqlgen::literals` namespace provides `_tN` suffixes for this purpose, where `N` ranges from 1 to 99: + +```cpp +using namespace sqlgen; +using namespace sqlgen::literals; + +// Reference the "id" column from table alias t1 +const auto id_t1 = "id"_t1; + +// Reference the "first_name" column from table alias t2 +const auto first_name_t2 = "first_name"_t2; +``` + +#### Example: Joins with Aliases + +```cpp +const auto get_people = + select_from( + "last_name"_t1 | as<"last_name">, + "first_name"_t1 | as<"first_name_parent">, + "first_name"_t3 | as<"first_name_child">, + ("age"_t1 - "age"_t3) | as<"parent_age_at_birth"> + ) + | inner_join("id"_t1 == "parent_id"_t2) + | left_join("id"_t3 == "child_id"_t2) + | order_by("id"_t1, "id"_t3) + | to>; +``` + +This produces SQL like: + +```sql +SELECT t1."last_name" AS "last_name", t1."first_name" AS "first_name_parent", t3."first_name" AS "first_name_child", (t1."age") - (t3."age") AS "parent_age_at_birth" +FROM "Person" t1 +INNER JOIN "Relationship" t2 ON t1."id" = t2."parent_id" +LEFT JOIN "Person" t3 ON t3."id" = t2."child_id" +ORDER BY t1."id", t3."id" +``` + +### Supported Suffixes + +- `_c` — Reference a column by name (e.g., `"age"_c`) +- `_t1`, `_t2`, ..., `_t99` — Reference a column by name and table alias (e.g., `"id"_t2`) + +All these literals are defined in the `sqlgen::literals` namespace. It is strongly recommended to use: + +```cpp +using namespace sqlgen::literals; +``` + +in your query files for convenience. + +## Type Safety + +- Column names are checked at compile time against the struct definition. +- Table aliases are enforced by the literal suffix, preventing ambiguous references in joins. +- If you use a column or alias that does not exist, the code will fail to compile. + +## Advanced: Custom Aliases + +If you need an alias outside the provided `_tN` range, you can use the `col` template directly: + +```cpp +const auto custom_col = col<"id", "custom_alias">; +``` + +## Notes + +- The `_c` and `_tN` literals return `Col` objects, which support all standard SQL operations (comparison, ordering, etc.). +- These literals are composable with all sqlgen query builder functions, such as `where`, `order_by`, `group_by`, and join conditions. +- The use of these literals is required for type-safe, readable, and maintainable query construction in sqlgen. +- All operations are thread-safe and have no mutable state. + +## Example: Full Query Composition + +```cpp +using namespace sqlgen; +using namespace sqlgen::literals; + +const auto query = sqlgen::read> + | where("age"_c >= 18 and "last_name"_c == "Simpson") + | order_by("first_name"_c.desc()) + | limit(10); +``` + +This generates: + +```sql +SELECT "id", "first_name", "last_name", "age" +FROM "Person" +WHERE ("age" >= 18) AND ("last_name" = 'Simpson') +ORDER BY "first_name" DESC +LIMIT 10; +``` diff --git a/docs/pattern.md b/docs/pattern.md index d353f2e..b31afff 100644 --- a/docs/pattern.md +++ b/docs/pattern.md @@ -109,6 +109,7 @@ struct Person { std::vector get_people(const auto& conn, const sqlgen::AlphaNumeric& first_name) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("first_name"_c == first_name); return query(conn).value(); diff --git a/docs/postgres.md b/docs/postgres.md index 628a336..9cea693 100644 --- a/docs/postgres.md +++ b/docs/postgres.md @@ -33,6 +33,7 @@ if (!conn) { } using namespace sqlgen; +using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and "first_name"_c != "Hugo"); diff --git a/docs/reading.md b/docs/reading.md index 83b3b90..25dc1f2 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -38,6 +38,7 @@ Filter results using a `where` clause: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and "first_name"_c != "Hugo"); @@ -56,12 +57,14 @@ WHERE ``` Note that `"..."_c` refers to the name of the column. If such a field does not -exists on the struct `Person`, the code will fail to compile. +exists on the struct `Person`, the code will fail to compile. It is defined in +the namespace `sqlgen::literals`. You can also use monadic error handling here: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and "first_name"_c != "Hugo"); @@ -76,6 +79,7 @@ Sort and limit results: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = sqlgen::read> | order_by("age"_c) | @@ -125,6 +129,7 @@ const auto adults = people_range | filter([](const sqlgen::Result& r) { ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c >= 18) | @@ -147,7 +152,7 @@ ORDER BY LIMIT 10; ``` -It is strongly recommended that you use `using namespace sqlgen`. However, +It is strongly recommended that you use `using namespace sqlgen` and `using namespace sqlgen::literals;`. However, if you do not want to do that, you can rewrite the example above as follows: ```cpp @@ -164,4 +169,4 @@ const auto adults = query(conn).value(); - All query clauses (`where`, `order_by`, `limit`) are optional. - The `Result` type provides error handling; use `.value()` to extract the result (will throw a exception if the results) or handle errors as needed. Refer to the - The `sqlgen::Range` type allows for lazy iteration over results. -- `"..."_c` refers to the name of the column. \ No newline at end of file +- `"..."_c` refers to the name of the column. diff --git a/docs/sqlite.md b/docs/sqlite.md index ef6ab7e..7ebfeb8 100644 --- a/docs/sqlite.md +++ b/docs/sqlite.md @@ -27,6 +27,7 @@ if (!conn) { } using namespace sqlgen; +using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and "first_name"_c != "Hugo"); diff --git a/docs/to_sql.md b/docs/to_sql.md index e4175fa..1a867a3 100644 --- a/docs/to_sql.md +++ b/docs/to_sql.md @@ -10,6 +10,7 @@ Transpile any SQL operation to a dialect-specific SQL string: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Define a query const auto query = sqlgen::read> | @@ -44,6 +45,7 @@ const auto sqlite_sql = sqlite::to_sql(query); ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Basic select const auto select_query = sqlgen::read>; @@ -81,6 +83,7 @@ before actually inserting the data. ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Define a table structure struct TestTable { @@ -111,6 +114,7 @@ CREATE TABLE IF NOT EXISTS "TestTable" ( ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto insert_query = Insert{}; const auto sql = postgres::to_sql(insert_query); @@ -134,6 +138,7 @@ VALUES (?, ?, ?, ?); ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto delete_query = delete_from | where("field2"_c > 0); diff --git a/docs/transactions.md b/docs/transactions.md index cf1ace4..df13c16 100644 --- a/docs/transactions.md +++ b/docs/transactions.md @@ -14,6 +14,7 @@ Here's a basic example of how to use transactions: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; // Start a transaction and chain operations // Note that all of these operations return @@ -37,6 +38,7 @@ Example with error handling: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; auto conn = sqlite::connect("database.db") .and_then(begin_transaction) diff --git a/docs/update.md b/docs/update.md index e3b79b2..802b9b9 100644 --- a/docs/update.md +++ b/docs/update.md @@ -12,6 +12,7 @@ Update specific columns in a table: const auto conn = sqlgen::sqlite::connect("database.db"); using namespace sqlgen; +using namespace sqlgen::literals; const auto query = update("age"_c.set(100), "first_name"_c.set("New Name")); @@ -42,6 +43,7 @@ Update specific records using a `where` clause: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = update("age"_c.set(100)) | where("first_name"_c == "Hugo"); @@ -58,12 +60,14 @@ WHERE "first_name" = 'Hugo'; ``` Note that `"..."_c` refers to the name of the column. If such a field does not -exist on the struct `Person`, the code will fail to compile. +exist on the struct `Person`, the code will fail to compile. It is defined +in the namespace `sqlgen::literals`. You can also use monadic error handling here: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = update("age"_c.set(100)) | where("first_name"_c == "Hugo"); @@ -78,6 +82,7 @@ You can set a column's value to another column's value: ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = update("first_name"_c.set("last_name"_c)) | where("age"_c > 18); @@ -97,6 +102,7 @@ WHERE "age" > 18; ```cpp using namespace sqlgen; +using namespace sqlgen::literals; const auto query = update( "first_name"_c.set("last_name"_c), @@ -120,7 +126,8 @@ SET WHERE "age" > 0; ``` -It is strongly recommended that you use `using namespace sqlgen`. However, +It is strongly recommended that you use `using namespace sqlgen` +and `using namespace sqlgen::literals`. However, if you do not want to do that, you can rewrite the example above as follows: ```cpp @@ -137,7 +144,7 @@ const auto result = query(conn); - You must specify at least one column to update - The `where` clause is optional - if omitted, all records will be updated - The `Result>` type provides error handling; use `.value()` to extract the result (will throw an exception if there's an error) or handle errors as needed or refer to the documentation on `sqlgen::Result<...>` for other forms of error handling -- `"..."_c` refers to the name of the column +- `"..."_c` refers to the name of the column. It is defined in the namespace `sqlgen::literals`. - You can set columns to either literal values or other column values - The update operation is atomic - either all specified columns are updated or none are diff --git a/include/sqlgen.hpp b/include/sqlgen.hpp index 60f21cb..e761558 100644 --- a/include/sqlgen.hpp +++ b/include/sqlgen.hpp @@ -31,6 +31,7 @@ #include "sqlgen/is_connection.hpp" #include "sqlgen/joins.hpp" #include "sqlgen/limit.hpp" +#include "sqlgen/literals.hpp" #include "sqlgen/operations.hpp" #include "sqlgen/order_by.hpp" #include "sqlgen/patterns.hpp" diff --git a/include/sqlgen/col.hpp b/include/sqlgen/col.hpp index 67d63fd..b344389 100644 --- a/include/sqlgen/col.hpp +++ b/include/sqlgen/col.hpp @@ -225,117 +225,6 @@ struct ToTranspilationType> { }; } // namespace transpilation -template -auto operator"" _c() { - return Col<_name>{}; -} - -#define SQLGEN_TABLE_ALIAS_LITERAL(N) \ - template \ - auto operator""_t##N() { \ - return Col<_name, "t" #N>{}; \ - } - -SQLGEN_TABLE_ALIAS_LITERAL(1) -SQLGEN_TABLE_ALIAS_LITERAL(2) -SQLGEN_TABLE_ALIAS_LITERAL(3) -SQLGEN_TABLE_ALIAS_LITERAL(4) -SQLGEN_TABLE_ALIAS_LITERAL(5) -SQLGEN_TABLE_ALIAS_LITERAL(6) -SQLGEN_TABLE_ALIAS_LITERAL(7) -SQLGEN_TABLE_ALIAS_LITERAL(8) -SQLGEN_TABLE_ALIAS_LITERAL(9) -SQLGEN_TABLE_ALIAS_LITERAL(10) -SQLGEN_TABLE_ALIAS_LITERAL(11) -SQLGEN_TABLE_ALIAS_LITERAL(12) -SQLGEN_TABLE_ALIAS_LITERAL(13) -SQLGEN_TABLE_ALIAS_LITERAL(14) -SQLGEN_TABLE_ALIAS_LITERAL(15) -SQLGEN_TABLE_ALIAS_LITERAL(16) -SQLGEN_TABLE_ALIAS_LITERAL(17) -SQLGEN_TABLE_ALIAS_LITERAL(18) -SQLGEN_TABLE_ALIAS_LITERAL(19) -SQLGEN_TABLE_ALIAS_LITERAL(20) -SQLGEN_TABLE_ALIAS_LITERAL(21) -SQLGEN_TABLE_ALIAS_LITERAL(22) -SQLGEN_TABLE_ALIAS_LITERAL(23) -SQLGEN_TABLE_ALIAS_LITERAL(24) -SQLGEN_TABLE_ALIAS_LITERAL(25) -SQLGEN_TABLE_ALIAS_LITERAL(26) -SQLGEN_TABLE_ALIAS_LITERAL(27) -SQLGEN_TABLE_ALIAS_LITERAL(28) -SQLGEN_TABLE_ALIAS_LITERAL(29) -SQLGEN_TABLE_ALIAS_LITERAL(30) -SQLGEN_TABLE_ALIAS_LITERAL(31) -SQLGEN_TABLE_ALIAS_LITERAL(32) -SQLGEN_TABLE_ALIAS_LITERAL(33) -SQLGEN_TABLE_ALIAS_LITERAL(34) -SQLGEN_TABLE_ALIAS_LITERAL(35) -SQLGEN_TABLE_ALIAS_LITERAL(36) -SQLGEN_TABLE_ALIAS_LITERAL(37) -SQLGEN_TABLE_ALIAS_LITERAL(38) -SQLGEN_TABLE_ALIAS_LITERAL(39) -SQLGEN_TABLE_ALIAS_LITERAL(40) -SQLGEN_TABLE_ALIAS_LITERAL(41) -SQLGEN_TABLE_ALIAS_LITERAL(42) -SQLGEN_TABLE_ALIAS_LITERAL(43) -SQLGEN_TABLE_ALIAS_LITERAL(44) -SQLGEN_TABLE_ALIAS_LITERAL(45) -SQLGEN_TABLE_ALIAS_LITERAL(46) -SQLGEN_TABLE_ALIAS_LITERAL(47) -SQLGEN_TABLE_ALIAS_LITERAL(48) -SQLGEN_TABLE_ALIAS_LITERAL(49) -SQLGEN_TABLE_ALIAS_LITERAL(50) -SQLGEN_TABLE_ALIAS_LITERAL(51) -SQLGEN_TABLE_ALIAS_LITERAL(52) -SQLGEN_TABLE_ALIAS_LITERAL(53) -SQLGEN_TABLE_ALIAS_LITERAL(54) -SQLGEN_TABLE_ALIAS_LITERAL(55) -SQLGEN_TABLE_ALIAS_LITERAL(56) -SQLGEN_TABLE_ALIAS_LITERAL(57) -SQLGEN_TABLE_ALIAS_LITERAL(58) -SQLGEN_TABLE_ALIAS_LITERAL(59) -SQLGEN_TABLE_ALIAS_LITERAL(60) -SQLGEN_TABLE_ALIAS_LITERAL(61) -SQLGEN_TABLE_ALIAS_LITERAL(62) -SQLGEN_TABLE_ALIAS_LITERAL(63) -SQLGEN_TABLE_ALIAS_LITERAL(64) -SQLGEN_TABLE_ALIAS_LITERAL(65) -SQLGEN_TABLE_ALIAS_LITERAL(66) -SQLGEN_TABLE_ALIAS_LITERAL(67) -SQLGEN_TABLE_ALIAS_LITERAL(68) -SQLGEN_TABLE_ALIAS_LITERAL(69) -SQLGEN_TABLE_ALIAS_LITERAL(70) -SQLGEN_TABLE_ALIAS_LITERAL(71) -SQLGEN_TABLE_ALIAS_LITERAL(72) -SQLGEN_TABLE_ALIAS_LITERAL(73) -SQLGEN_TABLE_ALIAS_LITERAL(74) -SQLGEN_TABLE_ALIAS_LITERAL(75) -SQLGEN_TABLE_ALIAS_LITERAL(76) -SQLGEN_TABLE_ALIAS_LITERAL(77) -SQLGEN_TABLE_ALIAS_LITERAL(78) -SQLGEN_TABLE_ALIAS_LITERAL(79) -SQLGEN_TABLE_ALIAS_LITERAL(80) -SQLGEN_TABLE_ALIAS_LITERAL(81) -SQLGEN_TABLE_ALIAS_LITERAL(82) -SQLGEN_TABLE_ALIAS_LITERAL(83) -SQLGEN_TABLE_ALIAS_LITERAL(84) -SQLGEN_TABLE_ALIAS_LITERAL(85) -SQLGEN_TABLE_ALIAS_LITERAL(86) -SQLGEN_TABLE_ALIAS_LITERAL(87) -SQLGEN_TABLE_ALIAS_LITERAL(88) -SQLGEN_TABLE_ALIAS_LITERAL(89) -SQLGEN_TABLE_ALIAS_LITERAL(90) -SQLGEN_TABLE_ALIAS_LITERAL(91) -SQLGEN_TABLE_ALIAS_LITERAL(92) -SQLGEN_TABLE_ALIAS_LITERAL(93) -SQLGEN_TABLE_ALIAS_LITERAL(94) -SQLGEN_TABLE_ALIAS_LITERAL(95) -SQLGEN_TABLE_ALIAS_LITERAL(96) -SQLGEN_TABLE_ALIAS_LITERAL(97) -SQLGEN_TABLE_ALIAS_LITERAL(98) -SQLGEN_TABLE_ALIAS_LITERAL(99) - } // namespace sqlgen #endif diff --git a/include/sqlgen/literals.hpp b/include/sqlgen/literals.hpp new file mode 100644 index 0000000..d5b4c21 --- /dev/null +++ b/include/sqlgen/literals.hpp @@ -0,0 +1,123 @@ +#ifndef SQLGEN_LITERALS_HPP_ +#define SQLGEN_LITERALS_HPP_ + +#include + +#include "col.hpp" + +namespace sqlgen::literals { + +template +auto operator"" _c() { + return Col<_name>{}; +} + +#define SQLGEN_TABLE_ALIAS_LITERAL(N) \ + template \ + auto operator""_t##N() { \ + return Col<_name, "t" #N>{}; \ + } + +SQLGEN_TABLE_ALIAS_LITERAL(1) +SQLGEN_TABLE_ALIAS_LITERAL(2) +SQLGEN_TABLE_ALIAS_LITERAL(3) +SQLGEN_TABLE_ALIAS_LITERAL(4) +SQLGEN_TABLE_ALIAS_LITERAL(5) +SQLGEN_TABLE_ALIAS_LITERAL(6) +SQLGEN_TABLE_ALIAS_LITERAL(7) +SQLGEN_TABLE_ALIAS_LITERAL(8) +SQLGEN_TABLE_ALIAS_LITERAL(9) +SQLGEN_TABLE_ALIAS_LITERAL(10) +SQLGEN_TABLE_ALIAS_LITERAL(11) +SQLGEN_TABLE_ALIAS_LITERAL(12) +SQLGEN_TABLE_ALIAS_LITERAL(13) +SQLGEN_TABLE_ALIAS_LITERAL(14) +SQLGEN_TABLE_ALIAS_LITERAL(15) +SQLGEN_TABLE_ALIAS_LITERAL(16) +SQLGEN_TABLE_ALIAS_LITERAL(17) +SQLGEN_TABLE_ALIAS_LITERAL(18) +SQLGEN_TABLE_ALIAS_LITERAL(19) +SQLGEN_TABLE_ALIAS_LITERAL(20) +SQLGEN_TABLE_ALIAS_LITERAL(21) +SQLGEN_TABLE_ALIAS_LITERAL(22) +SQLGEN_TABLE_ALIAS_LITERAL(23) +SQLGEN_TABLE_ALIAS_LITERAL(24) +SQLGEN_TABLE_ALIAS_LITERAL(25) +SQLGEN_TABLE_ALIAS_LITERAL(26) +SQLGEN_TABLE_ALIAS_LITERAL(27) +SQLGEN_TABLE_ALIAS_LITERAL(28) +SQLGEN_TABLE_ALIAS_LITERAL(29) +SQLGEN_TABLE_ALIAS_LITERAL(30) +SQLGEN_TABLE_ALIAS_LITERAL(31) +SQLGEN_TABLE_ALIAS_LITERAL(32) +SQLGEN_TABLE_ALIAS_LITERAL(33) +SQLGEN_TABLE_ALIAS_LITERAL(34) +SQLGEN_TABLE_ALIAS_LITERAL(35) +SQLGEN_TABLE_ALIAS_LITERAL(36) +SQLGEN_TABLE_ALIAS_LITERAL(37) +SQLGEN_TABLE_ALIAS_LITERAL(38) +SQLGEN_TABLE_ALIAS_LITERAL(39) +SQLGEN_TABLE_ALIAS_LITERAL(40) +SQLGEN_TABLE_ALIAS_LITERAL(41) +SQLGEN_TABLE_ALIAS_LITERAL(42) +SQLGEN_TABLE_ALIAS_LITERAL(43) +SQLGEN_TABLE_ALIAS_LITERAL(44) +SQLGEN_TABLE_ALIAS_LITERAL(45) +SQLGEN_TABLE_ALIAS_LITERAL(46) +SQLGEN_TABLE_ALIAS_LITERAL(47) +SQLGEN_TABLE_ALIAS_LITERAL(48) +SQLGEN_TABLE_ALIAS_LITERAL(49) +SQLGEN_TABLE_ALIAS_LITERAL(50) +SQLGEN_TABLE_ALIAS_LITERAL(51) +SQLGEN_TABLE_ALIAS_LITERAL(52) +SQLGEN_TABLE_ALIAS_LITERAL(53) +SQLGEN_TABLE_ALIAS_LITERAL(54) +SQLGEN_TABLE_ALIAS_LITERAL(55) +SQLGEN_TABLE_ALIAS_LITERAL(56) +SQLGEN_TABLE_ALIAS_LITERAL(57) +SQLGEN_TABLE_ALIAS_LITERAL(58) +SQLGEN_TABLE_ALIAS_LITERAL(59) +SQLGEN_TABLE_ALIAS_LITERAL(60) +SQLGEN_TABLE_ALIAS_LITERAL(61) +SQLGEN_TABLE_ALIAS_LITERAL(62) +SQLGEN_TABLE_ALIAS_LITERAL(63) +SQLGEN_TABLE_ALIAS_LITERAL(64) +SQLGEN_TABLE_ALIAS_LITERAL(65) +SQLGEN_TABLE_ALIAS_LITERAL(66) +SQLGEN_TABLE_ALIAS_LITERAL(67) +SQLGEN_TABLE_ALIAS_LITERAL(68) +SQLGEN_TABLE_ALIAS_LITERAL(69) +SQLGEN_TABLE_ALIAS_LITERAL(70) +SQLGEN_TABLE_ALIAS_LITERAL(71) +SQLGEN_TABLE_ALIAS_LITERAL(72) +SQLGEN_TABLE_ALIAS_LITERAL(73) +SQLGEN_TABLE_ALIAS_LITERAL(74) +SQLGEN_TABLE_ALIAS_LITERAL(75) +SQLGEN_TABLE_ALIAS_LITERAL(76) +SQLGEN_TABLE_ALIAS_LITERAL(77) +SQLGEN_TABLE_ALIAS_LITERAL(78) +SQLGEN_TABLE_ALIAS_LITERAL(79) +SQLGEN_TABLE_ALIAS_LITERAL(80) +SQLGEN_TABLE_ALIAS_LITERAL(81) +SQLGEN_TABLE_ALIAS_LITERAL(82) +SQLGEN_TABLE_ALIAS_LITERAL(83) +SQLGEN_TABLE_ALIAS_LITERAL(84) +SQLGEN_TABLE_ALIAS_LITERAL(85) +SQLGEN_TABLE_ALIAS_LITERAL(86) +SQLGEN_TABLE_ALIAS_LITERAL(87) +SQLGEN_TABLE_ALIAS_LITERAL(88) +SQLGEN_TABLE_ALIAS_LITERAL(89) +SQLGEN_TABLE_ALIAS_LITERAL(90) +SQLGEN_TABLE_ALIAS_LITERAL(91) +SQLGEN_TABLE_ALIAS_LITERAL(92) +SQLGEN_TABLE_ALIAS_LITERAL(93) +SQLGEN_TABLE_ALIAS_LITERAL(94) +SQLGEN_TABLE_ALIAS_LITERAL(95) +SQLGEN_TABLE_ALIAS_LITERAL(96) +SQLGEN_TABLE_ALIAS_LITERAL(97) +SQLGEN_TABLE_ALIAS_LITERAL(98) +SQLGEN_TABLE_ALIAS_LITERAL(99) + +} // namespace sqlgen::literals + +#endif diff --git a/tests/postgres/test_aggregations.cpp b/tests/postgres/test_aggregations.cpp index 26935d5..fd2731e 100644 --- a/tests/postgres/test_aggregations.cpp +++ b/tests/postgres/test_aggregations.cpp @@ -33,6 +33,7 @@ TEST(postgres, test_aggregations) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Children { int num_children; diff --git a/tests/postgres/test_aggregations_with_nullable.cpp b/tests/postgres/test_aggregations_with_nullable.cpp index f397615..5ca1da2 100644 --- a/tests/postgres/test_aggregations_with_nullable.cpp +++ b/tests/postgres/test_aggregations_with_nullable.cpp @@ -32,6 +32,7 @@ TEST(postgres, test_aggregations_with_nullable) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Children { int num_children; diff --git a/tests/postgres/test_auto_incr_primary_key.cpp b/tests/postgres/test_auto_incr_primary_key.cpp index 65e7014..3422e89 100644 --- a/tests/postgres/test_auto_incr_primary_key.cpp +++ b/tests/postgres/test_auto_incr_primary_key.cpp @@ -30,6 +30,7 @@ TEST(postgres, test_auto_incr_primary_key) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = postgres::connect(credentials) .and_then(drop | if_exists) diff --git a/tests/postgres/test_create_index.cpp b/tests/postgres/test_create_index.cpp index a2f1fae..fb15f2b 100644 --- a/tests/postgres/test_create_index.cpp +++ b/tests/postgres/test_create_index.cpp @@ -24,6 +24,7 @@ TEST(postgres, test_create_index) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people = sqlgen::postgres::connect(credentials) .and_then(drop | if_exists) diff --git a/tests/postgres/test_create_index_dry.cpp b/tests/postgres/test_create_index_dry.cpp index b6660d1..b202037 100644 --- a/tests/postgres/test_create_index_dry.cpp +++ b/tests/postgres/test_create_index_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_create_index_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = create_index<"test_table_ix", TestTable>("field1"_c, "field2"_c) | diff --git a/tests/postgres/test_create_index_where.cpp b/tests/postgres/test_create_index_where.cpp index b2860a3..8226801 100644 --- a/tests/postgres/test_create_index_where.cpp +++ b/tests/postgres/test_create_index_where.cpp @@ -24,6 +24,7 @@ TEST(postgres, test_create_index_where) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people = sqlgen::postgres::connect(credentials) diff --git a/tests/postgres/test_create_index_where_dry.cpp b/tests/postgres/test_create_index_where_dry.cpp index 4f1e148..37c2cba 100644 --- a/tests/postgres/test_create_index_where_dry.cpp +++ b/tests/postgres/test_create_index_where_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_create_index_where_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = create_index<"test_table_ix", TestTable>("field1"_c, "field2"_c) | diff --git a/tests/postgres/test_create_table.cpp b/tests/postgres/test_create_table.cpp index 0c58f03..7b61cd5 100644 --- a/tests/postgres/test_create_table.cpp +++ b/tests/postgres/test_create_table.cpp @@ -24,6 +24,7 @@ TEST(postgres, test_create_table) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people = sqlgen::postgres::connect(credentials) .and_then(drop | if_exists) diff --git a/tests/postgres/test_create_table_dry.cpp b/tests/postgres/test_create_table_dry.cpp index c733c77..cd56b64 100644 --- a/tests/postgres/test_create_table_dry.cpp +++ b/tests/postgres/test_create_table_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_create_table_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = create_table | if_not_exists; diff --git a/tests/postgres/test_delete_from.cpp b/tests/postgres/test_delete_from.cpp index 5b2b543..c31ba57 100644 --- a/tests/postgres/test_delete_from.cpp +++ b/tests/postgres/test_delete_from.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_delete_from) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_delete_from_dry.cpp b/tests/postgres/test_delete_from_dry.cpp index c34bcd7..9958455 100644 --- a/tests/postgres/test_delete_from_dry.cpp +++ b/tests/postgres/test_delete_from_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_delete_from_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = delete_from | where("field2"_c > 0); diff --git a/tests/postgres/test_drop_dry.cpp b/tests/postgres/test_drop_dry.cpp index 522ec42..66133f7 100644 --- a/tests/postgres/test_drop_dry.cpp +++ b/tests/postgres/test_drop_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_drop_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = drop | if_exists; diff --git a/tests/postgres/test_group_by.cpp b/tests/postgres/test_group_by.cpp index 700394a..ed7bf86 100644 --- a/tests/postgres/test_group_by.cpp +++ b/tests/postgres/test_group_by.cpp @@ -36,6 +36,7 @@ TEST(postgres, test_group_by) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Children { std::string last_name; diff --git a/tests/postgres/test_group_by_with_operations.cpp b/tests/postgres/test_group_by_with_operations.cpp index 04bc1b9..a1afe21 100644 --- a/tests/postgres/test_group_by_with_operations.cpp +++ b/tests/postgres/test_group_by_with_operations.cpp @@ -36,6 +36,7 @@ TEST(postgres, test_group_by) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Children { std::string last_name; diff --git a/tests/postgres/test_insert_and_read.cpp b/tests/postgres/test_insert_and_read.cpp index 380178a..f01c637 100644 --- a/tests/postgres/test_insert_and_read.cpp +++ b/tests/postgres/test_insert_and_read.cpp @@ -32,6 +32,7 @@ TEST(postgres, test_insert_and_read) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlgen::postgres::connect(credentials) .and_then(drop | if_exists) diff --git a/tests/postgres/test_insert_and_read_two_tables.cpp b/tests/postgres/test_insert_and_read_two_tables.cpp index cc453ce..8fbf05d 100644 --- a/tests/postgres/test_insert_and_read_two_tables.cpp +++ b/tests/postgres/test_insert_and_read_two_tables.cpp @@ -42,6 +42,7 @@ TEST(postgres, test_insert_and_read_two_tables) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlgen::postgres::connect(credentials) .and_then(drop | if_exists) diff --git a/tests/postgres/test_is_null.cpp b/tests/postgres/test_is_null.cpp index 760750f..b444d55 100644 --- a/tests/postgres/test_is_null.cpp +++ b/tests/postgres/test_is_null.cpp @@ -32,6 +32,7 @@ TEST(postgres, test_is_null) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = postgres::connect(credentials); diff --git a/tests/postgres/test_is_null_dry.cpp b/tests/postgres/test_is_null_dry.cpp index d015458..3e5258d 100644 --- a/tests/postgres/test_is_null_dry.cpp +++ b/tests/postgres/test_is_null_dry.cpp @@ -17,6 +17,7 @@ struct Person { TEST(postgres, test_is_null_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto sql = postgres::to_sql(sqlgen::read> | where("age"_c.is_null()) | diff --git a/tests/postgres/test_join.cpp b/tests/postgres/test_join.cpp index 116d37d..e05b66f 100644 --- a/tests/postgres/test_join.cpp +++ b/tests/postgres/test_join.cpp @@ -36,6 +36,7 @@ TEST(postgres, test_join) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto get_people = select_from( diff --git a/tests/postgres/test_joins_nested.cpp b/tests/postgres/test_joins_nested.cpp index 0182353..93b1421 100644 --- a/tests/postgres/test_joins_nested.cpp +++ b/tests/postgres/test_joins_nested.cpp @@ -48,6 +48,7 @@ TEST(postgres, test_joins_nested) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/postgres/test_joins_nested_grouped.cpp b/tests/postgres/test_joins_nested_grouped.cpp index 003195d..9a6841b 100644 --- a/tests/postgres/test_joins_nested_grouped.cpp +++ b/tests/postgres/test_joins_nested_grouped.cpp @@ -48,6 +48,7 @@ TEST(postgres, test_joins_nested_grouped) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/postgres/test_joins_two_tables.cpp b/tests/postgres/test_joins_two_tables.cpp index 7e5b917..5441684 100644 --- a/tests/postgres/test_joins_two_tables.cpp +++ b/tests/postgres/test_joins_two_tables.cpp @@ -48,6 +48,7 @@ TEST(postgres, test_joins_two_tables) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/postgres/test_joins_two_tables_grouped.cpp b/tests/postgres/test_joins_two_tables_grouped.cpp index 90c8eec..79b041c 100644 --- a/tests/postgres/test_joins_two_tables_grouped.cpp +++ b/tests/postgres/test_joins_two_tables_grouped.cpp @@ -48,6 +48,7 @@ TEST(postgres, test_joins_two_tables_grouped) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/postgres/test_like.cpp b/tests/postgres/test_like.cpp index 34a2d33..462a08d 100644 --- a/tests/postgres/test_like.cpp +++ b/tests/postgres/test_like.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_like) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = postgres::connect(credentials); diff --git a/tests/postgres/test_like_dry.cpp b/tests/postgres/test_like_dry.cpp index 6547d2e..a1ee612 100644 --- a/tests/postgres/test_like_dry.cpp +++ b/tests/postgres/test_like_dry.cpp @@ -17,6 +17,7 @@ struct Person { TEST(postgres, test_like_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto sql = postgres::to_sql(sqlgen::read> | diff --git a/tests/postgres/test_limit.cpp b/tests/postgres/test_limit.cpp index fac7a79..6934490 100644 --- a/tests/postgres/test_limit.cpp +++ b/tests/postgres/test_limit.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_limit) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_operations.cpp b/tests/postgres/test_operations.cpp index 635ddc4..ef33820 100644 --- a/tests/postgres/test_operations.cpp +++ b/tests/postgres/test_operations.cpp @@ -33,6 +33,7 @@ TEST(postgres, test_operations) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Children { int id_plus_age; diff --git a/tests/postgres/test_operations_with_nullable.cpp b/tests/postgres/test_operations_with_nullable.cpp index 5aedfdd..191f871 100644 --- a/tests/postgres/test_operations_with_nullable.cpp +++ b/tests/postgres/test_operations_with_nullable.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_operations_with_nullable) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Children { std::optional id_plus_age; diff --git a/tests/postgres/test_range.cpp b/tests/postgres/test_range.cpp index 92ea408..735b15a 100644 --- a/tests/postgres/test_range.cpp +++ b/tests/postgres/test_range.cpp @@ -36,6 +36,7 @@ TEST(postgres, test_range) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_range_select_from.cpp b/tests/postgres/test_range_select_from.cpp index cb054a7..9df60e5 100644 --- a/tests/postgres/test_range_select_from.cpp +++ b/tests/postgres/test_range_select_from.cpp @@ -36,6 +36,7 @@ TEST(postgres, test_range_select_from) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_select_from_with_timestamps.cpp b/tests/postgres/test_select_from_with_timestamps.cpp index 56a7f44..e0bb888 100644 --- a/tests/postgres/test_select_from_with_timestamps.cpp +++ b/tests/postgres/test_select_from_with_timestamps.cpp @@ -40,6 +40,7 @@ TEST(postgres, test_range_select_from_with_timestamps) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct Birthday { Date birthday; diff --git a/tests/postgres/test_select_from_with_to.cpp b/tests/postgres/test_select_from_with_to.cpp index 501f27c..df10210 100644 --- a/tests/postgres/test_select_from_with_to.cpp +++ b/tests/postgres/test_select_from_with_to.cpp @@ -36,6 +36,7 @@ TEST(postgres, test_range_select_from) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; struct FirstName { std::string first_name; diff --git a/tests/postgres/test_timestamp.cpp b/tests/postgres/test_timestamp.cpp index e7912d2..a955ef9 100644 --- a/tests/postgres/test_timestamp.cpp +++ b/tests/postgres/test_timestamp.cpp @@ -23,6 +23,7 @@ TEST(postgres, test_timestamp) { .ts = "2000-01-01 01:00:00"}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", .password = "password", diff --git a/tests/postgres/test_timestamp_with_tz.cpp b/tests/postgres/test_timestamp_with_tz.cpp index dc329bb..2abff86 100644 --- a/tests/postgres/test_timestamp_with_tz.cpp +++ b/tests/postgres/test_timestamp_with_tz.cpp @@ -23,6 +23,7 @@ TEST(postgres, test_timestamp_with_tz) { .ts = "2000-01-01 01:00:00+0000"}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto credentials = postgres::Credentials{.user = "postgres", .password = "password", diff --git a/tests/postgres/test_to_select_from2_dry.cpp b/tests/postgres/test_to_select_from2_dry.cpp index bb7e547..1bb3d15 100644 --- a/tests/postgres/test_to_select_from2_dry.cpp +++ b/tests/postgres/test_to_select_from2_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_to_select_from2_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = select_from("field1"_c.as<"field">(), diff --git a/tests/postgres/test_transaction.cpp b/tests/postgres/test_transaction.cpp index 8eef514..62ffdc9 100644 --- a/tests/postgres/test_transaction.cpp +++ b/tests/postgres/test_transaction.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_transaction) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_update.cpp b/tests/postgres/test_update.cpp index 2d8ed9e..a340240 100644 --- a/tests/postgres/test_update.cpp +++ b/tests/postgres/test_update.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_update) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_update_dry.cpp b/tests/postgres/test_update_dry.cpp index 1266282..957a05b 100644 --- a/tests/postgres/test_update_dry.cpp +++ b/tests/postgres/test_update_dry.cpp @@ -14,6 +14,7 @@ struct TestTable { TEST(postgres, test_update_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = update("field1"_c.set("Hello"), "nullable"_c.set("field1"_c)) | diff --git a/tests/postgres/test_varchar.cpp b/tests/postgres/test_varchar.cpp index 1e5c283..6f1367c 100644 --- a/tests/postgres/test_varchar.cpp +++ b/tests/postgres/test_varchar.cpp @@ -33,6 +33,7 @@ TEST(postgres, test_varchar) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_where.cpp b/tests/postgres/test_where.cpp index 4b00135..b1dbb82 100644 --- a/tests/postgres/test_where.cpp +++ b/tests/postgres/test_where.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_where) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_where_dry.cpp b/tests/postgres/test_where_dry.cpp index 6991da7..a90cef2 100644 --- a/tests/postgres/test_where_dry.cpp +++ b/tests/postgres/test_where_dry.cpp @@ -15,6 +15,7 @@ struct Person { TEST(postgres, test_where_dry) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and "first_name"_c != "Hugo") | diff --git a/tests/postgres/test_where_with_operations.cpp b/tests/postgres/test_where_with_operations.cpp index b24f39f..188f2c9 100644 --- a/tests/postgres/test_where_with_operations.cpp +++ b/tests/postgres/test_where_with_operations.cpp @@ -34,6 +34,7 @@ TEST(postgres, test_where_with_operations) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_where_with_timestamps.cpp b/tests/postgres/test_where_with_timestamps.cpp index 9875884..b6c7d0c 100644 --- a/tests/postgres/test_where_with_timestamps.cpp +++ b/tests/postgres/test_where_with_timestamps.cpp @@ -39,6 +39,7 @@ TEST(postgres, test_where_with_timestamps) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; using namespace std::literals::chrono_literals; const auto conn = diff --git a/tests/postgres/test_write_and_read.cpp b/tests/postgres/test_write_and_read.cpp index d45d980..cc96c77 100644 --- a/tests/postgres/test_write_and_read.cpp +++ b/tests/postgres/test_write_and_read.cpp @@ -32,6 +32,7 @@ TEST(postgres, test_write_and_read) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = postgres::connect(credentials).and_then(drop | if_exists); diff --git a/tests/postgres/test_write_and_read_curried.cpp b/tests/postgres/test_write_and_read_curried.cpp index a241ae3..de57bac 100644 --- a/tests/postgres/test_write_and_read_curried.cpp +++ b/tests/postgres/test_write_and_read_curried.cpp @@ -32,6 +32,7 @@ TEST(postgres, test_write_and_read_curried) { .dbname = "postgres"}; using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = postgres::connect(credentials) .and_then(drop | if_exists) diff --git a/tests/postgres/test_write_and_read_pool.cpp b/tests/postgres/test_write_and_read_pool.cpp index b80a809..c9e34c9 100644 --- a/tests/postgres/test_write_and_read_pool.cpp +++ b/tests/postgres/test_write_and_read_pool.cpp @@ -37,6 +37,7 @@ TEST(postgres, test_write_and_read_pool) { pool_config, credentials); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = session(pool) .and_then(drop | if_exists) diff --git a/tests/sqlite/test_aggregations.cpp b/tests/sqlite/test_aggregations.cpp index 2804c84..c993111 100644 --- a/tests/sqlite/test_aggregations.cpp +++ b/tests/sqlite/test_aggregations.cpp @@ -27,6 +27,7 @@ TEST(sqlite, test_aggregations) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Children { int num_children; diff --git a/tests/sqlite/test_aggregations_with_nullable.cpp b/tests/sqlite/test_aggregations_with_nullable.cpp index 83e9145..011c18e 100644 --- a/tests/sqlite/test_aggregations_with_nullable.cpp +++ b/tests/sqlite/test_aggregations_with_nullable.cpp @@ -26,6 +26,7 @@ TEST(sqlite, test_aggregations_with_nullable) { Person{.id = 3, .first_name = "Maggie", .last_name = "Simpson"}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Children { int num_children; diff --git a/tests/sqlite/test_alpha_numeric_query.cpp b/tests/sqlite/test_alpha_numeric_query.cpp index 50ef296..7d81871 100644 --- a/tests/sqlite/test_alpha_numeric_query.cpp +++ b/tests/sqlite/test_alpha_numeric_query.cpp @@ -18,6 +18,7 @@ struct Person { sqlgen::Result> get_people( const auto& _conn, const sqlgen::AlphaNumeric& _first_name) { using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("first_name"_c == _first_name); return query(_conn); diff --git a/tests/sqlite/test_auto_incr_primary_key.cpp b/tests/sqlite/test_auto_incr_primary_key.cpp index 8e8d312..83ecdb3 100644 --- a/tests/sqlite/test_auto_incr_primary_key.cpp +++ b/tests/sqlite/test_auto_incr_primary_key.cpp @@ -23,6 +23,7 @@ TEST(sqlite, test_auto_incr_primary_key) { Person{.first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlite::connect() .and_then(write(std::ref(people1))) diff --git a/tests/sqlite/test_create_index.cpp b/tests/sqlite/test_create_index.cpp index 057e7f5..607f01d 100644 --- a/tests/sqlite/test_create_index.cpp +++ b/tests/sqlite/test_create_index.cpp @@ -17,6 +17,7 @@ struct Person { TEST(sqlite, test_create_index) { using namespace sqlgen; + using namespace sqlgen::literals; const auto people = sqlgen::sqlite::connect() .and_then(create_table | if_not_exists) diff --git a/tests/sqlite/test_create_table.cpp b/tests/sqlite/test_create_table.cpp index 800a520..2c3d4f1 100644 --- a/tests/sqlite/test_create_table.cpp +++ b/tests/sqlite/test_create_table.cpp @@ -17,6 +17,7 @@ struct Person { TEST(sqlite, test_create_table) { using namespace sqlgen; + using namespace sqlgen::literals; const auto people = sqlgen::sqlite::connect() .and_then(create_table | if_not_exists) diff --git a/tests/sqlite/test_delete_from.cpp b/tests/sqlite/test_delete_from.cpp index 4ec5115..1771c1c 100644 --- a/tests/sqlite/test_delete_from.cpp +++ b/tests/sqlite/test_delete_from.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_delete_from) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = delete_from | where("first_name"_c == "Hugo"); diff --git a/tests/sqlite/test_drop.cpp b/tests/sqlite/test_drop.cpp index 74585e3..6f1d0b5 100644 --- a/tests/sqlite/test_drop.cpp +++ b/tests/sqlite/test_drop.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_drop) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = drop | if_exists; diff --git a/tests/sqlite/test_group_by.cpp b/tests/sqlite/test_group_by.cpp index 243a392..d37e0c2 100644 --- a/tests/sqlite/test_group_by.cpp +++ b/tests/sqlite/test_group_by.cpp @@ -27,6 +27,7 @@ TEST(sqlite, test_group_by) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Children { std::string last_name; diff --git a/tests/sqlite/test_group_by_with_operations.cpp b/tests/sqlite/test_group_by_with_operations.cpp index 833b80e..9dee485 100644 --- a/tests/sqlite/test_group_by_with_operations.cpp +++ b/tests/sqlite/test_group_by_with_operations.cpp @@ -27,6 +27,7 @@ TEST(sqlite, test_group_by_with_operations) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Children { std::string last_name; diff --git a/tests/sqlite/test_insert_and_read.cpp b/tests/sqlite/test_insert_and_read.cpp index 2964667..5608bd0 100644 --- a/tests/sqlite/test_insert_and_read.cpp +++ b/tests/sqlite/test_insert_and_read.cpp @@ -25,6 +25,7 @@ TEST(sqlite, test_insert_and_read) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlite::connect() .and_then(begin_transaction) diff --git a/tests/sqlite/test_insert_by_ref_and_read.cpp b/tests/sqlite/test_insert_by_ref_and_read.cpp index 85133d1..27ff638 100644 --- a/tests/sqlite/test_insert_by_ref_and_read.cpp +++ b/tests/sqlite/test_insert_by_ref_and_read.cpp @@ -25,6 +25,7 @@ TEST(sqlite, test_insert_by_ref_and_read) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlite::connect() .and_then(begin_transaction) diff --git a/tests/sqlite/test_is_null.cpp b/tests/sqlite/test_is_null.cpp index ba54173..e13af88 100644 --- a/tests/sqlite/test_is_null.cpp +++ b/tests/sqlite/test_is_null.cpp @@ -26,6 +26,7 @@ TEST(sqlite, test_is_null) { Person{.id = 4, .first_name = "Hugo", .last_name = "Simpson"}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlite::connect(); diff --git a/tests/sqlite/test_join.cpp b/tests/sqlite/test_join.cpp index 77263af..61df0f1 100644 --- a/tests/sqlite/test_join.cpp +++ b/tests/sqlite/test_join.cpp @@ -25,6 +25,7 @@ TEST(sqlite, test_join) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto get_people = select_from( diff --git a/tests/sqlite/test_joins_nested.cpp b/tests/sqlite/test_joins_nested.cpp index d794780..8f40e12 100644 --- a/tests/sqlite/test_joins_nested.cpp +++ b/tests/sqlite/test_joins_nested.cpp @@ -40,6 +40,7 @@ TEST(sqlite, test_joins_nested) { Relationship{.parent_id = 1, .child_id = 4}}); using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/sqlite/test_joins_nested_grouped.cpp b/tests/sqlite/test_joins_nested_grouped.cpp index 8f74fbd..b6fde52 100644 --- a/tests/sqlite/test_joins_nested_grouped.cpp +++ b/tests/sqlite/test_joins_nested_grouped.cpp @@ -40,6 +40,7 @@ TEST(sqlite, test_joins_nested_grouped) { Relationship{.parent_id = 1, .child_id = 4}}); using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/sqlite/test_joins_two_tables.cpp b/tests/sqlite/test_joins_two_tables.cpp index 678a59c..964c8dc 100644 --- a/tests/sqlite/test_joins_two_tables.cpp +++ b/tests/sqlite/test_joins_two_tables.cpp @@ -40,6 +40,7 @@ TEST(sqlite, test_joins_two_tables) { Relationship{.parent_id = 1, .child_id = 4}}); using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/sqlite/test_joins_two_tables_grouped.cpp b/tests/sqlite/test_joins_two_tables_grouped.cpp index 2dd836b..3495a8c 100644 --- a/tests/sqlite/test_joins_two_tables_grouped.cpp +++ b/tests/sqlite/test_joins_two_tables_grouped.cpp @@ -40,6 +40,7 @@ TEST(sqlite, test_joins_two_tables_grouped) { Relationship{.parent_id = 1, .child_id = 4}}); using namespace sqlgen; + using namespace sqlgen::literals; struct ParentAndChild { std::string last_name; diff --git a/tests/sqlite/test_like.cpp b/tests/sqlite/test_like.cpp index 5eff66a..ad66d8f 100644 --- a/tests/sqlite/test_like.cpp +++ b/tests/sqlite/test_like.cpp @@ -28,6 +28,7 @@ TEST(sqlite, test_like) { .id = 4, .first_name = "Hugo", .last_name = "Simpson", .age = 10}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlite::connect(); diff --git a/tests/sqlite/test_limit.cpp b/tests/sqlite/test_limit.cpp index 85b22f5..ffea054 100644 --- a/tests/sqlite/test_limit.cpp +++ b/tests/sqlite/test_limit.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_limit) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | order_by("age"_c) | limit(2); diff --git a/tests/sqlite/test_operations.cpp b/tests/sqlite/test_operations.cpp index 1a37061..796656a 100644 --- a/tests/sqlite/test_operations.cpp +++ b/tests/sqlite/test_operations.cpp @@ -27,6 +27,7 @@ TEST(sqlite, test_operations) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Children { int id_plus_age; diff --git a/tests/sqlite/test_operations_with_nullable.cpp b/tests/sqlite/test_operations_with_nullable.cpp index df80928..a5d5ad5 100644 --- a/tests/sqlite/test_operations_with_nullable.cpp +++ b/tests/sqlite/test_operations_with_nullable.cpp @@ -29,6 +29,7 @@ TEST(sqlite, test_operations_with_nullable) { .id = 4, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Children { std::optional id_plus_age; diff --git a/tests/sqlite/test_order_by.cpp b/tests/sqlite/test_order_by.cpp index 1b605bf..1c405af 100644 --- a/tests/sqlite/test_order_by.cpp +++ b/tests/sqlite/test_order_by.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_order_by) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | order_by("age"_c, "first_name"_c.desc()); diff --git a/tests/sqlite/test_range_select_from.cpp b/tests/sqlite/test_range_select_from.cpp index 396a90c..df9a4be 100644 --- a/tests/sqlite/test_range_select_from.cpp +++ b/tests/sqlite/test_range_select_from.cpp @@ -27,6 +27,7 @@ TEST(sqlite, test_range_select_from) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlgen::sqlite::connect() diff --git a/tests/sqlite/test_range_select_from_with_to.cpp b/tests/sqlite/test_range_select_from_with_to.cpp index 37d3f79..ef5c909 100644 --- a/tests/sqlite/test_range_select_from_with_to.cpp +++ b/tests/sqlite/test_range_select_from_with_to.cpp @@ -27,6 +27,7 @@ TEST(sqlite, test_range_select_from_with_to) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; struct FirstName { std::string first_name; diff --git a/tests/sqlite/test_select_from_with_timestamps.cpp b/tests/sqlite/test_select_from_with_timestamps.cpp index 76a3bcf..5c84359 100644 --- a/tests/sqlite/test_select_from_with_timestamps.cpp +++ b/tests/sqlite/test_select_from_with_timestamps.cpp @@ -33,6 +33,7 @@ TEST(sqlite, test_range_select_from_with_timestamps) { .birthday = sqlgen::Date("2010-01-01")}}); using namespace sqlgen; + using namespace sqlgen::literals; struct Birthday { Date birthday; diff --git a/tests/sqlite/test_single_read.cpp b/tests/sqlite/test_single_read.cpp index 742a964..77c96e9 100644 --- a/tests/sqlite/test_single_read.cpp +++ b/tests/sqlite/test_single_read.cpp @@ -29,6 +29,7 @@ TEST(sqlite, test_single_read) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = (sqlgen::read | where("id"_c == 0))(conn).value(); diff --git a/tests/sqlite/test_transaction.cpp b/tests/sqlite/test_transaction.cpp index dc027f2..23ffbca 100644 --- a/tests/sqlite/test_transaction.cpp +++ b/tests/sqlite/test_transaction.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_transaction) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto delete_hugo = delete_from | where("first_name"_c == "Hugo"); diff --git a/tests/sqlite/test_update.cpp b/tests/sqlite/test_update.cpp index 2cfed3d..65430aa 100644 --- a/tests/sqlite/test_update.cpp +++ b/tests/sqlite/test_update.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_update) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = update("first_name"_c.set("last_name"_c), "age"_c.set(100)) | diff --git a/tests/sqlite/test_where.cpp b/tests/sqlite/test_where.cpp index 8baef74..afde24d 100644 --- a/tests/sqlite/test_where.cpp +++ b/tests/sqlite/test_where.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_where) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and not("first_name"_c == "Hugo")) | diff --git a/tests/sqlite/test_where_with_nullable.cpp b/tests/sqlite/test_where_with_nullable.cpp index cfc7795..1b22587 100644 --- a/tests/sqlite/test_where_with_nullable.cpp +++ b/tests/sqlite/test_where_with_nullable.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_where_with_nullable) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c < 18 and "first_name"_c != "Hugo") | diff --git a/tests/sqlite/test_where_with_nullable_operations.cpp b/tests/sqlite/test_where_with_nullable_operations.cpp index 38bc22d..394111c 100644 --- a/tests/sqlite/test_where_with_nullable_operations.cpp +++ b/tests/sqlite/test_where_with_nullable_operations.cpp @@ -32,6 +32,7 @@ TEST(sqlite, test_where_with_nullable_operations) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c * 2 + 4 < 40 and "first_name"_c != "Hugo") | diff --git a/tests/sqlite/test_where_with_operations.cpp b/tests/sqlite/test_where_with_operations.cpp index f4eaf77..da7cb30 100644 --- a/tests/sqlite/test_where_with_operations.cpp +++ b/tests/sqlite/test_where_with_operations.cpp @@ -31,6 +31,7 @@ TEST(sqlite, test_where_with_operations) { sqlgen::write(conn, people1); using namespace sqlgen; + using namespace sqlgen::literals; const auto query = sqlgen::read> | where("age"_c * 2 + 4 < 40 and "first_name"_c != "Hugo") | diff --git a/tests/sqlite/test_where_with_timestamps.cpp b/tests/sqlite/test_where_with_timestamps.cpp index 066492d..e28391f 100644 --- a/tests/sqlite/test_where_with_timestamps.cpp +++ b/tests/sqlite/test_where_with_timestamps.cpp @@ -33,6 +33,7 @@ TEST(sqlite, test_where_with_timestamps) { .birthday = sqlgen::Date("2010-01-01")}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto conn = sqlgen::sqlite::connect(); diff --git a/tests/sqlite/test_write_and_read_curried.cpp b/tests/sqlite/test_write_and_read_curried.cpp index 6e20a72..002a3b7 100644 --- a/tests/sqlite/test_write_and_read_curried.cpp +++ b/tests/sqlite/test_write_and_read_curried.cpp @@ -26,6 +26,7 @@ TEST(sqlite, test_write_and_read_curried) { .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); using namespace sqlgen; + using namespace sqlgen::literals; const auto people2 = sqlite::connect() .and_then(write(std::ref(people1)))