Skip to content

Commit 0b8d84f

Browse files
committed
WIP: pipeline mode
1 parent 6cffecb commit 0b8d84f

File tree

5 files changed

+59
-23
lines changed

5 files changed

+59
-23
lines changed

include/tao/pq/transaction.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ namespace tao::pq
3636
[[nodiscard]] auto subtransaction() -> std::shared_ptr< transaction >;
3737
[[nodiscard]] auto pipeline() -> std::shared_ptr< pq::pipeline >;
3838

39-
void set_single_row_mode();
40-
#if defined( LIBPQ_HAS_CHUNK_MODE )
41-
void set_chunk_mode( const int rows );
42-
#endif
43-
4439
template< parameter_type... As >
4540
auto execute( const internal::zsv statement, As&&... as )
4641
{

include/tao/pq/transaction_base.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ namespace tao::pq
135135
send_params( statement, p.m_size, p.m_types, p.m_values, p.m_lengths, p.m_formats );
136136
}
137137

138+
void set_single_row_mode();
139+
#if defined( LIBPQ_HAS_CHUNK_MODE )
140+
void set_chunk_mode( const int rows );
141+
#endif
142+
138143
[[nodiscard]] auto get_result( const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now() ) -> result;
139144
void consume_pipeline_sync( const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now() );
140145
};

src/lib/pq/transaction.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,6 @@ namespace tao::pq
128128
return std::make_shared< pq::pipeline >( m_connection );
129129
}
130130

131-
void transaction::set_single_row_mode()
132-
{
133-
check_current_transaction();
134-
if( PQsetSingleRowMode( m_connection->underlying_raw_ptr() ) == 0 ) {
135-
throw std::runtime_error( "unable to switch to single row mode" );
136-
}
137-
}
138-
139-
#if defined( LIBPQ_HAS_CHUNK_MODE )
140-
void transaction::set_chunk_mode( const int rows )
141-
{
142-
check_current_transaction();
143-
if( PQsetChunkedRowsMode( m_connection->underlying_raw_ptr(), rows ) == 0 ) {
144-
throw std::runtime_error( "unable to switch to chunk mode" );
145-
}
146-
}
147-
#endif
148-
149131
void transaction::commit()
150132
{
151133
check_current_transaction();

src/lib/pq/transaction_base.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ namespace tao::pq
4545
m_connection->send_params( statement, n_params, types, values, lengths, formats );
4646
}
4747

48+
void transaction_base::set_single_row_mode()
49+
{
50+
check_current_transaction();
51+
if( PQsetSingleRowMode( m_connection->underlying_raw_ptr() ) == 0 ) {
52+
throw std::runtime_error( "unable to switch to single row mode" );
53+
}
54+
}
55+
56+
#if defined( LIBPQ_HAS_CHUNK_MODE )
57+
void transaction_base::set_chunk_mode( const int rows )
58+
{
59+
check_current_transaction();
60+
if( PQsetChunkedRowsMode( m_connection->underlying_raw_ptr(), rows ) == 0 ) {
61+
throw std::runtime_error( "unable to switch to chunk mode" );
62+
}
63+
}
64+
#endif
65+
4866
auto transaction_base::get_result( const std::chrono::steady_clock::time_point start ) -> result
4967
{
5068
check_current_transaction();

src/test/pq/pipeline_mode.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,42 @@ namespace
132132

133133
pl->finish();
134134
}
135+
136+
{
137+
connection->execute( "DROP TABLE IF EXISTS tao_pipeline_mode" );
138+
connection->execute( "CREATE TABLE tao_pipeline_mode ( name TEXT PRIMARY KEY, age INTEGER NOT NULL )" );
139+
140+
connection->prepare( "insert_user", "INSERT INTO tao_pipeline_mode ( name, age ) VALUES ( $1, $2 )" );
141+
142+
auto pl = connection->pipeline();
143+
144+
pl->send( "insert_user", "Daniel", 42 );
145+
pl->send( "insert_user", "Tom", 41 );
146+
pl->send( "insert_user", "Jerry", 29 );
147+
pl->sync();
148+
149+
TEST_ASSERT( pl->get_result().rows_affected() == 1 ); // daniel
150+
TEST_ASSERT( pl->get_result().rows_affected() == 1 ); // tom
151+
TEST_ASSERT( pl->get_result().rows_affected() == 1 ); // jerry
152+
TEST_EXECUTE( pl->consume_sync() );
153+
154+
pl->send( "SELECT name, age FROM tao_pipeline_mode" );
155+
pl->send( "SELECT name, age FROM tao_pipeline_mode" );
156+
pl->sync();
157+
158+
pl->set_single_row_mode();
159+
160+
TEST_ASSERT( pl->get_result().size() == 1 );
161+
TEST_ASSERT( pl->get_result().size() == 1 );
162+
TEST_ASSERT( pl->get_result().size() == 1 );
163+
TEST_ASSERT( pl->get_result().empty() );
164+
165+
TEST_ASSERT( pl->get_result().size() == 3 );
166+
167+
TEST_EXECUTE( pl->consume_sync() );
168+
169+
pl->finish();
170+
}
135171
}
136172

137173
} // namespace

0 commit comments

Comments
 (0)