added tests for sequence generator and table sequence pk generator
This commit is contained in:
parent
ee8ce62687
commit
3fc08fb7ff
|
|
@ -1,6 +1,7 @@
|
|||
#include "catch2/catch_test_macros.hpp"
|
||||
|
||||
#include "matador/query/query.hpp"
|
||||
#include "matador/query/sequence_pk_generator.hpp"
|
||||
|
||||
#include "SequenceFixture.hpp"
|
||||
|
||||
|
|
@ -34,3 +35,27 @@ TEST_CASE_METHOD(SequenceFixture, "test create and drop sequence", "[sequence][c
|
|||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SequenceFixture, "Test nextval and currval through sequence pk generator", "[sequence][nextval][currval]") {
|
||||
auto result = query::create()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
sequences_to_drop.emplace("person_seq");
|
||||
|
||||
sequence_pk_generator generator("person_seq");
|
||||
|
||||
auto pk_result = generator.next_id(db);
|
||||
REQUIRE(pk_result.is_ok());
|
||||
REQUIRE(*pk_result == 1);
|
||||
|
||||
pk_result = generator.current_id(db);
|
||||
REQUIRE(pk_result.is_ok());
|
||||
REQUIRE(*pk_result == 1);
|
||||
|
||||
result = query::drop()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "matador/query/expression/expression_operators.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
#include "matador/query/table_pk_generator.hpp"
|
||||
|
||||
#include "TableSequenceFixture.hpp"
|
||||
|
||||
|
|
@ -37,4 +38,24 @@ TEST_CASE_METHOD(TableSequenceFixture, "test create and drop table sequence", "[
|
|||
REQUIRE(id_result);
|
||||
REQUIRE(id_result->has_value());
|
||||
REQUIRE(id_result->value() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TableSequenceFixture, "Test nextval and currval through table sequence pk generator", "[table_sequence][nextval][currval]" ) {
|
||||
const auto next_id_col = "next_id"_col;
|
||||
auto result = query::query::insert()
|
||||
.into(sequence_table_name, { "name", next_id_col})
|
||||
.values({ "test_seq", 1 })
|
||||
.execute(db);
|
||||
REQUIRE(result);
|
||||
REQUIRE(result->affected_rows == 1);
|
||||
|
||||
table_pk_generator generator(sequence_table_name, "test_seq");
|
||||
|
||||
auto pk_result = generator.next_id(db);
|
||||
REQUIRE(pk_result.is_ok());
|
||||
REQUIRE(*pk_result == 1);
|
||||
|
||||
pk_result = generator.current_id(db);
|
||||
REQUIRE(pk_result.is_ok());
|
||||
REQUIRE(*pk_result == 2);
|
||||
}
|
||||
Loading…
Reference in New Issue