|
18 | 18 | drop-column
|
19 | 19 | drop-extension
|
20 | 20 | drop-table
|
| 21 | + explain |
21 | 22 | filter
|
22 | 23 | insert-into-as
|
23 | 24 | on-conflict
|
|
354 | 355 | (within-group [(sql/call :percentile_disc (hsql-types/array [0.25 0.5 0.75])) (order-by :s.i) :alias])
|
355 | 356 | (from (sql/raw "generate_series(1,10) AS s(i)"))
|
356 | 357 | (sql/format)))))
|
| 358 | + |
357 | 359 | (deftest create-extension-test
|
358 | 360 | (testing "create extension"
|
359 | 361 | (is (= ["CREATE EXTENSION \"uuid-ossp\""]
|
|
372 | 374 | (-> (drop-extension :uuid-ossp)
|
373 | 375 | (sql/format :allow-dashed-names? true
|
374 | 376 | :quoting :ansi))))))
|
| 377 | + |
| 378 | +(deftest explain-test |
| 379 | + (let [query (-> (select :*) |
| 380 | + (from :products))] |
| 381 | + (testing "EXPLAIN without any arguments" |
| 382 | + (is (= ["EXPLAIN SELECT * FROM products"] |
| 383 | + (-> query (explain) (sql/format))))) |
| 384 | + |
| 385 | + (testing "Explain with analyze" |
| 386 | + (is (= ["EXPLAIN ANALYZE SELECT * FROM products"] |
| 387 | + (-> query (explain {:analyze true}) (sql/format))))) |
| 388 | + |
| 389 | + (testing "Explain with analyze verbose" |
| 390 | + (is (= ["EXPLAIN ANALYZE VERBOSE SELECT * FROM products"] |
| 391 | + (-> query (explain {:analyze true :verbose true}) (sql/format)))) |
| 392 | + (is (= ["EXPLAIN ANALYZE VERBOSE SELECT * FROM products"] |
| 393 | + (-> query (explain {:verbose true :analyze true}) (sql/format))))) |
| 394 | + |
| 395 | + (testing "Explain with costs" |
| 396 | + (is (= ["EXPLAIN (COSTS TRUE) SELECT * FROM products"] |
| 397 | + (-> query (explain {:costs true}) (sql/format)))) |
| 398 | + (is (= ["EXPLAIN (COSTS FALSE) SELECT * FROM products"] |
| 399 | + (-> query (explain {:costs false}) (sql/format))))) |
| 400 | + |
| 401 | + (testing "Explain with settings" |
| 402 | + (is (= ["EXPLAIN (SETTINGS TRUE) SELECT * FROM products"] |
| 403 | + (-> query (explain {:settings true}) (sql/format)))) |
| 404 | + (is (= ["EXPLAIN (SETTINGS FALSE) SELECT * FROM products"] |
| 405 | + (-> query (explain {:settings false}) (sql/format))))) |
| 406 | + |
| 407 | + (testing "Explain with buffers" |
| 408 | + (is (= ["EXPLAIN (BUFFERS TRUE) SELECT * FROM products"] |
| 409 | + (-> query (explain {:buffers true}) (sql/format)))) |
| 410 | + (is (= ["EXPLAIN (BUFFERS FALSE) SELECT * FROM products"] |
| 411 | + (-> query (explain {:buffers false}) (sql/format))))) |
| 412 | + |
| 413 | + (testing "Explain with wal" |
| 414 | + (is (= ["EXPLAIN (WAL TRUE) SELECT * FROM products"] |
| 415 | + (-> query (explain {:wal true}) (sql/format)))) |
| 416 | + (is (= ["EXPLAIN (WAL FALSE) SELECT * FROM products"] |
| 417 | + (-> query (explain {:wal false}) (sql/format))))) |
| 418 | + |
| 419 | + (testing "Explain with timing" |
| 420 | + (is (= ["EXPLAIN (TIMING TRUE) SELECT * FROM products"] |
| 421 | + (-> query (explain {:timing true}) (sql/format)))) |
| 422 | + (is (= ["EXPLAIN (TIMING FALSE) SELECT * FROM products"] |
| 423 | + (-> query (explain {:timing false}) (sql/format))))) |
| 424 | + |
| 425 | + (testing "Explain with summary" |
| 426 | + (is (= ["EXPLAIN (SUMMARY TRUE) SELECT * FROM products"] |
| 427 | + (-> query (explain {:summary true}) (sql/format)))) |
| 428 | + (is (= ["EXPLAIN (SUMMARY FALSE) SELECT * FROM products"] |
| 429 | + (-> query (explain {:summary false}) (sql/format))))) |
| 430 | + |
| 431 | + (testing "Explain with format" |
| 432 | + (is (= ["EXPLAIN (FORMAT TEXT) SELECT * FROM products"] |
| 433 | + (-> query (explain {:format :text}) (sql/format)))) |
| 434 | + (is (= ["EXPLAIN (FORMAT XML) SELECT * FROM products"] |
| 435 | + (-> query (explain {:format :xml}) (sql/format)))) |
| 436 | + (is (= ["EXPLAIN (FORMAT JSON) SELECT * FROM products"] |
| 437 | + (-> query (explain {:format :json}) (sql/format)))) |
| 438 | + (is (= ["EXPLAIN (FORMAT YAML) SELECT * FROM products"] |
| 439 | + (-> query (explain {:format :yaml}) (sql/format))))))) |
0 commit comments