honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
camsaul 2020-10-07T18:30:58.153200Z

@seancorfield related: Does HoneySQL run tests against different DBMSes in CI? We could be confident that wrapping the subqueries in a UNION expression wouldn't break MySQL if we ran some test queries against MySQL in CI, for example. If it's not already set up I can help with it if you want. I did something similar for Metabase -- we currently run tests against 19 different DBMS/version combos in CircleCI with one job for each; we spin up Docker images for various DBs like MariaDB or SQSL Server. (Example: https://app.circleci.com/pipelines/github/metabase/metabase/9360/workflows/bf8a7e01-10b4-457c-ab75-7e324647a297) For test tooling I wrote some utility functions that will load test data from an EDN file into the DBMSes you're testing against, and then some test util macros so you can write one test and have it run against any/all of those DBMSes. Since they all have identical data, running the same query will give you the same result. https://github.com/metabase/metabase/blob/master/test/metabase/query_processor_test/filter_test.clj#L203-L213:

(deftest ends-with-test
  (mt/test-drivers (mt/normal-drivers)
    (is (= [[ 5 "Brite Spot Family Restaurant" 20 34.0778 -118.261 2]
            [ 7 "Don Day Korean Restaurant"    44 34.0689 -118.305 2]
            [17 "Ruen Pair Thai Restaurant"    71 34.1021 -118.306 2]
            [45 "Tu Lan Restaurant"             4 37.7821 -122.41  1]
            [55 "Dal Rae Restaurant"           67 33.983  -118.096 4]]
           (mt/formatted-rows :venues
             (mt/run-mbql-query venues
               {:filter   [:ends-with $name "Restaurant"]
                :order-by [[:asc $id]]})))))
So for example with HoneySQL you could have a unions-test that would check that a query with a UNION expression worked correctly, and then that would run against MySQL/Postgres/SQL Server/MariaDB/H2/SQLite/Vertica/Derby/etc. I don't think it would be too hard to write similar tooling for HoneySQL. LMK if you'd be interested in a PR

seancorfield 2020-10-07T18:56:16.155600Z

Currently, HoneySQL doesn't touch a database at all in its tests. I have contemplated it, but all the setup/teardown and vendor-specific conditionals/exceptions I already have to do for next.jdbc do not exactly fill me with enthusiasm for setting up all the same thing for HoneySQL where it would need even more DB tables to exercise the DSL results against a database and lots more vendor-specific conditionals/exceptions 😞