Skip to content

Commit 27eab1e

Browse files
committed
Add connection pool support
1 parent 0d099e2 commit 27eab1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5057
-28
lines changed

Docs/API/Classes.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,72 @@ <h4>Declaration</h4>
139139
</li>
140140
</ul>
141141
</div>
142+
<div class="task-group">
143+
<ul>
144+
<li class="item">
145+
<div>
146+
<code>
147+
<a name="/s:17PostgresClientKit14ConnectionPoolC"></a>
148+
<a name="//apple_ref/swift/Class/ConnectionPool" class="dashAnchor"></a>
149+
<a class="token" href="#/s:17PostgresClientKit14ConnectionPoolC">ConnectionPool</a>
150+
</code>
151+
</div>
152+
<div class="height-container">
153+
<div class="pointer-container"></div>
154+
<section class="section">
155+
<div class="pointer"></div>
156+
<div class="abstract">
157+
<p>A pool of re-usable, interchangeable <code><a href="Classes/Connection.html">Connection</a></code> instances.</p>
158+
159+
<p>Using a <code>ConnectionPool</code> allows an application to acquire an existing <code><a href="Classes/Connection.html">Connection</a></code> from the
160+
pool, use that connection to perform one or more SQL statements, and then release it for use
161+
elsewhere in the application.</p>
162+
163+
<p>The <code><a href="Structs/ConnectionPoolConfiguration.html">ConnectionPoolConfiguration</a></code> used to create a <code>ConnectionPool</code> specifies the number of
164+
connections in the pool, how long a request for a connection will wait for a connection to
165+
become available, and other characteristics of the pool.</p>
166+
167+
<p>All connections in a <code>ConnectionPool</code> are created from the same <code><a href="Structs/ConnectionConfiguration.html">ConnectionConfiguration</a></code>.
168+
They also have the same <code><a href="Protocols/ConnectionDelegate.html">ConnectionDelegate</a></code> (if a delegate is specified). Consequently
169+
any connection in a pool is interchangeable with any other.</p>
170+
171+
<p>Use <code><a href="Classes/ConnectionPool.html#/s:17PostgresClientKit14ConnectionPoolC07acquireD017completionHandleryys6ResultOyAA0D0Cs5Error_pGc_tF">ConnectionPool.acquireConnection(completionHandler:)</a></code> to request a connection from a
172+
<code>ConnectionPool</code>. This method is non-blocking: its completion handler is asynchronously
173+
executed when a connection is successfully allocated to the request or if an error occurs.
174+
To release the connection back to the pool, call <code><a href="Classes/ConnectionPool.html#/s:17PostgresClientKit14ConnectionPoolC07releaseD0yyAA0D0CF">ConnectionPool.releaseConnection(_:)</a></code>.</p>
175+
176+
<p>Alternately, use <code><a href="Classes/ConnectionPool.html#/s:17PostgresClientKit14ConnectionPoolC04withD017completionHandleryys6ResultOyAA0D0Cs5Error_pGc_tF">ConnectionPool.withConnection(completionHandler:)</a></code> to acquire a connection
177+
that is automatically released after execution of the completion handler.</p>
178+
179+
<p>When a connection is released to a <code>ConnectionPool</code>, there should be no transaction underway.
180+
Pair each SQL <code>BEGIN</code> command with either a <code>COMMIT</code> or <code>ROLLBACK</code> command (or equivalently,
181+
use the <code><a href="Classes/Connection.html#/s:17PostgresClientKit10ConnectionC16beginTransactionyyKF">Connection.beginTransaction()</a></code>, <code><a href="Classes/Connection.html#/s:17PostgresClientKit10ConnectionC17commitTransactionyyKF">Connection.commitTransaction()</a></code>, and
182+
<code><a href="Classes/Connection.html#/s:17PostgresClientKit10ConnectionC19rollbackTransactionyyKF">Connection.rollbackTransaction()</a></code> methods).</p>
183+
184+
<p>In general, do not close a <code><a href="Classes/Connection.html">Connection</a></code> acquired from a <code>ConnectionPool</code>. If a connection is
185+
closed (whether explicitly or because of an unrecoverable error) then, when that connection is
186+
released, it will be discarded from the pool, allowing a new connection to be created and added
187+
to the pool.</p>
188+
189+
<p>The <code>ConnectionPool</code> class is threadsafe: multiple threads may concurrently operate against a
190+
<code>ConnectionPool</code> instance. Connections acquired from the pool are subject to the threadsafety
191+
constraints described by the API documentation for <code><a href="Classes/Connection.html">Connection</a></code>.</p>
192+
193+
<a href="Classes/ConnectionPool.html" class="slightly-smaller">See more</a>
194+
</div>
195+
<div class="declaration">
196+
<h4>Declaration</h4>
197+
<div class="language">
198+
<p class="aside-title">Swift</p>
199+
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">ConnectionPool</span></code></pre>
200+
201+
</div>
202+
</div>
203+
</section>
204+
</div>
205+
</li>
206+
</ul>
207+
</div>
142208
<div class="task-group">
143209
<ul>
144210
<li class="item">
@@ -350,6 +416,9 @@ <h4>Declaration</h4>
350416
<li class="nav-group-task">
351417
<a href="Classes/Connection.html">Connection</a>
352418
</li>
419+
<li class="nav-group-task">
420+
<a href="Classes/ConnectionPool.html">ConnectionPool</a>
421+
</li>
353422
<li class="nav-group-task">
354423
<a href="Classes/ConsoleLogHandler.html">ConsoleLogHandler</a>
355424
</li>
@@ -424,6 +493,12 @@ <h4>Declaration</h4>
424493
<li class="nav-group-task">
425494
<a href="Structs/ConnectionConfiguration.html">ConnectionConfiguration</a>
426495
</li>
496+
<li class="nav-group-task">
497+
<a href="Structs/ConnectionPoolConfiguration.html">ConnectionPoolConfiguration</a>
498+
</li>
499+
<li class="nav-group-task">
500+
<a href="Structs/ConnectionPoolMetrics.html">ConnectionPoolMetrics</a>
501+
</li>
427502
<li class="nav-group-task">
428503
<a href="Structs/LogRecord.html">LogRecord</a>
429504
</li>

Docs/API/Classes/Connection.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,39 @@ <h4>Declaration</h4>
306306
</section>
307307
</div>
308308
</li>
309+
<li class="item">
310+
<div>
311+
<code>
312+
<a name="/s:17PostgresClientKit10ConnectionC13closeAbruptlyyyF"></a>
313+
<a name="//apple_ref/swift/Method/closeAbruptly()" class="dashAnchor"></a>
314+
<a class="token" href="#/s:17PostgresClientKit10ConnectionC13closeAbruptlyyyF">closeAbruptly()</a>
315+
</code>
316+
</div>
317+
<div class="height-container">
318+
<div class="pointer-container"></div>
319+
<section class="section">
320+
<div class="pointer"></div>
321+
<div class="abstract">
322+
<p>Closes this <code>Connection</code> abruptly.</p>
323+
324+
<p>Unlike <code><a href="../Classes/Connection.html#/s:17PostgresClientKit10ConnectionC5closeyyF">close()</a></code>, this method does not send a <q>terminate</q> request to the Postgres server;
325+
it simply closes the network socket.</p>
326+
327+
<p>Use this method to force a connection to immediately close, even if another thread is
328+
concurrently operating against the connection.</p>
329+
330+
</div>
331+
<div class="declaration">
332+
<h4>Declaration</h4>
333+
<div class="language">
334+
<p class="aside-title">Swift</p>
335+
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">closeAbruptly</span><span class="p">()</span></code></pre>
336+
337+
</div>
338+
</div>
339+
</section>
340+
</div>
341+
</li>
309342
</ul>
310343
</div>
311344
<div class="task-group">
@@ -540,6 +573,9 @@ <h4>Declaration</h4>
540573
<li class="nav-group-task">
541574
<a href="../Classes/Connection.html">Connection</a>
542575
</li>
576+
<li class="nav-group-task">
577+
<a href="../Classes/ConnectionPool.html">ConnectionPool</a>
578+
</li>
543579
<li class="nav-group-task">
544580
<a href="../Classes/ConsoleLogHandler.html">ConsoleLogHandler</a>
545581
</li>
@@ -614,6 +650,12 @@ <h4>Declaration</h4>
614650
<li class="nav-group-task">
615651
<a href="../Structs/ConnectionConfiguration.html">ConnectionConfiguration</a>
616652
</li>
653+
<li class="nav-group-task">
654+
<a href="../Structs/ConnectionPoolConfiguration.html">ConnectionPoolConfiguration</a>
655+
</li>
656+
<li class="nav-group-task">
657+
<a href="../Structs/ConnectionPoolMetrics.html">ConnectionPoolMetrics</a>
658+
</li>
617659
<li class="nav-group-task">
618660
<a href="../Structs/LogRecord.html">LogRecord</a>
619661
</li>

0 commit comments

Comments
 (0)