Skip to content

Commit

Permalink
Merge pull request #193 from LASTRADA-Software/feature/DataMapper-ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut authored Jan 30, 2025
2 parents 9e34c67 + dfa1d22 commit f0f7c1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Lightweight/DataMapper/DataMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ auto ToSharedPtrList(Container<Object, Allocator<Object>> container)

/// @brief Main API for mapping records to and from the database using high level C++ syntax.
///
/// A DataMapper instances operates on a single SQL connection and provides methods to
/// create, read, update and delete records in the database.
///
/// @see Field, BelongsTo, HasMany, HasManyThrough, HasOneThrough
/// @ingroup DataMapper
class DataMapper
Expand All @@ -82,6 +85,13 @@ class DataMapper
{
}

/// Constructs a new data mapper, using the given connection string.
explicit DataMapper(SqlConnectionString connectionString):
_connection { std::move(connectionString) },
_stmt { _connection }
{
}

DataMapper(DataMapper const&) = delete;
DataMapper(DataMapper&&) noexcept = default;
DataMapper& operator=(DataMapper const&) = delete;
Expand Down
6 changes: 6 additions & 0 deletions src/tests/DataMapperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ struct PersonName
static constexpr std::string_view TableName = RecordTableName<Person>;
};

TEST_CASE_METHOD(SqlTestFixture, "Constructor with connection string", "[DataMapper]")
{
auto dm = DataMapper(SqlConnection::DefaultConnectionString());
dm.CreateTable<Person>();
}

TEST_CASE_METHOD(SqlTestFixture, "CRUD", "[DataMapper]")
{
auto dm = DataMapper();
Expand Down

0 comments on commit f0f7c1c

Please sign in to comment.