diff --git a/docs/database/migrations.mdx b/docs/database/migrations.mdx index ebbe19a20..581df6a17 100644 --- a/docs/database/migrations.mdx +++ b/docs/database/migrations.mdx @@ -1299,7 +1299,7 @@ Schema::table("users", [](Blueprint &table) }); ``` -You may drop multiple columns from a table by passing a `QVector` of column names to the `dropColumns` method, the `dropColumns` method also provides parameter pack overload: +You may drop multiple columns from a table by passing a `QList` of column names to the `dropColumns` method, the `dropColumns` method also provides parameter pack overload: ```cpp Schema::table("users", [](Blueprint &table) @@ -1349,7 +1349,7 @@ Alternatively, you may create the index after defining the column. To do so, you table.unique("email"); ``` -You may even pass a `QVector` of columns to an index method to create a compound (or composite) index: +You may even pass a `QList` of columns to an index method to create a compound (or composite) index: ```cpp table.index({"account_id", "created_at"}); @@ -1415,7 +1415,7 @@ To drop an index, you must specify the index's name. By default, TinyORM automat -I may also drop indexes by a column name or column names for composite keys, if you pass a `QVector` of columns into a method that drops indexes, the conventional index name will be generated based on the table name, columns, and index type: +I may also drop indexes by a column name or column names for composite keys, if you pass a `QList` of columns into a method that drops indexes, the conventional index name will be generated based on the table name, columns, and index type: ```cpp Schema::table("geo", [](Blueprint &table) @@ -1498,7 +1498,7 @@ To drop a foreign key, you may use the `dropForeign` method, passing the name of table.dropForeign("posts_user_id_foreign"); ``` -Alternatively, you may pass a `QVector` containing the column name that holds the foreign key to the `dropForeign` method. The `QVector` will be converted to a foreign key constraint name using TinyORM's constraint naming conventions: +Alternatively, you may pass a `QList` containing the column name that holds the foreign key to the `dropForeign` method. The `QList` will be converted to a foreign key constraint name using TinyORM's constraint naming conventions: ```cpp table.dropForeign({"user_id"}); diff --git a/docs/database/query-builder.mdx b/docs/database/query-builder.mdx index f33bebd73..6f7098af2 100644 --- a/docs/database/query-builder.mdx +++ b/docs/database/query-builder.mdx @@ -109,7 +109,7 @@ user.value("email").toString(); #### Retrieving A List Of Column Values -If you would like to retrieve the `QVector` instance containing the values of a single column, you may use the `pluck` method. In this example, we'll retrieve a collection of user titles: +If you would like to retrieve the `QList` instance containing the values of a single column, you may use the `pluck` method. In this example, we'll retrieve a collection of user titles: ```cpp #include @@ -467,7 +467,7 @@ auto users = DB::table("users") .get(); ``` -You may also pass a `QVector` of conditions to the `where` function. Each `Orm::WhereItem` structure should contain the four arguments typically passed to the `where` method: +You may also pass a `QList` of conditions to the `where` function. Each `Orm::WhereItem` structure should contain the four arguments typically passed to the `where` method: ```cpp auto users = DB::table("users") @@ -509,7 +509,7 @@ select * from users where votes > 100 or (name = "Abigail" and votes > 50) ``` ### Condition Operator Overriding -The `where` method overload with a `QVector` as the first argument joins conditions using the `and` operator by default: +The `where` method overload with a `QList` as the first argument joins conditions using the `and` operator by default: ```cpp auto users = DB::table("users") @@ -608,7 +608,7 @@ auto files = DB::table("files") **whereIn / whereNotIn / orWhereIn / orWhereNotIn** -The `whereIn` method verifies that a given column's value is contained within the given `QVector`: +The `whereIn` method verifies that a given column's value is contained within the given `QList`: ```cpp auto users = DB::table("users") @@ -616,7 +616,7 @@ auto users = DB::table("users") .get(); ``` -The `whereNotIn` method verifies that the given column's value is not contained in the given `QVector`: +The `whereNotIn` method verifies that the given column's value is not contained in the given `QList`: ```cpp auto users = DB::table("users") @@ -710,7 +710,7 @@ auto users = DB::table("users") .get(); ``` -You may also pass a `QVector` of column comparisons to the `whereColumn` method. These conditions will be joined using the `and` operator: +You may also pass a `QList` of column comparisons to the `whereColumn` method. These conditions will be joined using the `and` operator: ```cpp auto users = DB::table("users") @@ -956,7 +956,7 @@ DB::table("users")->insert({ -You may insert several records at once by passing a `QVector` for column names as the first argument and `QVector>` for values as the second argument. Each `QVector` represents a record that should be inserted into the table. This overload is useful for multi-insert and allows to specify column names only once: +You may insert several records at once by passing a `QList` for column names as the first argument and `QList>` for values as the second argument. Each `QList` represents a record that should be inserted into the table. This overload is useful for multi-insert and allows to specify column names only once: ```cpp DB::table("users")->insert({"email", "votes"}, @@ -966,7 +966,7 @@ DB::table("users")->insert({"email", "votes"}, }); ``` -You may also insert several records at once by passing a `QVector`. Each `QVariantMap` represents a record that should be inserted into the table: +You may also insert several records at once by passing a `QList`. Each `QVariantMap` represents a record that should be inserted into the table: ```cpp DB::table("users")->insert({ @@ -1026,7 +1026,7 @@ Row and column aliases will be used with the MySQL server >=8.0.19 instead of th ## Update Statements -In addition to inserting records into the database, the query builder can also update existing records using the `update` method. The `update` method, accepts a `QVector` of column and value pairs, indicating the columns to be updated and returns a `std::tuple` . You may constrain the `update` query using `where` clauses: +In addition to inserting records into the database, the query builder can also update existing records using the `update` method. The `update` method, accepts a `QList` of column and value pairs, indicating the columns to be updated and returns a `std::tuple` . You may constrain the `update` query using `where` clauses: ```cpp auto [affected, query] = DB::table("users") @@ -1066,7 +1066,7 @@ DB::table("users")->decrement("votes"); DB::table("users")->decrement("votes", 5.2); // float or double type ``` -You may also specify additional columns to update during the operation as a `QVector`: +You may also specify additional columns to update during the operation as a `QList`: ```cpp DB::table("users")->increment("votes", 1, {{"name", "John"}}); diff --git a/docs/tinyorm/collections.mdx b/docs/tinyorm/collections.mdx index 0782dad82..2a4ac1050 100644 --- a/docs/tinyorm/collections.mdx +++ b/docs/tinyorm/collections.mdx @@ -15,13 +15,13 @@ keywords: [c++ orm, orm, collections, collection, model, tinyorm] The `Orm::Tiny::Types::ModelsCollection` is specialized container which provides a fluent, convenient wrapper for working with vector of models. All TinyORM methods that return more than one model result, will return instances of the `ModelsCollection` class, including results retrieved via the `get` method or methods that return relationships like the `getRelation` and `getRelationValue`. -The `ModelsCollection` class extends `QVector`, so it naturally inherits dozens of methods used to work with the underlying vector of TinyORM models. Be sure to review the [`QList`](https://doc.qt.io/qt/qlist.html) documentation to learn all about these helpful methods! +The `ModelsCollection` class extends `QList`, so it naturally inherits dozens of methods used to work with the underlying vector of TinyORM models. Be sure to review the [`QList`](https://doc.qt.io/qt/qlist.html) documentation to learn all about these helpful methods! :::info The `ModelsCollection` template parameter can be declared only with the model type or a model type pointer, it also can't be `const` and can't be a reference. It's constrained using the `DerivedCollectionModel` concept. ::: -You can iterate over the `ModelsCollection` the same way as over the `QVector`: +You can iterate over the `ModelsCollection` the same way as over the `QList`: ```cpp using Models::User; @@ -50,7 +50,7 @@ The `ModelsCollection` is returning from the Models' methods like `get`, #### Collection Conversion -While most TinyORM collection methods return a new instance of `ModelsCollection`, the `modelKeys`, `mapWithKeys`, and `pluck` methods return a base QVector or std unordered/map instances. Likewise, one of the `map` methods overload returns the `QVector`. +While most TinyORM collection methods return a new instance of `ModelsCollection`, the `modelKeys`, `mapWithKeys`, and `pluck` methods return a base QList or std unordered/map instances. Likewise, one of the `map` methods overload returns the `QList`. ### Creating Collections @@ -71,10 +71,10 @@ ModelsCollection userPointers { }; ``` -The `ModelsCollection` is implicitly convertible and assignable from the `QVector`: +The `ModelsCollection` is implicitly convertible and assignable from the `QList`: ```cpp -QVector usersVector { +QList usersVector { {{"name", "Kate"}, {"votes", 150}}, {{"name", "John"}, {"votes", 200}}, }; @@ -174,7 +174,7 @@ For a better understanding of the following examples, many of the variable decla The `all` method returns a copy of the underlying vector represented by the collection: ```cpp -QVector = users.all(); +QList = users.all(); ``` :::note @@ -541,10 +541,10 @@ auto usersAdded = users.map([](User &&userCopy) */ ``` -The second `map` overload allows to return the `QVector`: +The second `map` overload allows to return the `QList`: ```cpp -QVector usersAdded = users.map([](User &&userCopy) +QList usersAdded = users.map([](User &&userCopy) { const auto votesRef = userCopy["votes"]; @@ -616,7 +616,7 @@ ModelsCollection users { {{"id", 5}, {"name", "Rose"}}, }; -users.modelKeys(); // Returns QVector +users.modelKeys(); // Returns QList users.modelKeys(); // {1, 2, 3, 5} @@ -638,7 +638,7 @@ For the inverse of `only`, see the [except](#method-except) method. #### `pluck()` {#method-pluck} -The `pluck` method retrieves all of the values for a given column, the following overload returns the `QVector`: +The `pluck` method retrieves all of the values for a given column, the following overload returns the `QList`: ```cpp ModelsCollection products { @@ -651,7 +651,7 @@ auto plucked = products.pluck("name"); // {Desk, Chair} ``` -The second overload allows returning the custom type `QVector`: +The second overload allows returning the custom type `QList`: ```cpp auto plucked = products.pluck("name"); @@ -915,7 +915,7 @@ It can be also called on `ModelsCollection` rvalues, it returns an rvalue refere The `toBase` method returns a copy of the underlying vector represented by the collection: ```cpp -QVector = users.toBase(); +QList = users.toBase(); ``` :::note @@ -942,13 +942,13 @@ The `toJsonDocument` method converts the collection of models with all nested re #### `toMap()` {#method-tomap} -The `toMap` method converts the collection of models with all nested relations into an attributes map `QVector`. +The `toMap` method converts the collection of models with all nested relations into an attributes map `QList`. It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. #### `toMapVariantList()` {#method-tomapvariantlist} -The `toMapVariantList` method converts the collection of models with all nested relations into an attributes map, but it returns the `QVariantList` instead of the `QVector`. +The `toMapVariantList` method converts the collection of models with all nested relations into an attributes map, but it returns the `QVariantList` instead of the `QList`. It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. @@ -972,13 +972,13 @@ users.toQuery()->update({ #### `toList()` {#method-tolist} -The `toList` method converts the collection of models with all nested relations into an attributes vector `QVector>`. +The `toList` method converts the collection of models with all nested relations into an attributes vector `QList>`. It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. #### `toListVariantList()` {#method-tolistvariantlist} -The `toListVariantList` method converts the collection of models with all nested relations into an attributes vector, but it returns the `QVariantList` instead of the `QVector>`. +The `toListVariantList` method converts the collection of models with all nested relations into an attributes vector, but it returns the `QVariantList` instead of the `QList>`. It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. diff --git a/docs/tinyorm/getting-started.mdx b/docs/tinyorm/getting-started.mdx index ec1bf5053..e5d665f54 100644 --- a/docs/tinyorm/getting-started.mdx +++ b/docs/tinyorm/getting-started.mdx @@ -378,7 +378,7 @@ class Flight final : public Model private: /*! The model's default values for attributes. */ - inline static const QVector u_attributes { + inline static const QList u_attributes { {"delayed", false}, {"progress", 0}, {"added_on", QDateTime::currentDateTimeUtc()}, @@ -454,7 +454,7 @@ flight->getAttribute("number"); // "FR 900" ### Containers -As we have seen, TinyORM methods like `all` and `get` retrieve multiple records from the database. Since these methods return a `QVector`, you can iterate it like any other container with the [Range-based for loop](https://en.cppreference.com/w/cpp/language/range-for), [STL-Style Iterators](https://doc.qt.io/qt/containers.html#stl-style-iterators), [Java-Style Iterators](https://doc.qt.io/qt/containers.html#java-style-iterators) or [Ranges](https://www.walletfox.com/course/quickref_range_v3.php). +As we have seen, TinyORM methods like `all` and `get` retrieve multiple records from the database. Since these methods return a `QList`, you can iterate it like any other container with the [Range-based for loop](https://en.cppreference.com/w/cpp/language/range-for), [STL-Style Iterators](https://doc.qt.io/qt/containers.html#stl-style-iterators), [Java-Style Iterators](https://doc.qt.io/qt/containers.html#java-style-iterators) or [Ranges](https://www.walletfox.com/course/quickref_range_v3.php). ```cpp #include @@ -476,7 +476,7 @@ Your application may run out of memory if you attempt to load tens of thousands The `chunk` method will retrieve a subset of TinyORM models, passing them to a lambda expression for processing. Since only the current chunk of TinyORM models is retrieved at a time, the `chunk` method will provide significantly reduced memory usage when working with a large number of models: ```cpp -Flight::chunk(200, [](QVector &&flights, const int /*unused*/) +Flight::chunk(200, [](QList &&flights, const int /*unused*/) { for (auto &&flight : flights) { // @@ -492,7 +492,7 @@ If you are filtering the results of the `chunk` method based on a column that yo ```cpp Flight::whereEq("departed", true) - ->chunkById(200, [](QVector &&flights, const int /*unused*/) + ->chunkById(200, [](QList &&flights, const int /*unused*/) { for (auto &&flight : flights) flight.update({{"departed", false}}); @@ -575,7 +575,7 @@ auto flight = Flight::findOr>(1, [] { }); ``` -To obtain only a subset of the model's attributes you may use the `Model::only` method, it returns the `QVector`: +To obtain only a subset of the model's attributes you may use the `Model::only` method, it returns the `QList`: ```cpp #include "models/flight.hpp" @@ -600,7 +600,7 @@ auto flight = Flight::where("legs", ">", 3)->firstOrFail(); ### Retrieving Or Creating Models -The `firstOrCreate` method will attempt to locate a database record using the given column / value pairs. If the model can not be found in the database, a record will be inserted with the attributes resulting from merging the first `QVector` argument with the optional second `QVector` argument: +The `firstOrCreate` method will attempt to locate a database record using the given column / value pairs. If the model can not be found in the database, a record will be inserted with the attributes resulting from merging the first `QList` argument with the optional second `QList` argument: The `firstOrNew` method, like `firstOrCreate`, will attempt to locate a record in the database matching the given attributes. However, if a model is not found, a new model instance will be returned. Note that the model returned by `firstOrNew` has not yet been persisted to the database. You will need to manually call the `save` method to persist it: @@ -693,7 +693,7 @@ Flight::whereEq("active", 1) .update({{"delayed", 1}}); ``` -The `update` method expects the `QVector` of column and value pairs representing the columns that should be updated. +The `update` method expects the `QList` of column and value pairs representing the columns that should be updated. #### Examining Attribute Changes diff --git a/docs/tinyorm/relationships.mdx b/docs/tinyorm/relationships.mdx index b0725ecac..de3757381 100644 --- a/docs/tinyorm/relationships.mdx +++ b/docs/tinyorm/relationships.mdx @@ -269,7 +269,7 @@ private: Remember, TinyORM will automatically determine the proper foreign key column for the `Comment` model. By convention, TinyORM will take the "snake_case" name of the parent model and suffix it with `_id`. So, in this example, TinyORM will assume the foreign key column on the `Comment` model is `post_id`. -Once the relationship method has been defined, we can access the `QVector` of related comments by Model's `getRelationValue` method: +Once the relationship method has been defined, we can access the `QList` of related comments by Model's `getRelationValue` method: ```cpp #include "models/post.hpp" @@ -482,7 +482,7 @@ private: #endif // USER_HPP ``` -Once the relationship is defined, you may access the user's roles as the `QVector` by Model's `getRelationValue` method: +Once the relationship is defined, you may access the user's roles as the `QList` by Model's `getRelationValue` method: ```cpp #include @@ -907,7 +907,7 @@ As described above TinyORM offers two methods to access relationships; `getRelat The `getRelation` method is for "eager loaded" relations, when the relationship is not loaded, it throws the exception `RelationNotLoadedError`. The `getRelationValue` is for "lazy loading", when the relationship is not loaded, it will load it. -Both methods have two overloads, the `getRelation` overload is for obtaining many type relationships: +Both methods have two overloads, the `getRelation` overload is for obtaining many type relationships: ```cpp auto posts = User::find(1)->getRelation("posts"); @@ -1071,7 +1071,7 @@ select * from authors where id in (1, 2, 3, 4, 5, ...) #### Eager Loading Multiple Relationships -Sometimes you may need to eager load several different relationships. To do so, just pass a `QVector` of relationships to the `with` method: +Sometimes you may need to eager load several different relationships. To do so, just pass a `QList` of relationships to the `with` method: ```cpp auto books = Book::with({"author", "publisher"})->get(); @@ -1124,7 +1124,7 @@ private: }; /*! The relationships that should always be loaded. */ - QVector u_with { + QList u_with { "author", }; }; @@ -1144,7 +1144,7 @@ auto books = Book::withOnly("genre")->get(); ### Constraining Eager Loads -Sometimes you may wish to eager load a relationship but also specify additional query conditions for the eager loading query. You can accomplish this by passing a `QVector` of relationships to the `with` method where the `name` data member of `Orm::WithItem` struct is a relationship name and the `constraints` data member expects a lambda expression that adds additional constraints to the eager loading query. The first argument passed to the `constraints` lambda expression is an underlying `Orm::QueryBuilder` for a related model: +Sometimes you may wish to eager load a relationship but also specify additional query conditions for the eager loading query. You can accomplish this by passing a `QList` of relationships to the `with` method where the `name` data member of `Orm::WithItem` struct is a relationship name and the `constraints` data member expects a lambda expression that adds additional constraints to the eager loading query. The first argument passed to the `constraints` lambda expression is an underlying `Orm::QueryBuilder` for a related model: ```cpp #include "models/user.hpp" @@ -1181,7 +1181,7 @@ if (someCondition) book->load("author"); ``` -You may load more relationships at once, to do so, just pass a `QVector` of relationships to the `load` method: +You may load more relationships at once, to do so, just pass a `QList` of relationships to the `load` method: ```cpp Book::find(1)->load({"author", "publisher"}); @@ -1191,7 +1191,7 @@ Book::find(1)->load({"author", "publisher"}); So far, this only works on models, not on containers returned from Model's `get` or `all` methods. ::: -If you need to set additional query constraints on the eager loading query, you may pass a `QVector` of relationships to the `load` method where the `name` data member of `Orm::WithItem` struct is a relationship name and the `constraints` data member expects a lambda expression that adds additional constraints to the eager loading query. The first argument passed to the `constraints` lambda expression is an underlying `Orm::QueryBuilder` for a related model: +If you need to set additional query constraints on the eager loading query, you may pass a `QList` of relationships to the `load` method where the `name` data member of `Orm::WithItem` struct is a relationship name and the `constraints` data member expects a lambda expression that adds additional constraints to the eager loading query. The first argument passed to the `constraints` lambda expression is an underlying `Orm::QueryBuilder` for a related model: ```cpp author->load({{"books", [](auto &query) @@ -1281,7 +1281,7 @@ post->push(); ### The `create` Method -In addition to the `save` and `saveMany` methods, you may also use the `create` method, which accepts a vector of attributes, creates a model, and inserts it into the database. The difference between `save` and `create` is that `save` accepts a full TinyORM model instance while `create` accepts a `QVector`. The newly created model will be returned by the `create` method: +In addition to the `save` and `saveMany` methods, you may also use the `create` method, which accepts a vector of attributes, creates a model, and inserts it into the database. The difference between `save` and `create` is that `save` accepts a full TinyORM model instance while `create` accepts a `QList`. The newly created model will be returned by the `create` method: ```cpp #include "models/post.hpp"