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
faf2cd39
Commit
faf2cd39
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
`sel`/`upd`/`del`/`cascade-delete`/`ins` macros auto-infer namespace
parent
0de0aace
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/db/internal.clj
+12
-9
12 additions, 9 deletions
src/metabase/db/internal.clj
src/metabase/models/field.clj
+2
-2
2 additions, 2 deletions
src/metabase/models/field.clj
with
14 additions
and
11 deletions
src/metabase/db/internal.clj
+
12
−
9
View file @
faf2cd39
...
...
@@ -35,14 +35,15 @@
(
if-not
(
vector?
entity
)
[
entity
nil
]
[(
first
entity
)
(
vec
(
rest
entity
))]))
(
def
entity->korma
(
def
^
{
:arglists
'
([
entity
])}
entity->korma
"Convert an ENTITY argument to `sel` into the form we should pass to korma `select` and to various multi-methods such as
`post-select`.
* If entity is a vector like `[User :name]`, only keeps the first arg (`User`)
* Converts fully-qualified entity name strings like `\"metabase.models.user/User\"` to the corresponding entity
and requires their namespace if needed.
* Symbols like `'metabase.models.user/User` are handled the same way as strings."
* Symbols like `'metabase.models.user/User` are handled the same way as strings.
* Infers the namespace of unqualified symbols like `'CardFavorite`"
(
memoize
(
fn
-entity->korma
[
entity
]
{
:post
[(
:metabase.models.interface/entity
%
)]}
...
...
@@ -50,13 +51,15 @@
(
string?
entity
)
(
-entity->korma
(
symbol
entity
))
(
symbol?
entity
)
(
try
(
eval
entity
)
(
catch
clojure.lang.Compiler$CompilerException
_
; a wrapped ClassNotFoundException
(
->
entity
str
(
.split
"/"
)
first
symbol
require
)
(
eval
entity
)))
(
let
[[
_
ns
symb
]
(
re-matches
#
"^(?:([^/]+)/)?([^/]+)$"
(
str
entity
))
_
(
assert
symb
)
ns
(
symbol
(
or
ns
(
str
"metabase.models."
(
->
symb
(
s/replace
#
"([a-z])([A-Z])"
"$1-$2"
)
; convert something like CardFavorite
s/lower-case
))))
; to ns like metabase.models.card_favorite
symb
(
symbol
symb
)]
(
require
ns
)
@
(
ns-resolve
ns
symb
))))
:else
entity
))))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/field.clj
+
2
−
2
View file @
faf2cd39
...
...
@@ -14,7 +14,7 @@
qualified-name-components
)
(
def
^
:const
special-types
"Possible values for `Field
` `:
special_type`."
"Possible values for `Field
.
special_type`."
#
{
:avatar
:category
:city
...
...
@@ -55,7 +55,7 @@
:zip_code
"Zip Code"
})
(
def
^
:const
base-types
"Possible values for `Field
` `:
base_type`."
"Possible values for `Field
.
base_type`."
#
{
:BigIntegerField
:BooleanField
:CharField
...
...
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