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
2100fd76
Commit
2100fd76
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Extend flexibility of invoking a Metabase entity
parent
c52ec7ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/dashboard_card.clj
+7
-5
7 additions, 5 deletions
src/metabase/models/dashboard_card.clj
src/metabase/models/interface.clj
+49
-17
49 additions, 17 deletions
src/metabase/models/interface.clj
with
56 additions
and
22 deletions
src/metabase/models/dashboard_card.clj
+
7
−
5
View file @
2100fd76
...
...
@@ -11,10 +11,11 @@
[
metabase.util
:as
u
]))
(
i/defentity
DashboardCard
:report_dashboardcard
;; This is implemented as a `transform` function instead of `post-select` because we want it to apply even
;; when we use low-level korma primitives like `select`. Otherwise you can't `insert` what you `select`.
;; TODO - The fact that we have to work around these names means we should probably just rename them
(
k/transform
(
u/rpartial
set/rename-keys
{
:sizex
:sizeX,
:sizey
:sizeY
})))
;; TODO - This can be removed once we finish the transition from korma -> HoneySQL.
;; This needs to be here for the time being because things that go through regular `korma.core/select` don't get ran
;; through `post-select` (like they would if they went through a `metabase.db/` function) and we don't want to have to fix
;; naming manually everywhere
(
k/transform
(
u/rpartial
set/rename-keys
{
:sizex
:sizeX,
:sizey
:sizeY
})))
(
defn-
pre-insert
[
dashcard
]
(
let
[
defaults
{
:sizeX
2
...
...
@@ -29,7 +30,8 @@
(
merge
i/IEntityDefaults
{
:timestamped?
(
constantly
true
)
:pre-insert
pre-insert
:pre-cascade-delete
pre-cascade-delete
}))
:pre-cascade-delete
pre-cascade-delete
:post-select
(
u/rpartial
set/rename-keys
{
:sizex
:sizeX,
:sizey
:sizeY
})}))
;;; ## ---------------------------------------- HYDRATION ----------------------------------------
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/interface.clj
+
49
−
17
View file @
2100fd76
...
...
@@ -200,22 +200,16 @@
(
defn-
invoke-entity
"Fetch an object with a specific ID or all objects of type ENTITY from the DB.
(invoke-entity Database)
-> seq of all databases
(invoke-entity Database
1) -> Database w/ ID 1
"
(invoke-entity Database) -> seq of all databases
(invoke-entity Database
1
)
-> Database w/ ID 1
(invoke-entity Database
:id 1 ...) -> A single Database matching some key-value args
"
([
entity
]
(
for
[
obj
(
k/select
(
assoc
entity
:fields
(
default-fields
entity
)))]
(
do-post-select
entity
obj
)))
((
resolve
'metabase.db/select
)
entity
))
([
entity
id
]
(
when
id
(
when
(
and
id
(
config/config-bool
:mb-db-logging
)
(
not
@
(
resolve
'metabase.db/*sel-disable-logging*
)))
(
log/debug
"DB CALL:"
(
:name
entity
)
id
))
(
when-let
[[
obj
]
(
seq
(
k/select
(
assoc
entity
:fields
(
default-fields
entity
))
(
k/where
{
:id
id
})
(
k/limit
1
)))]
(
do-post-select
entity
obj
)))))
(
invoke-entity
entity
:id
id
)))
([
entity
k
v
&
more
]
(
apply
(
resolve
'metabase.db/select-one
)
entity
k
v
more
)))
(
def
^
:const
^
{
:arglists
'
([
entity
])}
^
Boolean
metabase-entity?
"Is ENTITY a valid metabase model entity?"
...
...
@@ -260,7 +254,7 @@
(Database) ; return a seq of *all* Databases (as instances of `DatabaseInstance`)
(Database 1) ; return Database 1"
{
:arglist
'
([
entity
table-name
]
[
entity
docstr?
table-name
&
korma-forms
])
:style/indent
1
}
:style/indent
2
}
[
entity
&
args
]
(
let
[[
docstr
[
table-name
&
korma-forms
]]
(
u/optional
string?
args
)
instance
(
symbol
(
str
entity
"Instance"
))
...
...
@@ -268,8 +262,46 @@
`
(
do
(
defrecord
~
instance
[]
clojure.lang.IFn
(
~
'invoke
[
this
#
]
(
invoke-entity-or-instance
this
#
))
(
~
'invoke
[
this
#
id
#
]
(
invoke-entity-or-instance
this
#
id
#
)))
(
~
'invoke
[
this
#
]
(
invoke-entity-or-instance
this
#
))
(
~
'invoke
[
this
#
id
#
]
(
invoke-entity-or-instance
this
#
id
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
arg17
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
arg17
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
arg17
#
arg18
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
arg17
#
arg18
#
))
(
~
'invoke
[
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
arg17
#
arg18
#
arg19
#
]
(
invoke-entity-or-instance
this
#
arg1
#
arg2
#
arg3
#
arg4
#
arg5
#
arg6
#
arg7
#
arg8
#
arg9
#
arg10
#
arg11
#
arg12
#
arg13
#
arg14
#
arg15
#
arg16
#
arg17
#
arg18
#
arg19
#
)))
(
u/strict-extend
~
instance
IEntity
IEntityDefaults
...
...
@@ -277,7 +309,7 @@
(
def
~
(
vary-meta
entity
assoc
:tag
(
symbol
(
str
(
namespace-munge
*ns*
)
\.
instance
))
:arglists
''
([]
[
id
])
:arglists
''
([]
[
id
]
[
&
kvs
]
)
:doc
(
or
docstr
(
format
"Korma entity for '%s' table; instance of %s."
(
name
table-name
)
instance
)))
(
->
(
k/create-entity
~
(
name
entity
))
...
...
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