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
b94e86c5
Commit
b94e86c5
authored
10 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Mongo QP
parent
20c68c03
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
project.clj
+1
-0
1 addition, 0 deletions
project.clj
src/metabase/driver/mongo.clj
+5
-40
5 additions, 40 deletions
src/metabase/driver/mongo.clj
with
6 additions
and
40 deletions
project.clj
+
1
−
0
View file @
b94e86c5
...
...
@@ -72,6 +72,7 @@
[
lein-instant-cheatsheet
"2.1.1"
]
; use awesome instant cheatsheet created by yours truly w/ 'lein instant-cheatsheet'
[
lein-marginalia
"0.8.0"
]
; generate documentation with 'lein marg'
[
refactor-nrepl
"1.0.1"
]]
; support for advanced refactoring in Emacs/LightTable
:warn-on-reflection
true
; Emit warnings on all reflection calls
:jvm-opts
[
"-Dlogfile.path=target/log"
"-Xms1024m"
; give JVM a decent heap size to start with
"-Xmx2048m"
; hard limit of 2GB so we stop hitting the 4GB container limit on CircleCI
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/mongo.clj
+
5
−
40
View file @
b94e86c5
...
...
@@ -11,48 +11,12 @@
[
db
:as
mdb
]
[
query
:as
mq
])
[
metabase.driver
:as
driver
]
(
metabase.driver
[
interface
:refer
:all
])))
[
metabase.driver.interface
:refer
:all
]
(
metabase.driver.mongo
[
query-processor
:as
qp
]
[
util
:refer
[
*mongo-connection*
with-mongo-connection
]])))
(
declare
driver
)
;; ## with-mongo-connection
(
def
^
:dynamic
*mongo-connection*
"Bound by top-level `with-mongo-connection` so it may be reused within its body."
nil
)
(
defn-
-with-mongo-connection
"Run F with a new connection (bound to `*mongo-connection*`) to DATABASE.
Don't use this directly; use `with-mongo-connection`."
[
f
database
]
(
let
[
connection-string
(
if
(
map?
database
)
(
->
database
:details
:conn_str
)
database
)
_
(
assert
(
string?
connection-string
)
(
str
"with-mongo-connection failed: connection string is must be a string, got: "
connection-string
))
{
conn
:conn
mongo-connection
:db
}
(
mg/connect-via-uri
connection-string
)]
(
log/debug
(
color/cyan
"<< OPENED NEW MONGODB CONNECTION >>"
))
(
try
(
binding
[
*mongo-connection*
mongo-connection
]
(
f
*mongo-connection*
))
(
finally
(
mg/disconnect
conn
)))))
(
defmacro
with-mongo-connection
"Open a new MongoDB connection to DATABASE-OR-CONNECTION-STRING, bind connection to BINDING, execute BODY, and close the connection.
The DB connection is re-used by subsequent calls to `with-mongo-connection` within BODY.
(We're smart about it: DATABASE isn't even evaluated if `*mongo-connection*` is already bound.)
(with-mongo-connection [conn @(:db (sel :one Table ...))] ; delay isn't derefed if *mongo-connection* is already bound
...)
(with-mongo-connection [conn \"mongodb://127.0.0.1:27017/test\"] ; use a string instead of a DB
...)"
[[
binding
database
]
&
body
]
`
(
let
[
f
#
(
fn
[
~
binding
]
~@
body
)]
(
if
*mongo-connection*
(
f
#
*mongo-connection*
)
(
-with-mongo-connection
f
#
~
database
))))
;;; ### Driver Helper Fns
(
defn-
table->column-names
...
...
@@ -109,7 +73,8 @@
dbname
)))
;;; ### QP
(
process-query
[
_
query
])
(
process-query
[
_
query
]
(
qp/process-and-run
query
))
;;; ### Syncing
(
sync-in-context
[
_
database
do-sync-fn
]
...
...
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