-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexists.html
More file actions
209 lines (202 loc) · 7.07 KB
/
Copy pathexists.html
File metadata and controls
209 lines (202 loc) · 7.07 KB
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
<!doctype html>
<html lang="en">
<head>
<title>Exists | Query | Ebean</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="/images/favicon.ico">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro|Ubuntu&display=swap">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
<link rel="stylesheet" href="/css/reset3.css">
<link rel="stylesheet" href="/css/site3.css">
<link rel="stylesheet" href="/css/pygments3.css">
</head>
<body>
<div id="main">
<div id="banner">
<header>
<nav id="top">
<h1 id="breadcrumb">
<a class="nav-logo" href="/"><img src="/images/logo-200.png" height="35"></a> <a href="/docs">Documentation</a><span class="sep"> / </span><a href="/docs/query/">Query</a><span class="sep"> / </span><span class="last">exists</span>
</h1>
<ul>
<li><a onclick="toggleTheme();" title="switch dark light theme"><i class="fas fa-adjust"></i></a></li>
</ul>
</nav>
</header>
</div>
<div class="grid grid-docs">
<aside>
<nav class="side">
<ul>
<li class="nav0 ">
<a href="/docs/getting-started">Getting started</a>
</li>
<li class="nav0 ">
<a href="/docs/intro">Introduction</a>
</li>
<li class="nav0 active">
<a class="active" href="/docs">Documentation</a>
<ul>
<li class="nav1 ">
<a href="/docs/agents">AI Agents</a>
</li>
<li class="nav1 ">
<a href="/docs/best-practice">Best practice</a>
</li>
<li class="nav1 active">
<a class="active" href="/docs/query">Query</a>
<ul class="nav">
<li class="active">
<a class="active" href="/docs/query/exists">exists</a>
</li>
<li >
<a href="/docs/query/findOne">findOne</a>
</li>
<li >
<a href="/docs/query/findList">findList</a>
</li>
<li >
<a href="/docs/query/findCount">findCount</a>
</li>
<li >
<a href="/docs/query/findNative">findNative</a>
</li>
<li >
<a href="/docs/query/findPagedList">findPagedList</a>
</li>
<li >
<a href="/docs/query/findMap">findMap</a>
</li>
<li >
<a href="/docs/query/findSet">findSet</a>
</li>
<li >
<a href="/docs/streaming#findEach">findEach</a>
</li>
<li >
<a href="/docs/query/streaming#findStream">findStream</a>
</li>
<li >
<a href="/docs/query/streaming#findIterate">findIterate</a>
</li>
<li >
<a href="/docs/query/findIds">findIds</a>
</li>
<li >
<a href="/docs/query/findSingleAttribute">findSingleAttribute</a>
</li>
<li >
<a href="/docs/query/findFuture">findFuture</a>
</li>
<li >
<a href="/docs/query/findVersions">findVersions</a>
</li>
</ul>
</li>
<li class="nav1 ">
<a href="/docs/persist">Persist</a>
</li>
<li class="nav1 ">
<a href="/docs/transactions">Transactions</a>
</li>
<li class="nav1 ">
<a href="/docs/mapping">Mapping</a>
</li>
<li class="nav1 ">
<a href="/docs/ddl-generation">DDL & Migrations</a>
</li>
<li class="nav1 ">
<a href="/docs/logging">Logging</a>
</li>
<li class="nav1 ">
<a href="/docs/testing">Testing</a>
</li>
<li class="nav1 ">
<a href="/docs/read-replicas">Read Replicas</a>
</li>
<li class="nav1 ">
<a href="/docs/database">Database platforms</a>
</li>
<li class="nav1 ">
<a href="/docs/multi-database">Multiple databases</a>
</li>
<li class="nav1 ">
<a href="/docs/kotlin">Kotlin</a>
</li>
<li><a href="/docs/tuning">Tuning</a></li>
<li class="nav1 ">
<a href="/docs/features">Features</a>
</li>
</ul>
</li>
<li class="nav0 ">
<a href="/support">Getting help</a>
</li>
<li class="nav0 ">
<a target="_blank" href="/apidoc/13">API Javadoc</a>
</li>
<li class="nav0 ">
<a href="/videos">Videos</a>
</li>
<li class="nav0 ">
<a href="/docs/upgrading">Upgrading</a>
</li>
<li class="nav0 ">
<a href="/docs/deprecated">Deprecated</a>
</li>
<li class="nav0 ">
<a href="/releases">Releases</a>
</li>
</ul>
</nav>
</aside>
<article>
<form action="https://www.google.com/search" method="get" class="inline-form">
<input type="hidden" name="as_sitesearch" value="ebean.io">
<div id="page-search">
<div class="input-group">
<input class="frm" name="q" id="searchinput" type="text" placeholder="Search... (press 's' to focus)" data-placeholder-focus="Search... (use '↑', '↓' and '⏎' to select results)" data-placeholder-blur="Search... (press 's' to focus)" autocomplete="off">
<div class="input-group-btn">
<button class="frm" type="submit"><i class="fas fa-search"></i></button>
</div>
</div>
<div id="page-search-results" style="display: none;">
<ul id="search-results-container" class="search-results"><li class=" active"><a href="/docs" title="Docs"><span style="color:#777;">Docs</span> Documentation </a></li><li class=""><small style="color:#999;">And 101 more...</small></li></ul>
</div>
</div>
</form>
<h2>Exists</h2>
<p>
The <em>exists</em> query is a convenience that sets the query to only
select the Id property, use a maxRows = 1 and tests if the query returns
a row.
</p>
<div class="syntax java"><div class="highlight"><pre><span></span><span class="kt">boolean</span> <span class="n">userExists</span> <span class="o">=</span>
<span class="k">new</span> <span class="n">QContact</span><span class="o">()</span>
<span class="o">.</span><span class="na field">email</span><span class="o">.</span><span class="na">equalTo</span><span class="o">(</span><span class="s">"rob@foo.com"</span><span class="o">)</span>
<span class="o">.</span><span class="na">exists</span><span class="o">();</span>
</pre></div>
</div>
<div class="syntax sql"><div class="highlight"><pre><span></span><span class="k">select</span> <span class="n">t0</span><span class="p">.</span><span class="n">id</span> <span class="k">from</span> <span class="n">contact</span> <span class="n">t0</span> <span class="k">where</span> <span class="n">t0</span><span class="p">.</span><span class="n">email</span> <span class="o">=</span> <span class="o">?</span> <span class="k">limit</span> <span class="mi">1</span>
</pre></div>
</div>
<p>
We could instead write this query using findIds() and maxRows() but it is a
common enough pattern to perform checks like this that we have this exists query.
</p>
</article>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="/js/site3.js"></script>
<script src="/js/search3.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-75181644-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-75181644-1');
</script>
</body>
</html>