Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
6dc4920e
Commit
6dc4920e
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
new implementation of exists?
parent
587890ef
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/user.clj
+2
-2
2 additions, 2 deletions
src/metabase/api/user.clj
src/metabase/db.clj
+10
-23
10 additions, 23 deletions
src/metabase/db.clj
src/metabase/models/segment.clj
+1
-1
1 addition, 1 deletion
src/metabase/models/segment.clj
with
13 additions
and
26 deletions
src/metabase/api/user.clj
+
2
−
2
View file @
6dc4920e
...
...
@@ -62,8 +62,8 @@
first_name
NonEmptyString
last_name
NonEmptyString
}
(
check-self-or-superuser
id
)
(
check-404
(
exists?
User
:id
id
:is_active
true
))
; only allow updates if the specified account is active
(
check-400
(
not
(
exists?
User
:email
email
:id
[
not=
id
])))
; can't change email if it's already taken BY ANOTHER ACCOUNT
(
check-404
(
exists?
User
,
:id
id
,
:is_active
true
))
; only allow updates if the specified account is active
(
check-400
(
not
(
exists?
User
,
:email
email
,
:id
[
:
not=
id
])))
; can't change email if it's already taken BY ANOTHER ACCOUNT
(
check-500
(
upd-non-nil-keys
User
id
:email
email
:first_name
first_name
...
...
This diff is collapsed.
Click to expand it.
src/metabase/db.clj
+
10
−
23
View file @
6dc4920e
...
...
@@ -338,18 +338,6 @@
(
some->
id
entity
models/post-insert
)))
;; ## EXISTS?
(
defmacro
exists?
"Easy way to see if something exists in the db.
(exists? User :id 100)"
[
entity
&
{
:as
kwargs
}]
`
(
boolean
(
seq
(
k/select
(
i/entity->korma
~
entity
)
(
k/fields
[
:id
])
(
k/where
~
(
if
(
seq
kwargs
)
kwargs
{}))
(
k/limit
1
)))))
;; ## CASADE-DELETE
(
defn
^
:deprecated
-cascade-delete
...
...
@@ -605,17 +593,6 @@
(
insert!
entity
(
apply
array-map
k
v
more
))))
;;; ## EXISTS?
;; The new implementation of exists? is commented out for the time being until we re-work existing uses
#
_
(
defn
exists?
"Easy way to see if something exists in the DB.
(db/exists? User :id 100)
NOTE: This only works for objects that have an `:id` field."
[
entity
&
kvs
]
(
boolean
(
select-one
entity
(
apply
where
(
h/select
:id
)
kvs
))))
;;; ## SELECT
;; All of the following functions are based off of the old `sel` macro and can do things like select certain fields by wrapping ENTITY in a vector
...
...
@@ -724,6 +701,16 @@
(
apply
select-field->field
:id
field
entity
options
))
;;; ## EXISTS?
(
defn
exists?
"Easy way to see if something exists in the DB.
(db/exists? User :id 100)
NOTE: This only works for objects that have an `:id` field."
[
entity
&
kvs
]
(
boolean
(
select-one
entity
(
apply
where
(
h/select
:id
)
kvs
))))
;;; ## CASADE-DELETE
(
defn
cascade-delete!
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/segment.clj
+
1
−
1
View file @
6dc4920e
...
...
@@ -76,7 +76,7 @@
Returns true if `Segment` exists and is active, false otherwise."
[
id
]
{
:pre
[(
integer?
id
)]}
(
db/exists?
Segment
:id
id
:is_active
true
))
(
db/exists?
Segment
,
:id
id
,
:is_active
true
))
(
defn
retrieve-segment
"Fetch a single `Segment` by its ID value."
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment