-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdbio.html
331 lines (310 loc) · 29.4 KB
/
dbio.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Database I/O Actions — Slick 3.1.0-M1 documentation</title>
<link rel="stylesheet" href="_static/slick.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '3.1.0-M1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="top" title="Slick 3.1.0-M1 documentation" href="index.html" />
<link rel="next" title="Schemas" href="schemas.html" />
<link rel="prev" title="Database Configuration" href="database.html" />
<script type="text/javascript">
if(window.location.host == 'slick.typesafe.com'){
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23127719-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
</script>
</head>
<body>
<div class="header-wrapper">
<div class="header">
<div class="rel">
<span class="github"><a href="https://github.com/slick/slick/edit/master/slick/src/sphinx/dbio.rst">edit this page on github</a><span>
|
<a href="database.html" title="Database Configuration"
accesskey="P">previous</a> |
<a href="schemas.html" title="Schemas"
accesskey="N">next</a> |
<a href="genindex.html" title="General Index"
accesskey="I">index</a>
</div>
<div class="headertitle"><a href="index.html">
<span class="logo"><img class="logo" src="_static/slick-logo.png" alt="Slick"/></span>
3.1.0-M1 manual
</a></div>
</div>
</div>
<div class="content-wrapper">
<div class="content">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="database-i-o-actions">
<h1>Database I/O Actions<a class="headerlink" href="#database-i-o-actions" title="Permalink to this headline">¶</a></h1>
<p>Anything that you can execute on a database, whether it is a getting the result of a query
(<tt class="docutils literal"><span class="pre">myQuery.result</span></tt>), creating a table (<tt class="docutils literal"><span class="pre">myTable.schema.create</span></tt>), inserting data
(<tt class="docutils literal"><span class="pre">myTable</span> <span class="pre">+=</span> <span class="pre">item</span></tt>) or something else, is an instance of
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction">DBIOAction</a>, parameterized by the result type it will produce when you
execute it.</p>
<p><em>Database I/O Actions</em> can be combined with several different combinators (see the
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction">DBIOAction class</a> and <a class="reference external" href="api/index.html#slick.dbio.DBIO$">DBIO object</a>
for details), but they will always be executed strictly sequentially and (at least conceptually) in a
single database session.</p>
<p>In most cases you will want to use the type aliases <a class="reference external" href="api/index.html#slick.dbio.package@DBIO[+R]:DBIO[R]">DBIO</a>
and <a class="reference external" href="api/index.html#slick.dbio.package@StreamingDBIO[+R,+T]:StreamingDBIO[R,T]">StreamingDBIO</a> for non-streaming and
streaming Database I/O Actions. They omit the optional <em>effect types</em> supported by <a class="reference external" href="api/index.html#slick.dbio.DBIOAction">DBIOAction</a>.</p>
<div class="section" id="executing-database-i-o-actions">
<span id="executing-actions"></span><span id="index-0"></span><h2>Executing Database I/O Actions<a class="headerlink" href="#executing-database-i-o-actions" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">DBIOAction</span></tt>s can be executed either with the goal of producing a fully materialized result or streaming
data back from the database.</p>
<div class="section" id="materialized">
<span id="index-1"></span><h3>Materialized<a class="headerlink" href="#materialized" title="Permalink to this headline">¶</a></h3>
<p>You can use <tt class="docutils literal"><span class="pre">run</span></tt> to execute a <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> on a Database and produce a materialized result. This can
be, for example, a scalar query result (<tt class="docutils literal"><span class="pre">myTable.length.result</span></tt>), a collection-valued query
result (<tt class="docutils literal"><span class="pre">myTable.to[Set].result</span></tt>), or any other action. Every <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> supports this mode of
execution.</p>
<p>Execution of the action starts when <tt class="docutils literal"><span class="pre">run</span></tt> is called, and the materialized result is returned as a
<tt class="docutils literal"><span class="pre">Future</span></tt> which is completed asynchronously as soon as the result is available:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">val</span> <span class="n">q</span> <span class="k">=</span> <span class="k">for</span> <span class="o">(</span><span class="n">c</span> <span class="k"><-</span> <span class="n">coffees</span><span class="o">)</span> <span class="k">yield</span> <span class="n">c</span><span class="o">.</span><span class="n">name</span>
<span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="n">q</span><span class="o">.</span><span class="n">result</span>
<span class="k">val</span> <span class="n">f</span><span class="k">:</span> <span class="kt">Future</span><span class="o">[</span><span class="kt">Seq</span><span class="o">[</span><span class="kt">String</span><span class="o">]]</span> <span class="k">=</span> <span class="n">db</span><span class="o">.</span><span class="n">run</span><span class="o">(</span><span class="n">a</span><span class="o">)</span>
<span class="n">f</span><span class="o">.</span><span class="n">onSuccess</span> <span class="o">{</span> <span class="k">case</span> <span class="n">s</span> <span class="k">=></span> <span class="n">println</span><span class="o">(</span><span class="n">s</span><span class="s">"Result: $s"</span><span class="o">)</span> <span class="o">}</span>
</pre></div>
</div>
</div>
<div class="section" id="streaming">
<span id="index-2"></span><h3>Streaming<a class="headerlink" href="#streaming" title="Permalink to this headline">¶</a></h3>
<p>Collection-valued queries also support streaming results. In this case, the actual collection type
is ignored and elements are streamed directly from the result set through a <a class="reference external" href="http://www.reactive-streams.org/">Reactive Streams</a>
<tt class="docutils literal"><span class="pre">Publisher</span></tt>, which can be processed and consumed by <a class="reference external" href="http://akka.io/docs/">Akka Streams</a>.</p>
<p>Execution of the <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> does not start until a <tt class="docutils literal"><span class="pre">Subscriber</span></tt> is attached to the stream. Only a single
<tt class="docutils literal"><span class="pre">Subscriber</span></tt> is supported, and any further attempts to subscribe again will fail. Stream elements are
signaled as soon as they become available in the streaming part of the <tt class="docutils literal"><span class="pre">DBIOAction</span></tt>. The end of the
stream is signaled only after the entire action has completed. For example, when streaming inside
a transaction and all elements have been delivered successfully, the stream can still fail
afterwards if the transaction cannot be committed.</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">val</span> <span class="n">q</span> <span class="k">=</span> <span class="k">for</span> <span class="o">(</span><span class="n">c</span> <span class="k"><-</span> <span class="n">coffees</span><span class="o">)</span> <span class="k">yield</span> <span class="n">c</span><span class="o">.</span><span class="n">name</span>
<span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="n">q</span><span class="o">.</span><span class="n">result</span>
<span class="k">val</span> <span class="n">p</span><span class="k">:</span> <span class="kt">DatabasePublisher</span><span class="o">[</span><span class="kt">String</span><span class="o">]</span> <span class="k">=</span> <span class="n">db</span><span class="o">.</span><span class="n">stream</span><span class="o">(</span><span class="n">a</span><span class="o">)</span>
<span class="c1">// .foreach is a convenience method on DatabasePublisher.</span>
<span class="c1">// Use Akka Streams for more elaborate stream processing.</span>
<span class="n">p</span><span class="o">.</span><span class="n">foreach</span> <span class="o">{</span> <span class="n">s</span> <span class="k">=></span> <span class="n">println</span><span class="o">(</span><span class="n">s</span><span class="s">"Element: $s"</span><span class="o">)</span> <span class="o">}</span>
</pre></div>
</div>
<p>When streaming a JDBC result set, the next result page will be buffered in the background if the
Subscriber is not ready to receive more data, but all elements are signaled synchronously and the
result set is not advanced before synchronous processing is finished. This allows synchronous
callbacks to low-level JDBC values like <tt class="docutils literal"><span class="pre">Blob</span></tt> which depend on the state of the result set. The
convenience method <tt class="docutils literal"><span class="pre">mapResult</span></tt> is provided for this purpose:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">val</span> <span class="n">q</span> <span class="k">=</span> <span class="k">for</span> <span class="o">(</span><span class="n">c</span> <span class="k"><-</span> <span class="n">coffees</span><span class="o">)</span> <span class="k">yield</span> <span class="n">c</span><span class="o">.</span><span class="n">image</span>
<span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="n">q</span><span class="o">.</span><span class="n">result</span>
<span class="k">val</span> <span class="n">p1</span><span class="k">:</span> <span class="kt">DatabasePublisher</span><span class="o">[</span><span class="kt">Blob</span><span class="o">]</span> <span class="k">=</span> <span class="n">db</span><span class="o">.</span><span class="n">stream</span><span class="o">(</span><span class="n">a</span><span class="o">)</span>
<span class="k">val</span> <span class="n">p2</span><span class="k">:</span> <span class="kt">DatabasePublisher</span><span class="o">[</span><span class="kt">Array</span><span class="o">[</span><span class="kt">Byte</span><span class="o">]]</span> <span class="k">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">mapResult</span> <span class="o">{</span> <span class="n">b</span> <span class="k">=></span>
<span class="n">b</span><span class="o">.</span><span class="n">getBytes</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">b</span><span class="o">.</span><span class="n">length</span><span class="o">().</span><span class="n">toInt</span><span class="o">)</span>
<span class="o">}</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="composing-database-i-o-actions">
<span id="transactions"></span><span id="index-3"></span><h2>Composing Database I/O Actions<a class="headerlink" href="#composing-database-i-o-actions" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">DBIOAction</span></tt>s describe sequences of individual actions to execute in strictly sequential order on
one database session (at least conceptually), therefore the most commonly used combinators deal with
sequencing. Since a <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> eventually results in a <tt class="docutils literal"><span class="pre">Success</span></tt> or <tt class="docutils literal"><span class="pre">Failure</span></tt>, its combinators,
just like the ones on <tt class="docutils literal"><span class="pre">Future</span></tt>, have to distinguish between successful and failed executions. Unless
specifically noted, all combinators only apply to successful actions. Any failure will abort the
sequence of execution and result in a failed <tt class="docutils literal"><span class="pre">Future</span></tt> or <em>Reactive Stream</em>.</p>
<div class="section" id="sequential-execution">
<h3>Sequential Execution<a class="headerlink" href="#sequential-execution" title="Permalink to this headline">¶</a></h3>
<p>The simplest combinator is <a class="reference external" href="api/index.html#slick.dbio.DBIO$@seq[E<:Effect](DBIOAction[_,NoStream,E]*):DBIOAction[Unit,NoStream,E]">DBIO.seq</a>
which takes a varargs list of actions to run in sequence, discarding their return value. If you
need the return value, you can use <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@andThen[R2,S2<:NoStream,E2<:Effect](DBIOAction[R2,S2,E2]):DBIOAction[R2,S2,EwithE2]">andThen</a>
to combine two actions and keep the result of the second one. If you need both return values of two
actions, there is the <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@zip[R2,E2<:Effect](DBIOAction[R2,NoStream,E2]):DBIOAction[(R,R2),NoStream,EwithE2]">zip</a>
combinator. For getting all result values from a sequence of actions (of compatible types), use
<a class="reference external" href="api/index.html#slick.dbio.DBIO$@sequence[R,M[+_]<:TraversableOnce[_],E<:Effect](M[DBIOAction[R,NoStream,E]])(CanBuildFrom[M[DBIOAction[R,NoStream,E]],R,M[R]]):DBIOAction[M[R],NoStream,E]">DBIO.sequence</a>.
All these combinators work with pre-existing <tt class="docutils literal"><span class="pre">DBIOAction</span></tt>s which are composed eagerly.</p>
<p>If an action depends on a previous action in the sequence, you have to compute it on the fly with
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction@flatMap[R2,S2<:NoStream,E2<:Effect]((R)⇒DBIOAction[R2,S2,E2])(ExecutionContext):DBIOAction[R2,S2,EwithE2]">flatMap</a>
or <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@map[R2]((R)⇒R2)(ExecutionContext):DBIOAction[R2,NoStream,E]">map</a>.
These two methods plus <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@filter((R)⇒Boolean)(ExecutionContext):DBIOAction[R,NoStream,E]">filter</a>
enable the use of <em>for comprehensions</em> for action sequencing. Since they take function
arguments, they also require an implicit <tt class="docutils literal"><span class="pre">ExecutionContext</span></tt> on which to run the function. This
way Slick ensures that no non-database code is run on the database thread pool.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You should prefer the less flexible methods without an <tt class="docutils literal"><span class="pre">ExecutionContext</span></tt> where possible. The
resulting actions can be executed more efficiently.</p>
</div>
<p>Similar to <a class="reference external" href="api/index.html#slick.dbio.DBIO$@sequence[R,M[+_]<:TraversableOnce[_],E<:Effect](M[DBIOAction[R,NoStream,E]])(CanBuildFrom[M[DBIOAction[R,NoStream,E]],R,M[R]]):DBIOAction[M[R],NoStream,E]">DBIO.sequence</a>
for upfront composition, there is <a class="reference external" href="api/index.html#slick.dbio.DBIO$@fold[T,E<:Effect](Seq[DBIOAction[T,NoStream,E]],T)((T,T)⇒T)(ExecutionContext):DBIOAction[T,NoStream,E]">DBIO.fold</a>
for working with sequences of actions and composing them based on the previous result.</p>
</div>
<div class="section" id="error-handling">
<h3>Error Handling<a class="headerlink" href="#error-handling" title="Permalink to this headline">¶</a></h3>
<p>You can use <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@andFinally[E2<:Effect](DBIOAction[_,NoStream,E2]):DBIOAction[R,S,EwithE2]">andFinally</a>
to perform a cleanup action, no matter whether the previous action succeeded or failed. This is similar to using
<tt class="docutils literal"><span class="pre">try</span> <span class="pre">...</span> <span class="pre">finally</span> <span class="pre">...</span></tt> in imperative Scala code. A more flexible version of
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction@andFinally[E2<:Effect](DBIOAction[_,NoStream,E2]):DBIOAction[R,S,EwithE2]">andFinally</a>
is <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@cleanUp[E2<:Effect]((Option[Throwable])⇒DBIOAction[_,NoStream,E2],Boolean)(ExecutionContext):DBIOAction[R,S,EwithE2]">cleanUp</a>.
It lets you transform the failure and decide how to fail the resulting action if both the original
one and the cleanup failed.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For even more flexible error handling use <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@asTry:DBIOAction[Try[R],NoStream,E]">asTry</a>
and <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@failed:DBIOAction[Throwable,NoStream,E]">failed</a>. Unlike with
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction@andFinally[E2<:Effect](DBIOAction[_,NoStream,E2]):DBIOAction[R,S,EwithE2]">andFinally</a>
and <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@cleanUp[E2<:Effect]((Option[Throwable])⇒DBIOAction[_,NoStream,E2],Boolean)(ExecutionContext):DBIOAction[R,S,EwithE2]">cleanUp</a>
the resulting actions cannot be used for streaming.</p>
</div>
</div>
<div class="section" id="primitives">
<h3>Primitives<a class="headerlink" href="#primitives" title="Permalink to this headline">¶</a></h3>
<p>You can convert a <tt class="docutils literal"><span class="pre">Future</span></tt> into an action with <a class="reference external" href="api/index.html#slick.dbio.DBIO$@from[R](Future[R]):DBIOAction[R,NoStream,Effect]">DBIO.from</a>.
This allows the result of the <tt class="docutils literal"><span class="pre">Future</span></tt> to be used in an action sequence. A pre-existing value or
failure can be converted with <a class="reference external" href="api/index.html#slick.dbio.DBIO$@successful[R](R):DBIOAction[R,NoStream,Effect]">DBIO.successful</a>
and <a class="reference external" href="api/index.html#slick.dbio.DBIO$@failed(Throwable):DBIOAction[Nothing,NoStream,Effect]">DBIO.failed</a>, respectively.</p>
</div>
<div class="section" id="debugging">
<h3>Debugging<a class="headerlink" href="#debugging" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@named(String):DBIOAction[R,S,E]">named</a> combinator names an
action. This name can be seen in debug logs if you enable the
<tt class="docutils literal"><span class="pre">slick.backend.DatabaseComponent.action</span></tt> logger.</p>
</div>
<div class="section" id="transactions-and-pinned-sessions">
<h3>Transactions and Pinned Sessions<a class="headerlink" href="#transactions-and-pinned-sessions" title="Permalink to this headline">¶</a></h3>
<p>When executing a <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> which is composed of several smaller actions, Slick acquires sessions from
the connection pool and releases them again as needed so that a session is not kept in use
unnecessarily while waiting for the result from a non-database computation (e.g. the function passed to
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction@flatMap[R2,S2<:NoStream,E2<:Effect]((R)⇒DBIOAction[R2,S2,E2])(ExecutionContext):DBIOAction[R2,S2,EwithE2]">flatMap</a>
that determines the next Action to run). All <a class="reference external" href="api/index.html#slick.dbio.DBIOAction">DBIOAction combinators</a>
which combine two database actions without any non-database computations in between (e.g.
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction@andThen[R2,S2<:NoStream,E2<:Effect](DBIOAction[R2,S2,E2]):DBIOAction[R2,S2,EwithE2]">andThen</a>
or <a class="reference external" href="api/index.html#slick.dbio.DBIOAction@zip[R2,E2<:Effect](DBIOAction[R2,NoStream,E2]):DBIOAction[(R,R2),NoStream,EwithE2]">zip</a>)
can fuse these actions for more efficient execution, with the side-effect that the fused action
runs inside a single session. You can use
<a class="reference external" href="api/index.html#slick.dbio.DBIOAction@withPinnedSession:DBIOAction[R,S,E]">withPinnedSession</a> to force the
use of a single session, keeping the existing session open even when waiting for non-database
computations.</p>
<p>There is a similar combinator called
<a class="reference external" href="api/index.html#slick.driver.JdbcActionComponent$JdbcActionExtensionMethods@transactionally:DBIOAction[R,S,EwithTransactional]">transactionally</a>
to force the use of a transaction. This guarantees that the entire <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> that is executed will
either succeed or fail atomically.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Failure is not guaranteed to be atomic <em>at the level of an individual</em> <tt class="docutils literal"><span class="pre">DBIOAction</span></tt> that is wrapped with
<tt class="docutils literal"><span class="pre">transactionally</span></tt>, so you should not apply error recovery combinators at that point. An actual database
transaction is inly created and committed / rolled back for the outermost <tt class="docutils literal"><span class="pre">transactionally</span></tt> action.</p>
</div>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">val</span> <span class="n">a</span> <span class="k">=</span> <span class="o">(</span><span class="k">for</span> <span class="o">{</span>
<span class="n">ns</span> <span class="k"><-</span> <span class="n">coffees</span><span class="o">.</span><span class="n">filter</span><span class="o">(</span><span class="k">_</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">startsWith</span><span class="o">(</span><span class="s">"ESPRESSO"</span><span class="o">)).</span><span class="n">map</span><span class="o">(</span><span class="k">_</span><span class="o">.</span><span class="n">name</span><span class="o">).</span><span class="n">result</span>
<span class="k">_</span> <span class="k"><-</span> <span class="nc">DBIO</span><span class="o">.</span><span class="n">seq</span><span class="o">(</span><span class="n">ns</span><span class="o">.</span><span class="n">map</span><span class="o">(</span><span class="n">n</span> <span class="k">=></span> <span class="n">coffees</span><span class="o">.</span><span class="n">filter</span><span class="o">(</span><span class="k">_</span><span class="o">.</span><span class="n">name</span> <span class="o">===</span> <span class="n">n</span><span class="o">).</span><span class="n">delete</span><span class="o">)</span><span class="k">:</span> <span class="k">_</span><span class="kt">*</span><span class="o">)</span>
<span class="o">}</span> <span class="k">yield</span> <span class="o">()).</span><span class="n">transactionally</span>
<span class="k">val</span> <span class="n">f</span><span class="k">:</span> <span class="kt">Future</span><span class="o">[</span><span class="kt">Unit</span><span class="o">]</span> <span class="k">=</span> <span class="n">db</span><span class="o">.</span><span class="n">run</span><span class="o">(</span><span class="n">a</span><span class="o">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="jdbc-interoperability">
<span id="jdbc-interop"></span><span id="index-4"></span><h2>JDBC Interoperability<a class="headerlink" href="#jdbc-interoperability" title="Permalink to this headline">¶</a></h2>
<p>In order to drop down to the JDBC level for functionality that is not available in Slick, you can
use a <tt class="docutils literal"><span class="pre">SimpleDBIO</span></tt> action which is run on a database thread and gets access to the JDBC <tt class="docutils literal"><span class="pre">Connection</span></tt>:</p>
<div class="highlight-scala"><div class="highlight"><pre><span class="k">val</span> <span class="n">getAutoCommit</span> <span class="k">=</span> <span class="nc">SimpleDBIO</span><span class="o">[</span><span class="kt">Boolean</span><span class="o">](</span><span class="k">_</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">getAutoCommit</span><span class="o">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sidebar">
<h3>Search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<h3 style="margin-top: 1.5em;">Table Of Contents</h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="supported-databases.html">Supported Databases</a></li>
<li class="toctree-l1"><a class="reference internal" href="gettingstarted.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="database.html">Database Configuration</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Database I/O Actions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#executing-database-i-o-actions">Executing Database I/O Actions</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#materialized">Materialized</a></li>
<li class="toctree-l3"><a class="reference internal" href="#streaming">Streaming</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#composing-database-i-o-actions">Composing Database I/O Actions</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#sequential-execution">Sequential Execution</a></li>
<li class="toctree-l3"><a class="reference internal" href="#error-handling">Error Handling</a></li>
<li class="toctree-l3"><a class="reference internal" href="#primitives">Primitives</a></li>
<li class="toctree-l3"><a class="reference internal" href="#debugging">Debugging</a></li>
<li class="toctree-l3"><a class="reference internal" href="#transactions-and-pinned-sessions">Transactions and Pinned Sessions</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#jdbc-interoperability">JDBC Interoperability</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="schemas.html">Schemas</a></li>
<li class="toctree-l1"><a class="reference internal" href="queries.html">Queries</a></li>
<li class="toctree-l1"><a class="reference internal" href="code-generation.html">Schema Code Generation</a></li>
<li class="toctree-l1"><a class="reference internal" href="userdefined.html">User-Defined Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="sql.html">Plain SQL Queries</a></li>
<li class="toctree-l1"><a class="reference internal" href="orm-to-slick.html">Coming from ORM to Slick</a></li>
<li class="toctree-l1"><a class="reference internal" href="sql-to-slick.html">Coming from SQL to Slick</a></li>
<li class="toctree-l1"><a class="reference internal" href="upgrade.html">Upgrade Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">Slick Extensions</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="testkit.html">Slick TestKit</a></li>
</ul>
</div>
<div class="clearer"></div>
</div>
</div>
<div class="footer-wrapper">
<div class="footer">
<div class="left">
<a href="database.html" title="Database Configuration"
>previous</a> |
<a href="schemas.html" title="Schemas"
>next</a> |
<a href="genindex.html" title="General Index"
>index</a>
</div>
<div class="right">
<div class="footer">
© Copyright 2011-2015 Typesafe, Inc.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b3.
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</body>
</html>